+ Reply to Thread
Results 1 to 2 of 2

importing multiple txt files from a selectable path

  1. #1
    Registered User
    Join Date
    04-07-2005
    Posts
    1

    importing multiple txt files from a selectable path

    i would like to import several .txt files from a selectable folder.
    i allready got a function to select the pathname.
    eg.
    "path" = d:\logfiles

    But now I want to import different txt files with different delimiters from this folder.
    eg.

    d:\logfiles\track.log
    d:\logfiles\model.log

    i also got the code for importing the file, but it requires an imput named "FileName".
    i would like to find a way to set this "FileName" using the variable "path"

    something like

    FileName = path\track.log

    any help would be much appreciated.


    Diego Jansen

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Diego,

    Here is macro I wrote that returns all thefolders and files in a given directory. There are 2 public arrays. DirFiles holds all the files found and DirFolders holds the folders. The zero element of each array holds the total for that array making it easy to use in a loop.

    Macro Code:
    Place this code in VBA Module.


    Public DirFiles() As String
    Public DirFolders() As String
    _________________________________________________________________

    Public Sub GetFilesAndFolders(Directory_Path As String)

    'GET ALL FOLDERS AND FILES FOR GIVEN PATH
    'Macro written Jan. 22, 2005
    'Author: Leith Ross
    'Email: [email protected]

    Dim F As Integer
    Dim N As Integer

    Dim FolderFlag As Long
    Dim FileFlags As Long
    Dim MySearch As String

    FolderFlag = vbDirectory
    FileFlags = vbNormal + vbArchive + vbHidden + vbSystem + vbReadOnly

    On Error GoTo Error_Handler

    'Add a Backslash to the Path if needed
    If Right(Directory_Path, 1) <> "\" Then
    Directory_Path = Directory_Path & "\"
    End If

    ChDir (Directory_Path)

    MySearch = Dir(Directory_Path, FolderFlag + FileFlags)

    Do While MySearch <> "" ' Start the loop.
    ' Ignore the current directory and the encompassing directory.
    If MySearch <> "." And MySearch <> ".." Then
    ' Check if Result is a Directory by a Bitwise Test
    Result = GetAttr(Directory_Path & MySearch)
    If Result And FolderFlag Then
    N = N + 1
    ReDim Preserve DirFolders(N)
    DirFolders(N) = MySearch
    End If
    If Result And FileFlags Then
    F = F + 1
    ReDim Preserve DirFiles(F)
    DirFiles(F) = MySearch
    End If
    End If
    MySearch = Dir ' Get next entry.
    Loop

    'Save the Totals
    DirFiles(0) = F
    DirFolders(0) = N

    Exit Sub

    Error_Handler:
    ErrInfo = " Error #" & Str(Err.Number) _
    & vbCrLf & Err.Description
    RetVal = MsgBox(ErrInfo, vbCritical + vbOKOnly, "File Manager")

    End Sub

    _________________________________________________________________

    If you have questions contact me here at the Forum or Email me at [email protected].

    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1