Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ren- turns file into a folder
#1
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*
 
Code:
Copy      Help
str s
DATE d.getclock
s.timeformat("{D} {hhmmss}" d)
str n.from("g:\last backup " s ".txt")
ren- "g:\last backup*.txt" n
#2
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
Code:
Copy      Help
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
#3
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.
#4
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.
 
Code:
Copy      Help
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
#5
Tried that, as well as the original code you provided. Both give "unknown member" error at Fullpath.
#6
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
Code:
Copy      Help
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
#7
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.


Forum Jump:


Users browsing this thread: 1 Guest(s)