Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Rename problem


  • Please log in to reply
4 replies to this topic
Elaphe
  • Members
  • 317 posts
  • Last active: Oct 03 2015 07:34 AM
  • Joined: 06 Dec 2012

I have some hundreds of files named like this:

 

Myfile 460082 15-04-2013.txt

Myfile 740189 21-11-2014.txt

Myfile 110226 18-03-2014.txt

etc.

 

The number after Myfile is random but it's always 6 digit long.

 

I know how to create a loop to rename all these filesl, but I don't know exactly what would be the best way to do this renaming. I need to change the format of the date to:

 

Myfile 460082 2013-04-15.txt

 

Any idea?



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

This should get you started. 

s = Myfile 460082 15-04-2013.txt
if RegExMatch(s, "(?P<File>.*\d{6}) (?P<D>\d{2})-(?P<M>\d{2})-(?P<Y>\d{4}).(?P<Ext>.*)", v)
    msgbox % "vFile: " vFile 
    . "`nvD: " vD 
    . "`nvM: " vM 
    . "`nvY: " vY 
    . "`nvExt: " vExt 

And of course create a list of the files you wish to rename, and then perform the loop on this list. Otherwise you might rename the same file twice.



vsub
  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011

How about this:

File = Myfile 460082 15-04-2013.txt
StringRight,Date,File,14
StringSplit,Date,Date,-
MsgBox,% SubStr(File,1,StrLen(File)-14) SubStr(Date3,1,4) "-" Date2 "-" Date1 ".txt"


RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

The myFile part is probably of variable size so perhaps.

File = Myfile 460082 15-04-2013.txt

StringRight,Date,File, % instr(file, ".") - 11
StringSplit,Date,Date,-
MsgBox,% SubStr(File,1,StrLen(File)-(instr(file, ".") - 11)) SubStr(Date3,1,4) "-" Date2 "-" Date1 ".txt"



Elaphe
  • Members
  • 317 posts
  • Last active: Oct 03 2015 07:34 AM
  • Joined: 06 Dec 2012

thanx RHCP. It works great.