Hi,
I have to rename files in a folder in a way that there is an X_ added in front of the name of the file. I have managed it with this code:
Private Sub Command3_Click()
Path = "C:"
file = Dir(Path & "*.csv")
Do While file <> ""
Oldname = file
newname = Path & "X_" & Oldname
Name Path & Oldname As newname
file = Dir
Loop
ReplaceWhat = "X_X_"
ReplaceWith = "X_"
vPath = "C:"
vFile = Dir(vPath & "*.csv")
Do While vFile <> ""
Name vPath & vFile As vPath & Replace(vFile, ReplaceWhat, ReplaceWith)
vFile = Dir
Loop
End Sub
So this works in a way that the first file has the X_ two times and that is why the replacement needs to applied. But is not there any better solution? And why the first loop runs one more extra time for the first file?
thank you
Andrew
I have to rename files in a folder in a way that there is an X_ added in front of the name of the file. I have managed it with this code:
Private Sub Command3_Click()
Path = "C:"
file = Dir(Path & "*.csv")
Do While file <> ""
Oldname = file
newname = Path & "X_" & Oldname
Name Path & Oldname As newname
file = Dir
Loop
ReplaceWhat = "X_X_"
ReplaceWith = "X_"
vPath = "C:"
vFile = Dir(vPath & "*.csv")
Do While vFile <> ""
Name vPath & vFile As vPath & Replace(vFile, ReplaceWhat, ReplaceWith)
vFile = Dir
Loop
End Sub
So this works in a way that the first file has the X_ two times and that is why the replacement needs to applied. But is not there any better solution? And why the first loop runs one more extra time for the first file?
thank you
Andrew