Results 1 to 3 of 3

Thread: How can I open a Folder for it's files to be examined?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    Here's what I have. I want to look in the folder D:\Credit\newFolder for a number of files all with the same file extension. I want to know how to open this pariticular folder(D:\Credit\newFolder) to look for the file extensions .JPG.


    <code>
    'Taken from Crispin
    Option Explicit
    Dim fs As New FileSystemObject
    Dim folCurrent
    Dim ColFiles
    Dim VarCurrentFile

    Private Sub doJpg()
    'can I add in here a open statement for a folder????
    Set folCurrent = fs.GetFolder(Text1.Text)
    Set ColFiles = folCurrent.Files
    fs.CreateFolder (folCurrent & "\NEWDIR")
    For Each VarCurrentFile In ColFiles
    If UCase(Right$(VarCurrentFile, 3)) = "JPG" Then
    'process the filenames one by one
    Debug.Print VarCurrentFile
    fs.CopyFile VarCurrentFile, folCurrent & "\NEWDIR", True
    end if
    Next
    End Sub
    </code>

    Thanks a lot for all your help
    JK

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Ontario, Canada
    Posts
    79
    The DIR Function may help you out here:

    Code:
        Dim sDir As String
        Dim sDir2 As String
        
        sDir = "c:\temp\*.jpg"
        sDir2 = Dir(sDir, vbDirectory)
        Do While sDir2 <> ""
            MsgBox ("Filename: " & sDir2)
        Loop
    The above code will give me a listing of all .JPG files in the c:\temp directory one at a time. In the above example, it will MsgBox each one.

  3. #3
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    dim dirname as string, newdir as string
    dim f as string

    dirname = "D:\Credit\newFolder\"
    newdir = dirname & "NEWDIR"

    mkdir newdir
    newdir = newdir + "\"
    f = Dir$(dirname & "*.jpg")

    do while f <> ""

    filecopy dirname & f, newdir & f
    f = Dir$

    Loop

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