[SOLVED] Rename and Move File

  • Hi Experts


    I think I am almost there...


    I am looping through files in a folder, opening them, doing stuff in them, and then closing the file. After the close is where I have the problems


    I am wanting to move that file to a new location, but... if the file exists in the new location, rename it as file(1) (or 2 or 3 - basically increment the number by 1.


    The code I have is:



    My problem is that the loop code to increment just keeps looping (I can see the number increases everytime), I need it to get to the next available number and move the file.


    Any help would be appreciated

  • Ok, partial solve - I have moved the loop, giving me

    Code
    Loop
    fso.MoveFile Source:=MyPath & MyFile, Destination:=DestPath & ReFile


    but now I have notices 2 things
    1) The file is called Filename(0) not Filename (1)
    2) When the file is moved, I get a file not found error - in the loop


    Thanks for any help

  • Hi All,


    I have solved the issue.


    I needed to do a simple Do.. Until


    I had a minor issue of the Number not resetting, for the second file, so I needed to reset that to 0


    The final code I used was:

Participate now!

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