Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Count the number of files in a directory (Access XP)

    How do you ask the user to specify the directory where an import will be from? I'm uploading all the files in the specified directory. Will application.getfilename work? or is there a better method to use.

    How do I count the number of files in this directory. I will be population the statusbar with 1 of X files imported.

    Thanks

  2. #2
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count the number of files in a directory (Access XP)

    <P ID="edit" class=small>(Edited by D Willett on 20-Nov-03 12:02. Over screen size)</P><pre>Dim I As Long
    Dim strMainFolder As String
    Dim strSourceFolder As String
    Dim strFile As String

    strMainFolder = "C:WindowsDesktopWorkShop"
    strSourceFolder = "L:WorkShop"

    ' Check if WorkShop folder exists
    If Dir(strMainFolder, vbDirectory) = "" Then
    MsgBox "Folder Does Not Exist" & vbCrLf & _
    "Creating Folder Now", , "Make Directory"
    MkDir strMainFolder
    End If

    'Check if source folder exists
    If Dir(strSourceFolder, vbDirectory) = "" Then
    MsgBox "No WorkShop Folder !!" & vbCrLf & _
    "Please Check If Folder Exists Before Proceeding", , "Folder Error"

    'Get out
    Exit Sub
    End If

    'Search for jpgs
    With Application.FileSearch
    .NewSearch
    .LookIn = strSourceFolder
    .SearchSubFolders = True
    .FileType = msoFileTypeAllFiles
    .FileName = "*.jpg"
    .Execute

    For I = .FoundFiles.Count To 1 Step -1

    'Copy *.Jpg Images from L:Workshop to Desktop
    strFile = .FoundFiles(I)
    FileCopy strFile, strMainFolder & GetFileName(strFile)

    'Delete Original
    Kill strFile
    Next I
    End With

    MsgBox "Images Imported", , ""

    End Sub</pre>


    Mario
    Heres something I use to import all Jpg's from a network folder and
    then empty the folder leaving it clean for the next operation.

    You can change the file extension and Path,Folder names to suit your need.

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count the number of files in a directory (Access XP)

    Thanks Dave!!!

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count the number of files in a directory (Access XP)

    You're welcome, although it doesn't count as your request, I'm sure you could edit it, and it doesn't give the user a choice of which folder.
    It does however check if the folder exists and creates it if it doesn't.

    BTW
    Hans wrote most of it.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Count the number of files in a directory (Access XP)

    1. The attached module contains a function BrowseFolder that lets the user select a folder. Use it like this:

    Dim strFolder As String
    strFolder = BrowseFolder("Please select a folder")
    If strFolder = "" Then
    MagBox "Canceled"
    Else
    MsgBox "You selected " & strFolder
    End If

    2. The following function will count files in a folder. If scripting has been disabled on your system, it won't work:

    Function FileCount(FolderName As String) As Long
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    FileCount = fso.GetFolder(FolderName).Files.Count
    Set fso = Nothing
    End Function
    Attached Files Attached Files

  6. #6
    Star Lounger
    Join Date
    Aug 2003
    Location
    Brisbane, Queensland, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count the number of files in a directory (Access XP)

    Mario,

    I swiped some code form one of the Microsoft samples (can't remember which one) some years ago that I use all the time. Look at the function ForceNewLink in the attached database and follow it through. It allows you to use the Windows FileFind box to look for a file.

    Graeme.
    Attached Files Attached Files

Posting Permissions

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