Posts: 23
Threads: 8
Joined: Aug 2005
This script renames a txt file but for some reason turns it into a folder, and thereafter the folder does not delete each time but they accumulate.
I just want to rename a file.
*scratches head*
str s
DATE d.getclock
s.timeformat("{D} {hhmmss}" d)
str n.from("g:\last backup " s ".txt")
ren- "g:\last backup*.txt" n
Posts: 1,338
Threads: 61
Joined: Jul 2006
03-11-2021, 02:03 PM
(This post was last modified: 03-11-2021, 11:36 PM by Kevin.)
You have two problems with the code your using . When using wildcard characters in filename part of
from. Then
to must be folder. All matching files will be copied to the folder.
also you have invalid filename characters in your date string
these are not allowed in filenames in windows
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
need to first enumerate to find the file then remove invalid filename characters then can rename
Dir d
foreach(d "$desktop$\last backup*.txt" FE_Dir)
,str path=d.FullPath
,if(path.len)
,,str s.timeformat("{D} {hhmmss}")
,,s.ReplaceInvalidFilenameCharacters("-")
,,str n.from("$desktop$\last backup" s ".txt")
,,ren- path n
Posts: 23
Threads: 8
Joined: Aug 2005
Thanks, but it's now hitting an error at Fullpath: "unknown member".
The date string was actually outputting fine before, I'm not sure why that needed fixing - I'm not even sure which is the invalid character.
Posts: 1,338
Threads: 61
Joined: Jul 2006
the date string would of course always output but would not work as a filename because your not allowed to use / in filenames.
Please show your code
should look like this.
Dir d
foreach(d "G:\last backup*.txt" FE_Dir)
,str path=d.FullPath
,if(path.len)
,,str s.timeformat("{D} {hhmmss}")
,,s.ReplaceInvalidFilenameCharacters("-")
,,str n.from("G:\last backup" s ".txt")
,,ren- path n
Posts: 23
Threads: 8
Joined: Aug 2005
Tried that, as well as the original code you provided. Both give "unknown member" error at Fullpath.
Posts: 1,338
Threads: 61
Joined: Jul 2006
03-12-2021, 01:43 PM
(This post was last modified: 03-12-2021, 02:22 PM by Kevin.)
What version of Quick Macros are you using?
I think you may be using an older version of QM
d.FullPath has been in qm since version 2.4.0
try this
Dir d
foreach(d "G:\last backup*.txt" FE_Dir)
,str path=d.FileName(1)
,if(path.len)
,,str s.timeformat("{D} {hhmmss}")
,,s.ReplaceInvalidFilenameCharacters("-")
,,str n.from("G:\last backup" s ".txt")
,,ren- path n
Posts: 23
Threads: 8
Joined: Aug 2005
Thanks, that works. Really appreciated. Pity this simple operation needs full-on programming skills - I'm afraid that's beyond me.
I'm using v.2.3.3.7 because I need the password box which was removed with 2.4 and that issue
wasn't resolved.