looping thorugh directory but it calls 1st file and no more

  • There are about 14 files in the folder, it calls the 1st one and after that myFile = ""



    Code
    myPath = "G:\Path\"
    myExtension = "*.xls*"
    MyFile = Dir(myPath & vbDirectory)
        Do While MyFile <> ""
            If MyFile <> "." And MyFile <> ".." Then
            'do stuff
            End If
        myFile = Dir
        Loop


    Any ideas?

  • Re: looping thorugh directory but it calls 1st file and no more


    Ok, I figured out the problem. I want to go through each file and create a file somewhere else if it doesn't already exist. Within the loop i'm checking if the file exists with this code:



    Code
    If Dir(curPath & curFile & curExt) = "" Then


    From what I read, this is what is screwing up the loop. What options do I have since this method is ruining the DoWhile Loop?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!