Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to display files that are not in directory?

how to display files that are not in directory?

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestionworkspace
18 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zaimah
    wrote on last edited by
    #1

    Im suppose to have an app where it will compare two folders, Folder A and Folder B. It will check whether files in folder A are in folder B. If the file in folder A are not in folder B, it will display the name of the files that are not in folder B. This is the coding that i manage to do.. But nothing happen when i click the button check.. PLsss sumbody help me..

    Private Sub btncheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncheck.Click
    Dim di1 As DirectoryInfo = New DirectoryInfo(txtdir1.Text) ' Folder A
    Dim di2 As DirectoryInfo = New DirectoryInfo(txtdir2.Text) ' Folder B

        Try
            Dim dirs1 As FileSystemInfo() = di1.GetDirectories
            Dim dirs2 As FileSystemInfo() = di2.GetDirectories
            Dim d1, d2 As DirectoryInfo
            Dim i As Integer
          
            For i = 0 To dirs1.Length - 1
                For Each d1 In dirs1
                    Dim f1 As FileInfo() = d1.GetFiles()
    
                    For Each d2 In dirs2
                        Dim f2 As FileInfo() = d2.GetFiles()
    
                        If d1.Name = d2.Name Then
                        Else
    
                            Console.WriteLine(d1.Name)
                        End If
                    Next
                Next
            Next
    
    
    
        Catch ex As Exception
    
        End Try
    
    End Sub
    
    
    Private Sub btndirectory\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndirectory.Click
        Dim folderopen As New FolderBrowserDialog
        With folderopen
            .RootFolder = Environment.SpecialFolder.Desktop
            .SelectedPath = "C:\\DOCUMENT"
            .Description = "Select the source directory"
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                ' Display the selected folder if the user clicked on the OK button.
                MessageBox.Show(.SelectedPath)
                txtdir1.Text = .SelectedPath
            End If
    
        End With
    End Sub
    
    Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbldate.Text = Now.ToLongDateString
    End Sub
    
    
    Private Sub btndirectory2\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim folderopen As New FolderBrowserDialog
        With folderopen
            .RootFolder = Environment.SpecialFolder.Desktop
            .SelectedPath =
    
    L 1 Reply Last reply
    0
    • Z zaimah

      Im suppose to have an app where it will compare two folders, Folder A and Folder B. It will check whether files in folder A are in folder B. If the file in folder A are not in folder B, it will display the name of the files that are not in folder B. This is the coding that i manage to do.. But nothing happen when i click the button check.. PLsss sumbody help me..

      Private Sub btncheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncheck.Click
      Dim di1 As DirectoryInfo = New DirectoryInfo(txtdir1.Text) ' Folder A
      Dim di2 As DirectoryInfo = New DirectoryInfo(txtdir2.Text) ' Folder B

          Try
              Dim dirs1 As FileSystemInfo() = di1.GetDirectories
              Dim dirs2 As FileSystemInfo() = di2.GetDirectories
              Dim d1, d2 As DirectoryInfo
              Dim i As Integer
            
              For i = 0 To dirs1.Length - 1
                  For Each d1 In dirs1
                      Dim f1 As FileInfo() = d1.GetFiles()
      
                      For Each d2 In dirs2
                          Dim f2 As FileInfo() = d2.GetFiles()
      
                          If d1.Name = d2.Name Then
                          Else
      
                              Console.WriteLine(d1.Name)
                          End If
                      Next
                  Next
              Next
      
      
      
          Catch ex As Exception
      
          End Try
      
      End Sub
      
      
      Private Sub btndirectory\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndirectory.Click
          Dim folderopen As New FolderBrowserDialog
          With folderopen
              .RootFolder = Environment.SpecialFolder.Desktop
              .SelectedPath = "C:\\DOCUMENT"
              .Description = "Select the source directory"
              If .ShowDialog = Windows.Forms.DialogResult.OK Then
                  ' Display the selected folder if the user clicked on the OK button.
                  MessageBox.Show(.SelectedPath)
                  txtdir1.Text = .SelectedPath
              End If
      
          End With
      End Sub
      
      Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          lbldate.Text = Now.ToLongDateString
      End Sub
      
      
      Private Sub btndirectory2\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim folderopen As New FolderBrowserDialog
          With folderopen
              .RootFolder = Environment.SpecialFolder.Desktop
              .SelectedPath =
      
      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      zaimah wrote:

      Catch ex As Exception End Try

      Great. First you throw away all available information about possible exceptions, and then you ask the CP community what goes wrong in your program. NEVER ignore exceptions the way you did. Log them, print them to the console, count them, whatever but don't let them go unnoticed. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Love, happiness and fewer bugs for 2009!


      Z 1 Reply Last reply
      0
      • L Luc Pattyn

        zaimah wrote:

        Catch ex As Exception End Try

        Great. First you throw away all available information about possible exceptions, and then you ask the CP community what goes wrong in your program. NEVER ignore exceptions the way you did. Log them, print them to the console, count them, whatever but don't let them go unnoticed. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Love, happiness and fewer bugs for 2009!


        Z Offline
        Z Offline
        zaimah
        wrote on last edited by
        #3

        shame on me :) iv just put MsgBox(ex.Message) between Catch ex As Exception and End Try.. but still nothing happen.. i know my question sound a bit stupid.. im new in this.. and thanks a lot for the reply :)

        L 1 Reply Last reply
        0
        • Z zaimah

          shame on me :) iv just put MsgBox(ex.Message) between Catch ex As Exception and End Try.. but still nothing happen.. i know my question sound a bit stupid.. im new in this.. and thanks a lot for the reply :)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          OK, now start debugging, i.e. either add some output statements so you can see what is going on, or use single-stepping and watch the values. how many entries are in dirs1 and dirs2? you are aware you are comparing two folders assuming they contain just 1 level of subfolders and no files at the toplevel? strange code: Why is there a for i loop? what is the use of f1 and f2? you assign a value to them but never use them? all you do is compare the names of the subfolders! :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Love, happiness and fewer bugs for 2009!


          modified on Saturday, January 3, 2009 8:03 AM

          Z 1 Reply Last reply
          0
          • L Luc Pattyn

            OK, now start debugging, i.e. either add some output statements so you can see what is going on, or use single-stepping and watch the values. how many entries are in dirs1 and dirs2? you are aware you are comparing two folders assuming they contain just 1 level of subfolders and no files at the toplevel? strange code: Why is there a for i loop? what is the use of f1 and f2? you assign a value to them but never use them? all you do is compare the names of the subfolders! :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Love, happiness and fewer bugs for 2009!


            modified on Saturday, January 3, 2009 8:03 AM

            Z Offline
            Z Offline
            zaimah
            wrote on last edited by
            #5

            actually i have to compare lots of folder.. like this, there are 280 folder under customers id.. each of the customers folder, there are files .. we have to compare source folder with the folder in portal.. with this prgm, to make sure that we know which r the files in the source have not been copied.. so i will choose one customer's folder the source and the portal... the folder only hv 1 level subfolder.. i hv tried to put sum outpt statements.. when i put console.write"Hello" after Try, it doesnt display "Hello", but if i put MsgBox("Hello") after Try the msg box came out. When i put msgbox inside For Each d1 in dirs1, nothing come out.. so it must be sum thing wrong with my For Each statements.. and one more thing, why console.write doesn't work? and the i loop is actually i want it to compare with all the files in the source folder.. lets say the source have 14 files and the portal only got 10.. it must check all 14 between all 10 files in portal.. when i test it with the output staments, i put out the i loop.. bcoz im afraid it will effect the output.. iv just notice about the unused f1 and f2.. thanks :)

            L 1 Reply Last reply
            0
            • Z zaimah

              actually i have to compare lots of folder.. like this, there are 280 folder under customers id.. each of the customers folder, there are files .. we have to compare source folder with the folder in portal.. with this prgm, to make sure that we know which r the files in the source have not been copied.. so i will choose one customer's folder the source and the portal... the folder only hv 1 level subfolder.. i hv tried to put sum outpt statements.. when i put console.write"Hello" after Try, it doesnt display "Hello", but if i put MsgBox("Hello") after Try the msg box came out. When i put msgbox inside For Each d1 in dirs1, nothing come out.. so it must be sum thing wrong with my For Each statements.. and one more thing, why console.write doesn't work? and the i loop is actually i want it to compare with all the files in the source folder.. lets say the source have 14 files and the portal only got 10.. it must check all 14 between all 10 files in portal.. when i test it with the output staments, i put out the i loop.. bcoz im afraid it will effect the output.. iv just notice about the unused f1 and f2.. thanks :)

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, as I said before, your code does not make much sense: i, f1 and f2 are assigned a value but never used.

              zaimah wrote:

              When i put msgbox inside For Each d1 in dirs1, nothing come out

              maybe dirs1 is empty so the foreach gets skipped. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Love, happiness and fewer bugs for 2009!


              Z 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, as I said before, your code does not make much sense: i, f1 and f2 are assigned a value but never used.

                zaimah wrote:

                When i put msgbox inside For Each d1 in dirs1, nothing come out

                maybe dirs1 is empty so the foreach gets skipped. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Love, happiness and fewer bugs for 2009!


                Z Offline
                Z Offline
                zaimah
                wrote on last edited by
                #7

                i have throw the i, f1 and f2.. the possibility for the folder is empty is there, but i tried with folder level 1,2 and 3.. still nothing come out... if f1 n f2 is not there anymore, logically if i put For Each d1 In dirs MsgBox("Hello") <-- at least it will execute this command to display the word. but nothing come out. if i, f1 and f2 is out of the coding, what is the possibility of error in my coding? :( is there sum thing wrong with the coding? or is there sum thing wrong with me? :)

                L 1 Reply Last reply
                0
                • Z zaimah

                  i have throw the i, f1 and f2.. the possibility for the folder is empty is there, but i tried with folder level 1,2 and 3.. still nothing come out... if f1 n f2 is not there anymore, logically if i put For Each d1 In dirs MsgBox("Hello") <-- at least it will execute this command to display the word. but nothing come out. if i, f1 and f2 is out of the coding, what is the possibility of error in my coding? :( is there sum thing wrong with the coding? or is there sum thing wrong with me? :)

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Hi, I suggest you add Console.WriteLine statements to watch intermediate values, or you single-step in the debugger and watch how things evolve. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  Love, happiness and fewer bugs for 2009!


                  Z 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, I suggest you add Console.WriteLine statements to watch intermediate values, or you single-step in the debugger and watch how things evolve. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Love, happiness and fewer bugs for 2009!


                    Z Offline
                    Z Offline
                    zaimah
                    wrote on last edited by
                    #9

                    I manage to correct my coding... but there's another problems appear... two main directories that is dirA and dirB.. dirA have 3 folders and it is the main source.. must compare with dirB.. where if in dirA hv folder name ASB01,BP001 and CP001. And each of the folder hv files. I have to compare dirA with dirB where it suppose to display which folder and files in dirA are not in dirB. But when i did this coding, it only compare the first folder, and display the files that are not in dirB. When it comes to the next folder, it didnt compare, it display all the files in dirA. Example if dirA have folder ASB01 with files C4001, C4002 and folder BP001. Meanwhile dirB have folder ASB01 with files C4001 only. It will display ASB001/C4002, and all the files and other folder than ASB001. Iv been trying to find the problems.. :(

                    Try
                    Dim dA1, dB1 As DirectoryInfo
                    Dim dirA2 As FileSystemInfo() = dirA1.GetDirectories
                    Dim dirB2 As FileSystemInfo() = dirB1.GetDirectories

                            For Each dA1 In dirA2
                                For Each dB1 In dirB2
                    
                                   If dA1.Name = dB1.Name Then
                    
                                   Dim dA2, dB2 As FileSystemInfo
                                   Dim dirA3 As FileSystemInfo() = dA1.GetFileSystemInfos
                                   Dim dirB3 As FileSystemInfo() = dB1.GetFileSystemInfos
                                        
                                        For Each dA2 In dirA3
                                            For Each dB2 In dirB3
                    
                                              If dA2.Name = dB2.Name Then
                                              Else
                                                ListBox1.Items.Add(dA2.FullName)
                                              End If
                                            Next dB2
                                        Next dA2
                    
                                   Else
                                        
                                    ListBox1.Items.Add(dA2.FullName)
                    
                                   End If
                                 Next dB1
                            Next dA1
                            Catch ex As Exception
                    
                            MsgBox(ex.Message)
                    
                        End Try
                    
                    End Sub
                    
                    L 1 Reply Last reply
                    0
                    • Z zaimah

                      I manage to correct my coding... but there's another problems appear... two main directories that is dirA and dirB.. dirA have 3 folders and it is the main source.. must compare with dirB.. where if in dirA hv folder name ASB01,BP001 and CP001. And each of the folder hv files. I have to compare dirA with dirB where it suppose to display which folder and files in dirA are not in dirB. But when i did this coding, it only compare the first folder, and display the files that are not in dirB. When it comes to the next folder, it didnt compare, it display all the files in dirA. Example if dirA have folder ASB01 with files C4001, C4002 and folder BP001. Meanwhile dirB have folder ASB01 with files C4001 only. It will display ASB001/C4002, and all the files and other folder than ASB001. Iv been trying to find the problems.. :(

                      Try
                      Dim dA1, dB1 As DirectoryInfo
                      Dim dirA2 As FileSystemInfo() = dirA1.GetDirectories
                      Dim dirB2 As FileSystemInfo() = dirB1.GetDirectories

                              For Each dA1 In dirA2
                                  For Each dB1 In dirB2
                      
                                     If dA1.Name = dB1.Name Then
                      
                                     Dim dA2, dB2 As FileSystemInfo
                                     Dim dirA3 As FileSystemInfo() = dA1.GetFileSystemInfos
                                     Dim dirB3 As FileSystemInfo() = dB1.GetFileSystemInfos
                                          
                                          For Each dA2 In dirA3
                                              For Each dB2 In dirB3
                      
                                                If dA2.Name = dB2.Name Then
                                                Else
                                                  ListBox1.Items.Add(dA2.FullName)
                                                End If
                                              Next dB2
                                          Next dA2
                      
                                     Else
                                          
                                      ListBox1.Items.Add(dA2.FullName)
                      
                                     End If
                                   Next dB1
                              Next dA1
                              Catch ex As Exception
                      
                              MsgBox(ex.Message)
                      
                          End Try
                      
                      End Sub
                      
                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      Hi, there are many mistakes, I'll name a few: 1.

                      zaimah wrote:

                      MsgBox(ex.Message)

                      IMO it is a bad idea to ignore all but the message of an exception; ex.ToString() offers the mesage, the stack traceback and extra information such as the file name in case a file I/O problem occurs. That should be interesting. 2.

                      zaimah wrote:

                      For Each dA2 In dirA3 For Each dB2 In dirB3 If dA2.Name = dB2.Name Then Else

                      The else will execute many times, say dirA3 contains X+Y+Z and dirB3 contains K+L+M+N, then each file in dirA3 will be shown 4 times just because there are 4 items in dirB3. That cannot be what you want. 3. What you seem to be trying is some kind of backup utility, finding files that exist in dirA but not in dirB. To do so, you don't need to enumerate the files in dirB, all it takes is enumerate the files in dirA and check existence of the corresponding file in dirB, hence come up with the fullname the file would have in dirB and test File.Exists(). That will cost you the calculation of the fullnames, and it saves you the nested for loops (and the multiple firing of the else problem, see 2). Two more comments: A. the general solution needs recursion, that would be able to cope with an arbitrary hierarchy of files and folders. B. you can ask GetFiles/GetFolder/... to work recursively for you, hiding all the nested-folder stuff, with one caveat: it then returns many more items (always as full path names) all at once, possibly leading to out-of-memory (or memory low) problems. It could be fine for a small part of a disk or partition, but it would NOT be the way to go for backing up an entire disk (which could hold millions of files)! :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      Love, happiness and fewer bugs for 2009!


                      Z 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        Hi, there are many mistakes, I'll name a few: 1.

                        zaimah wrote:

                        MsgBox(ex.Message)

                        IMO it is a bad idea to ignore all but the message of an exception; ex.ToString() offers the mesage, the stack traceback and extra information such as the file name in case a file I/O problem occurs. That should be interesting. 2.

                        zaimah wrote:

                        For Each dA2 In dirA3 For Each dB2 In dirB3 If dA2.Name = dB2.Name Then Else

                        The else will execute many times, say dirA3 contains X+Y+Z and dirB3 contains K+L+M+N, then each file in dirA3 will be shown 4 times just because there are 4 items in dirB3. That cannot be what you want. 3. What you seem to be trying is some kind of backup utility, finding files that exist in dirA but not in dirB. To do so, you don't need to enumerate the files in dirB, all it takes is enumerate the files in dirA and check existence of the corresponding file in dirB, hence come up with the fullname the file would have in dirB and test File.Exists(). That will cost you the calculation of the fullnames, and it saves you the nested for loops (and the multiple firing of the else problem, see 2). Two more comments: A. the general solution needs recursion, that would be able to cope with an arbitrary hierarchy of files and folders. B. you can ask GetFiles/GetFolder/... to work recursively for you, hiding all the nested-folder stuff, with one caveat: it then returns many more items (always as full path names) all at once, possibly leading to out-of-memory (or memory low) problems. It could be fine for a small part of a disk or partition, but it would NOT be the way to go for backing up an entire disk (which could hold millions of files)! :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        Love, happiness and fewer bugs for 2009!


                        Z Offline
                        Z Offline
                        zaimah
                        wrote on last edited by
                        #11

                        Thanks for the explaination.. It really helps me understand the problems. iv got a few helps from friends and this are the new coding that i did. but still it keeps on repeating the name of the files..

                        Dim folderALocation As String = txtdir1.Text
                        Dim folderBLocation As String = txtdir2.Text

                        'Get all files in Folder A including those found in sub directories
                        Dim folderAFiles() As String = System.IO.Directory.GetFiles
                        (folderALocation, "*.*", IO.SearchOption.AllDirectories)

                        'Enumerate through the string array and determine if each file exists within Folder B

                        For Each fileName As String In folderAFiles

                          If System.IO.File.Exists(fileName.Replace(folderALocation,  
                          folderBLocation)) = False Then
                                ListBox1.Items.Add(fileName)
                          End If
                        
                          Next
                        
                        L 1 Reply Last reply
                        0
                        • Z zaimah

                          Thanks for the explaination.. It really helps me understand the problems. iv got a few helps from friends and this are the new coding that i did. but still it keeps on repeating the name of the files..

                          Dim folderALocation As String = txtdir1.Text
                          Dim folderBLocation As String = txtdir2.Text

                          'Get all files in Folder A including those found in sub directories
                          Dim folderAFiles() As String = System.IO.Directory.GetFiles
                          (folderALocation, "*.*", IO.SearchOption.AllDirectories)

                          'Enumerate through the string array and determine if each file exists within Folder B

                          For Each fileName As String In folderAFiles

                            If System.IO.File.Exists(fileName.Replace(folderALocation,  
                            folderBLocation)) = False Then
                                  ListBox1.Items.Add(fileName)
                            End If
                          
                            Next
                          
                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #12

                          Hi, I see you made real progress. I ran your code and it works fine under ideal conditions, i.e. when: - both textboxes contain absolute paths - both paths end on backslash, or none of them do - both paths point to local partitions Otherwise things will or may go wrong. You should program more defensively, i.e. either reject or fix bad input. Minor remarks: 1. string.Replace replaces all occurences so it could happen that your destination gets damaged, assume textbox1="a" and textbox2="b", now all characters a will get replaced in filenames and extensions. The better approach is to compute filename2 as folderBlocation followed by the tail of filename (all but the first N chars where N=folderAlocation.Length) 2. it still may go wrong when you enter the path in a way that is valid but not the standard way, e.g. when there are aliases (could happen with networked drives) or double dots (..\folder) since GetFiles would return a so-called canonical path, not necessarily the way you specified it. 3. I would replace "...Exists = false ..." by "Not Exists..." 4. I would use "*" as a filter instead of "*.*" (non-Windows file systems don't enforce a dot when there is no extension, so you would never see those files) :)

                          Luc Pattyn [Forum Guidelines] [My Articles]


                          I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                          Z 1 Reply Last reply
                          0
                          • L Luc Pattyn

                            Hi, I see you made real progress. I ran your code and it works fine under ideal conditions, i.e. when: - both textboxes contain absolute paths - both paths end on backslash, or none of them do - both paths point to local partitions Otherwise things will or may go wrong. You should program more defensively, i.e. either reject or fix bad input. Minor remarks: 1. string.Replace replaces all occurences so it could happen that your destination gets damaged, assume textbox1="a" and textbox2="b", now all characters a will get replaced in filenames and extensions. The better approach is to compute filename2 as folderBlocation followed by the tail of filename (all but the first N chars where N=folderAlocation.Length) 2. it still may go wrong when you enter the path in a way that is valid but not the standard way, e.g. when there are aliases (could happen with networked drives) or double dots (..\folder) since GetFiles would return a so-called canonical path, not necessarily the way you specified it. 3. I would replace "...Exists = false ..." by "Not Exists..." 4. I would use "*" as a filter instead of "*.*" (non-Windows file systems don't enforce a dot when there is no extension, so you would never see those files) :)

                            Luc Pattyn [Forum Guidelines] [My Articles]


                            I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                            Z Offline
                            Z Offline
                            zaimah
                            wrote on last edited by
                            #13

                            This is my folder.. dirA and dirB is on my desktop. I will click folder FTP and PORTAL for txtdir1.Text and txtdir2.Text \FTP \ASB01 C4201 C4432 \BP001 C4186 C4187 C4190 C4191 \BRT01 C4192 C4209 C4212 \PORTAL \ASB01 C4201 \BP001 C4186 C4187 And the output comeout is C:\Documents and Settings\Desktop\FTP\ASB01\C4432 C:\Documents and Settings\Desktop\FTP\BP001\C4186 C:\Documents and Settings\Desktop\FTP\BP001\C4187 C:\Documents and Settings\Desktop\FTP\BP001\C4187 C:\Documents and Settings\Desktop\FTP\BP001\C4190 C:\Documents and Settings\Desktop\FTP\BP001\C4191 C:\Documents and Settings\Desktop\FTP\BP001\C4191 C:\Documents and Settings\Desktop\FTP\BRT01\C4192 C:\Documents and Settings\Desktop\FTP\BRT01\C4209 C:\Documents and Settings\Desktop\FTP\BRT01\C4212 C:\Documents and Settings\Desktop\FTP\BP001\C4187 C:\Documents and Settings\Desktop\FTP\BP001\C4191 C:\Documents and Settings\Desktop\FTP\ASB01\C4432 1. and i dont understand ur remarks number 1. Can u pls explain details? Maybe bcoz im new in this programming, thats why i dont fully understand ur explaination. 2. Remarks number 3, does it means change ".Exists = false" to ".Exists = true" ? 3. I have change "*.*" with "*" but still nothing happen.. Sorry for my stupid question :sigh:

                            L 1 Reply Last reply
                            0
                            • Z zaimah

                              This is my folder.. dirA and dirB is on my desktop. I will click folder FTP and PORTAL for txtdir1.Text and txtdir2.Text \FTP \ASB01 C4201 C4432 \BP001 C4186 C4187 C4190 C4191 \BRT01 C4192 C4209 C4212 \PORTAL \ASB01 C4201 \BP001 C4186 C4187 And the output comeout is C:\Documents and Settings\Desktop\FTP\ASB01\C4432 C:\Documents and Settings\Desktop\FTP\BP001\C4186 C:\Documents and Settings\Desktop\FTP\BP001\C4187 C:\Documents and Settings\Desktop\FTP\BP001\C4187 C:\Documents and Settings\Desktop\FTP\BP001\C4190 C:\Documents and Settings\Desktop\FTP\BP001\C4191 C:\Documents and Settings\Desktop\FTP\BP001\C4191 C:\Documents and Settings\Desktop\FTP\BRT01\C4192 C:\Documents and Settings\Desktop\FTP\BRT01\C4209 C:\Documents and Settings\Desktop\FTP\BRT01\C4212 C:\Documents and Settings\Desktop\FTP\BP001\C4187 C:\Documents and Settings\Desktop\FTP\BP001\C4191 C:\Documents and Settings\Desktop\FTP\ASB01\C4432 1. and i dont understand ur remarks number 1. Can u pls explain details? Maybe bcoz im new in this programming, thats why i dont fully understand ur explaination. 2. Remarks number 3, does it means change ".Exists = false" to ".Exists = true" ? 3. I have change "*.*" with "*" but still nothing happen.. Sorry for my stupid question :sigh:

                              L Offline
                              L Offline
                              Luc Pattyn
                              wrote on last edited by
                              #14

                              Hi, 1. if File.Exists(file)=False then can/should be written as if NOT File.Exists(file) then , that is what I meant, this is not a mistake just a comment on style. 2. I guess you are using relative paths, your text boxes just contain FTP and PORTAL, instead of C:\Documents and Settings\Desktop\FTP and C:\Documents and Settings\Desktop\PORTAL Now assume one of your files inside FTP is ...\FTP\FTP1.DAT, then String.Replace("FTP", "PORTAL") would turn that into ...\PORTAL\PORTAL1.DAT which is not what you intend; Replace does not care about folders and filenames, it just eagerly replaces. That is way I suggested not using Replace, but performing a string concatenation; this only works if the paths are absolute, i.e. the thing to be replaced starts at the first character (replace C:\Documents and Settings\Desktop\FTP by C:\Documents and Settings\Desktop\PORTAL) 3. a general debugging rule: as long as your code does not behave the way you want, split a more complex line in multiple lines and watch the intermediate values, like so:

                              ...
                              dim filename2 as string=filename.Replace(AFolder,BFolder)
                              Console.WriteLine("--- Going to look if this exists: "&filename2)
                              if not File.Exists(filename2) then
                              ...

                              That way you will see whether or not you are checking the right filenames, or are having some trouble with paths and/or replace issues. Of course you can use myListBox.Add() or whatever you prefer to see intermediate values... listing them to a console or listbox is much easier than watching them through debug commands or through MessageBox.Show statements (they get irritating pretty soon). 4. your code ran fine with me when the textboxes contained "H:\someFolder\" and "H:\someFolderCopy\"; it discovered 2 files missing out of several thousand. :)

                              Luc Pattyn [Forum Guidelines] [My Articles]


                              I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                              Z 1 Reply Last reply
                              0
                              • L Luc Pattyn

                                Hi, 1. if File.Exists(file)=False then can/should be written as if NOT File.Exists(file) then , that is what I meant, this is not a mistake just a comment on style. 2. I guess you are using relative paths, your text boxes just contain FTP and PORTAL, instead of C:\Documents and Settings\Desktop\FTP and C:\Documents and Settings\Desktop\PORTAL Now assume one of your files inside FTP is ...\FTP\FTP1.DAT, then String.Replace("FTP", "PORTAL") would turn that into ...\PORTAL\PORTAL1.DAT which is not what you intend; Replace does not care about folders and filenames, it just eagerly replaces. That is way I suggested not using Replace, but performing a string concatenation; this only works if the paths are absolute, i.e. the thing to be replaced starts at the first character (replace C:\Documents and Settings\Desktop\FTP by C:\Documents and Settings\Desktop\PORTAL) 3. a general debugging rule: as long as your code does not behave the way you want, split a more complex line in multiple lines and watch the intermediate values, like so:

                                ...
                                dim filename2 as string=filename.Replace(AFolder,BFolder)
                                Console.WriteLine("--- Going to look if this exists: "&filename2)
                                if not File.Exists(filename2) then
                                ...

                                That way you will see whether or not you are checking the right filenames, or are having some trouble with paths and/or replace issues. Of course you can use myListBox.Add() or whatever you prefer to see intermediate values... listing them to a console or listbox is much easier than watching them through debug commands or through MessageBox.Show statements (they get irritating pretty soon). 4. your code ran fine with me when the textboxes contained "H:\someFolder\" and "H:\someFolderCopy\"; it discovered 2 files missing out of several thousand. :)

                                Luc Pattyn [Forum Guidelines] [My Articles]


                                I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                                Z Offline
                                Z Offline
                                zaimah
                                wrote on last edited by
                                #15

                                hi Luc :) 1. yup, now i understand what u were trying to explain 2. sorry, i used wrong words.. my english is not so good.. I choose the full path name C:\Documents and Settings\Desktop\FTP and C:\Documents and Settings\Desktop\PORTAL 3. again, thank you for ur explaination.. ;) 4. That is why im confiused bcoz my friend run this code witth the expected output, but mine didnt.. this is getting weird.. :)

                                L 1 Reply Last reply
                                0
                                • Z zaimah

                                  hi Luc :) 1. yup, now i understand what u were trying to explain 2. sorry, i used wrong words.. my english is not so good.. I choose the full path name C:\Documents and Settings\Desktop\FTP and C:\Documents and Settings\Desktop\PORTAL 3. again, thank you for ur explaination.. ;) 4. That is why im confiused bcoz my friend run this code witth the expected output, but mine didnt.. this is getting weird.. :)

                                  L Offline
                                  L Offline
                                  Luc Pattyn
                                  wrote on last edited by
                                  #16

                                  You're welcome. If it fails, look at the intermediate values; maybe you have a typo somewhere. :)

                                  Luc Pattyn [Forum Guidelines] [My Articles]


                                  I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                                  Z 1 Reply Last reply
                                  0
                                  • L Luc Pattyn

                                    You're welcome. If it fails, look at the intermediate values; maybe you have a typo somewhere. :)

                                    Luc Pattyn [Forum Guidelines] [My Articles]


                                    I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                                    Z Offline
                                    Z Offline
                                    zaimah
                                    wrote on last edited by
                                    #17

                                    yup.. there's sum thing wrong with the directory that i select.. it can run rite now thanks :).. but another problem come out :~ actually i have to select files that must need to map drive 1st. but when i used this coding to select files in my computer, it cannot select the drive from portal and ftp that i has map already.. can u pls take a look at my coding?

                                    Dim folderopen As New FolderBrowserDialog
                                    With folderopen
                                    .RootFolder = Environment.SpecialFolder.Desktop
                                    .SelectedPath = "C:\DOCUMENT"
                                    .Description = "Select the source directory"
                                    If .ShowDialog = Windows.Forms.DialogResult.OK Then
                                    ' Display the selected folder if the user clicked on the OK button.
                                    MessageBox.Show(.SelectedPath)
                                    txtdir2.Text = .SelectedPath
                                    End If

                                        End With
                                    
                                    L 1 Reply Last reply
                                    0
                                    • Z zaimah

                                      yup.. there's sum thing wrong with the directory that i select.. it can run rite now thanks :).. but another problem come out :~ actually i have to select files that must need to map drive 1st. but when i used this coding to select files in my computer, it cannot select the drive from portal and ftp that i has map already.. can u pls take a look at my coding?

                                      Dim folderopen As New FolderBrowserDialog
                                      With folderopen
                                      .RootFolder = Environment.SpecialFolder.Desktop
                                      .SelectedPath = "C:\DOCUMENT"
                                      .Description = "Select the source directory"
                                      If .ShowDialog = Windows.Forms.DialogResult.OK Then
                                      ' Display the selected folder if the user clicked on the OK button.
                                      MessageBox.Show(.SelectedPath)
                                      txtdir2.Text = .SelectedPath
                                      End If

                                          End With
                                      
                                      L Offline
                                      L Offline
                                      Luc Pattyn
                                      wrote on last edited by
                                      #18

                                      Hi, I'm not familiar with FolderBrowserDialog, but you seem to violate the following MSDN remark: "If the SelectedPath property is set before showing the dialog box, the folder with this path will be the selected folder, as long as SelectedPath is set to an absolute path that is a subfolder of RootFolder (or more accurately, points to a subfolder of the shell namespace represented by RootFolder)." C:\Document is not inside SpecialFolder.Desktop (which is located much deeper, its exact position depends on you Windows version). :)

                                      Luc Pattyn [Forum Guidelines] [My Articles]


                                      I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.


                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups