Results 1 to 5 of 5

Thread: [RESOLVED] pipe files in a folder to a text file

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Resolved [RESOLVED] pipe files in a folder to a text file

    I have a dbase database with a bunch of data tables in a folder. I need to get all of the files in that folder that start with "EN" and end with ".DBF" into a text file. There are a few hundred, otherwise I'd do it manually. I've search the forums but haven't found what I'm looking for and my VB is a little rusty in file handling.

    Anyone have a nice snippet to get me close?

    EDIT: I should add that I found a FileSystemObject example that should work, but I don't remember the trick to getting the FSO to work. It keeps telling me the user-defined type "Dim FSys As FileSystemObject" is not defined.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: pipe files in a folder to a text file

    Quote Originally Posted by ober0330
    I have a dbase database with a bunch of data tables in a folder. I need to get all of the files in that folder that start with "EN" and end with ".DBF" into a text file. There are a few hundred, otherwise I'd do it manually. I've search the forums but haven't found what I'm looking for and my VB is a little rusty in file handling.

    Anyone have a nice snippet to get me close?

    EDIT: I should add that I found a FileSystemObject example that should work, but I don't remember the trick to getting the FSO to work. It keeps telling me the user-defined type "Dim FSys As FileSystemObject" is not defined.
    To use the FSO, click Projects/References and find Microsoft Scripting Runtime. Check it, and click Ok.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: pipe files in a folder to a text file

    Yeah, I found that finally. Now the stupid script doesn't seem to be finding the files.
    VB Code:
    1. Public FSys As FileSystemObject
    2.  
    3.  
    4.  
    5. 'Constant Value Description for FileAttributes
    6.  
    7. 'Normal     0 Normal file. No attributes are set.
    8. 'ReadOnly   1 Read-only file. Attribute is read/write.
    9. 'Hidden     2 Hidden file. Attribute is read/write.
    10. 'System     4 System file. Attribute is read/write.
    11. 'Volume     8 Disk drive volume label. Attribute is read-only.
    12. 'Directory  16 Folder or directory. Attribute is read-only.
    13. 'Archive    32 File has changed since last backup. Attribute is read/write.
    14. 'Alias      64 Link or shortcut. Attribute is read-only.
    15. 'Compressed 128 Compressed file. Attribute is read-only.
    16.  
    17. Function ScanFolder(FolderSpec As String, SearchStr As String) As String
    18.  
    19. Dim thisFolder As Folder
    20. Dim allFolders As Folders
    21. Dim thisFile As File
    22. Dim allFiles As Files
    23. Dim nfile As Integer
    24.  
    25. Dim i As Integer
    26. Dim x As Integer
    27.  
    28.    Set thisFolder = FSys.GetFolder(FolderSpec)
    29.    Set allFolders = thisFolder.SubFolders
    30.    
    31. nfile = FreeFile
    32.  
    33.  
    34.    
    35.  
    36.    For Each thisFolder In allFolders
    37.    
    38. '      List1.AddItem thisFolder.Path
    39.      
    40.       If (thisFolder.Attributes And Hidden) <> Hidden Then   ' Leave hidden directories alone
    41.         Set allFiles = thisFolder.Files
    42.        
    43.         If allFiles.Count > 0 Then
    44.             Open App.Path & "\engines.txt" For Output As #nfile
    45.               For Each thisFile In allFiles
    46.                  If Right(thisFile.Name, 4) = SearchStr Then
    47.                     Print #nfile, thisFile.Name
    48.                  End If
    49.               Next
    50.             Close #nfile
    51.         End If
    52.        
    53.         Set allFiles = Nothing
    54.         Call ScanFolder(thisFolder.Path, SearchStr)
    55.       End If
    56.  
    57.       DoEvents
    58.      
    59.    Next
    60.    
    61.    
    62.  
    63.    
    64.    Set thisFolder = Nothing
    65.    Set allFolders = Nothing
    66.    Exit Function
    67.    
    68. End Function
    69.  
    70. Private Sub Command1_Click()
    71.  
    72.    MousePointer = 11
    73.    Call ScanFolder("C:\Documents and Settings\ut9950h\Desktop", ".DBF")
    74.    MousePointer = 1
    75.    
    76.    MsgBox "ScanFolders Complete - "
    77.    
    78. End Sub
    79.  
    80. Private Sub Form_Load()
    81.    
    82.    Set FSys = New FileSystemObject
    83.  
    84. End Sub

    Any ideas? One of the folders on my desktop is the folder that contains all the DBF files (as well as a bunch of other crap).
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: pipe files in a folder to a text file

    Is it finding anything?

    Have you put a break on it and 'walked' through the code to see what it is actually doing?

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: pipe files in a folder to a text file

    Yeah, nevermind. I got it. Just have to chop off the extension now, but I can handle that:
    VB Code:
    1. Function ScanFolder(FolderSpec As String, SearchStr As String) As String
    2.  
    3. Dim thisFolder As Folder
    4. Dim thisFile As File
    5. Dim allFiles As Files
    6. Dim nfile As Integer
    7.  
    8.    Set thisFolder = FSys.GetFolder(FolderSpec)
    9.    
    10.     nfile = FreeFile
    11.  
    12.     Set allFiles = thisFolder.Files
    13.        
    14.         If allFiles.Count > 0 Then
    15.             Open App.Path & "\engines.txt" For Output As #nfile
    16.               For Each thisFile In allFiles
    17.                  If Right(thisFile.Name, 4) = SearchStr Then
    18.                     If Mid(thisFile.Name, 1, 2) = "EN" Then
    19.                         Print #nfile, Mid(thisFile.Name, 2)
    20.                     End If
    21.                  End If
    22.               Next
    23.             Close #nfile
    24.         End If
    25.        
    26.         Set allFiles = Nothing
    27.  
    28.       DoEvents
    29. Set thisFolder = Nothing
    30.    
    31. End Function
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width