PDA

View Full Version : Solved: Dir function skipping the first file



joshcas
07-03-2013, 08:04 AM
Hi , Good Morning

I’m having a glitch in my code because the DIR function is skipping the first file in the “Output” folder , do you know why this might be happening and how to fix it ?,

Here is my code:


StrFile = Dir(ThisWorkbook.Path & "\Output\")
Do While Len(StrFile) > 0
StrFile = Dir
WriteDebugLog (Now & " : deleting old file " & sRemoteFilePathFull & StrFile)
KillIt (sRemoteFilePathFull & StrFile)
WriteDebugLog (Now & " : copying " & StrFile & " from pc to server")
FileCopy SDefaultLocalPathtwo & StrFile, sRemoteFilePathFull & StrFile
Loop



Any help will be much appreciated

p45cal
07-03-2013, 08:17 AM
because you're not doing anything with what's been assigned to StrFile when this first line is executed:
StrFile = Dir(ThisWorkbook.Path & "\Output\")

snb
07-03-2013, 08:17 AM
the code doesn't skip, you do:



StrFile = Dir(ThisWorkbook.Path & "\Output\")
Do While Len(StrFile) > 0

WriteDebugLog (Now & " : deleting old file " & sRemoteFilePathFull & StrFile)
KillIt (sRemoteFilePathFull & StrFile)
WriteDebugLog (Now & " : copying " & StrFile & " from pc to server")
FileCopy SDefaultLocalPathtwo & StrFile, sRemoteFilePathFull & StrFile
StrFile = Dir
Loop

SamT
07-03-2013, 02:08 PM
Do Until Len(StrFile) = 0
'
'
'
Loop

joshcas
07-04-2013, 05:17 AM
Hi p45cal, snb , SamT

Good talking to you again,

Brilliant solutions as always, it’s working flawless thanks to you guys

Thank you so much for taking the time to answer my question, I really appreciate it

Happy 4th of July