Consulting

Results 1 to 5 of 5

Thread: Solved: Dir function skipping the first file

  1. #1

    Solved: Dir function skipping the first file

    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:

    [vba]
    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
    [/vba]


    Any help will be much appreciated

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    because you're not doing anything with what's been assigned to StrFile when this first line is executed:
    StrFile = Dir(ThisWorkbook.Path & "\Output\")
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    the code doesn't skip, you do:

    [VBA]
    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
    [/VBA]

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    [VBA]Do Until Len(StrFile) = 0
    '
    '
    '
    Loop[/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    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
    Last edited by joshcas; 07-04-2013 at 05:28 AM.

Posting Permissions

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