|
jovejupiter
|
 |
« on: November 25, 2005, 06:46:18 AM » |
|
Hi
I'm looking for a simple way to rearrange blocks of text within filenames as a batch process.
The reason is that I enjoy listening to old US radio adventure and scifi series from the 1940s and 50s, such as Suspense, Escape and DimensionX. A lot of shows are in circulation but the file naming style varies - for example showname-date-episodenumber-episodetitle.mp3 or showname-episodenumber-date-episodetitle and so on. I'd like to be able to get a consistent set of names to help identify duplicates etc.
The program would need to take a filename of the form AxBxCxDxE.*, where A,B,C,D and E are blocks of text of at least one character, and x represents a spacer character which could be any valid character for XP filenames. It would then rearrange the name to, for example BxExDxCxA.*, or whatever sequence was required, and repeat the process for all of the files in a specified folder.
I imagine the interface would be a window with three boxes - one box to specify the folder containing the files to me renamed (ideally with the usual browse button), one box to specify the spacer character and one box to list the required sequence of text block in the new file names.
An alternative would be a command line program where the command would look something like: c:\path\program c:\folder x 53214 where the files are located in c:\folder, the spacer character is x and the rename process would be AxBxCxDxE.* changed to ExCxBxAxD.*
Ideally the program should handle filenames with up to 9 blocks of text
I've searched the net for a suitable program but only found one which claimed to be able to do it. Unfortunately it had vast numbers of options (total overkill for this application), had a confusing interface and was very poorly documented. As a result I never managed to get it to work properly
A simple solution would be very much appreciated.
Thanks in advance
Tony
|
|
|
|
|
Logged
|
|
|
|
|
mouser
|
 |
« Reply #1 on: November 25, 2005, 06:52:18 AM » |
|
this sounds like a nice feature to have in a renamer - but before someone like skrommel tries to write this, might i recommend instead we look for a renamer which already supports something like this using regular expression rename, which would work well in this case.
|
|
|
|
|
Logged
|
|
|
|
|
f0dder
|
 |
« Reply #2 on: November 25, 2005, 06:54:18 AM » |
|
Yes, a RegEx file renamer would be very nifty... I know some irc guy who wrote one a while ago (main purpose was renaming MP3s I think), but I haven't seen him in a while :/
|
|
|
|
|
Logged
|
 - carpe noctem
|
|
|
|
|
mouser
|
 |
« Reply #3 on: November 25, 2005, 07:01:32 AM » |
|
surely most of the renamers support regex rename
|
|
|
|
|
Logged
|
|
|
|
|
mouser
|
 |
« Reply #4 on: November 25, 2005, 07:05:24 AM » |
|
though i have to admit that the basic procedure being asked for is a nice idea - might i add to this the ability to CHANGE the separator character.
ie change from A,B,C,D to D - B - A
i still think is kind of crazy to write this separately from a renamer as a new project.
|
|
|
|
|
Logged
|
|
|
|
|
skrommel
|
 |
« Reply #5 on: November 25, 2005, 02:43:07 PM » |
|
 Here's a quick script I think works... Just edit the three first lines. Edited 2005.27: Changed the script to work properly with multiple files. Skrommel [ copy or print] path    =C:\Temp       ;Path to the files to rename inseparator=-          ;Char(s) separating the parts of the filename outfile  =<4><2>test<2>-<1>  ;Pattern of the output filename ;infile  =<1>-<2>-<3>-<4>   ;Pattern of the input filename, not used Loop,%path%\*.*,,1 { outname=%outfile%  Splitpath,A_LoopFileFullPath,name,dir,ext,name_no_ext,drive  StringSplit,name_,name_no_ext,%inseparator%  Loop,%name_0%   %A_Index%:=name_%A_Index%  Loop,%name_0%  {   part:=%A_Index%   StringReplace,outname,outname,<%A_Index%>,%part%,ReplaceAll  }  FileMove,%A_LoopFileFullPath%,%dir%\%outname%.%ext% }
|
|
|
|
« Last Edit: November 26, 2005, 07:26:43 PM by skrommel »
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #6 on: November 26, 2005, 09:39:27 AM » |
|
Hi Skrommel,
Thanks for the script. This is probably going to seem an odd question for a forum like this, but how do I run it? I've been using computers since the late 70s but somehow I've never had time to get into coding. (apart from HTML and assorted in-programme macros)
As an aside, can anybody recommend a good introduction to scripting, which takes you from the real basics up to a reasonably competent level? Things like this make me think that I really should put some time aside to learn more about the subject.
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|
mouser
|
 |
« Reply #7 on: November 26, 2005, 09:55:18 AM » |
|
it's not an add question - i think skrommel is so used to using "AutoHotkey" that he forgets that most of the world has never heard of it. all of skrommel's utilities are written in a very cool free scripting language system called AutoHotkey: http://www.autohotkey.com/it's definitely worth installing since you'll probably be seeing more scripts from skrommel you like  most of the time skrommel adds tools to his page but sometimes if its short like this one he just pastes it in a reply. so you would copy and paste his code and save it as a file with a .ahk extension, and then after you install AutoHotkey you can run it (or compile it into an exe using autohotkey tool). while i'm here i have a question for skrommel: 1) can we drag and drop files onto this autohotkey script from explorer to have them renamed? 2) if we compile the script can we do this? 3) in your line setting the separator, would there be a way to specify a SPACE character as a separator?
|
|
|
|
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #8 on: November 26, 2005, 12:44:59 PM » |
|
Thanks Mouser,
I'll have a look at AutoHotkey
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|
|
|
skrommel
|
 |
« Reply #10 on: November 26, 2005, 06:21:05 PM » |
|
 Sorry about that! I just threw it together (and edited it about 10 times after posting it!) so I forgot to add the usual AutoHotkey info. @mouser: 1) can we drag and drop files onto this autohotkey script from explorer to have them renamed? 2) if we compile the script can we do this? This can easily be added if you compile or say yes to allow dropping on AHK-file when installing AHK. 3) in your line setting the separator, would there be a way to specify a SPACE character as a separator? Check out the PatternRenamer script below. It supports drag and drop or a command line, you can use <space> as a separator, and you can have a multichar separator or several singlechar ones. It also shows a preview of the first new filename before starting the renaming. Skrommel [ copy or print] ;PatternRenamer.ahk ; Rename files ;Skrommel @2005  www.donationcoders.com/skrommel #SingleInstance,Force SetBatchLines,-1 ;AutoTrim,Off separator  =-<space>      ;Char(s) separating the parts of the input filename, use <space> for space oneseparator=1          ;0=No 1=Yes Treat the separator as one unit? outpattern =<4><2>test<2>-<1>  ;Pattern of the output filename inpattern  =<1>- <2>- <3>- <4> ;Pattern of the input filename, not in use, just to explain! Loop,%0% {  StringReplace,inseparator,separator,<space>,%A_Space%,ReplaceAll  outfile=%outpattern%  shortpath:=%A_Index%  Loop,%shortpath%   longpath=%A_LoopFileLongPath%  SplitPath,longpath,name,dir,ext,name_no_ext,drive  If oneseparator=1  {   StringReplace,name_no_ext,name_no_ext,%inseparator%,``,ReplaceAll   StringSplit,name_,name_no_ext,``  }  Else   StringSplit,name_,name_no_ext,%inseparator%  Loop,%name_0%   %A_Index%:=name_%A_Index%  Loop,%name_0%  {   part:=%A_Index%   StringReplace,outfile,outfile,<%A_Index%>,%part%,ReplaceAll  }  Loop,10   StringReplace,outfile,outfile,<%A_Index%>,,ReplaceAll  If A_Index=1  {   msg=InFile:`t`t%longpath%   msg=%msg%`nOutFile:`t`t%dir%\%outfile%.%ext%   msg=%msg%`nSeparator:`t%separator%   msg=%msg%`nOneSeparator:`t%oneseparator%   msg=%msg%`nInPattern:`t%inpattern%   msg=%msg%`nOutPattern:`t%outpattern%   MsgBox,4,Is this correct?,%msg%   IfMsgBox,No    Break  }  FileMove,%longpath%,%dir%\%outfile%.%ext%,1 }
|
|
|
|
« Last Edit: November 26, 2005, 07:29:45 PM by skrommel »
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #11 on: November 26, 2005, 06:34:57 PM » |
|
Hi again Skrommel,
I downloaded AutoHotkey which looks extremely useful - The only problem is that your script only rearranges the name of the first file in the folder and doesn't repeat the operation for the other files.
The documentation on the website looks pretty extensive - Does anybody have the whole set of documentation as a single pdf (or similar) rather than as a set of web pages?
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #12 on: November 26, 2005, 06:43:42 PM » |
|
Hi again Skrommel,
I converted your pattern renamer script to an exe on my desktop and it seems to work fine for drag and drop.
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #13 on: November 26, 2005, 07:08:20 PM » |
|
Hi again,
The program is converting multiple files but seems to miss a few files and leaves them unchanged.
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|
skrommel
|
 |
« Reply #14 on: November 26, 2005, 07:30:51 PM » |
|
 Still got problems? Care to elaborate? Skrommel
|
|
|
|
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #15 on: November 27, 2005, 12:21:05 PM » |
|
Hi Skrommel,
I created 15 text files, all identical except for their names which ran from series-date-001-episode.txt to series-date-015-episode.txt
As a test I wanted to reverse the order of the parts, so I set the relevant part of the input ahk file to
separator =- ;Char(s) separating the parts of the input filename, use <space> for space oneseparator=1 ;0=No 1=Yes Treat the separator as one unit? outpattern =<4>-<3>-<2>-<1> ;Pattern of the output filename inpattern =<1>-<2>-<3>-<4> ;Pattern of the input filename, not in use, just to explain!
If I understand the code correctly, that should take files of the form A-B-C-D.* and convert them to D-C-B-A.*
As I'm not completely familiar with AutoHotkey yet, I converted the script to an exe file using Ahk2Exe.exe and placed it on my desktop.
Then I dragged the 15 files to the desktop icon.
Files number 004 to 115 were converted correctly but files number 001 to 003 were unchanged.
I then dragged the 3 remaining files to the desktop icon and file 003 was converted.
Dragging files 001 and 002 to the icon converted file 002
Finally dragging file 001 to the icon converted it.
Is there something I've misunderstood about how to set up the input parameters or is there a problem with the code?
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|
skrommel
|
 |
« Reply #16 on: November 27, 2005, 06:17:43 PM » |
|
 Hmmm.... Is this a problem with the topmost script, too? Skrommel
|
|
|
|
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #17 on: November 28, 2005, 03:20:20 PM » |
|
Hi again Skrommel,
I converted the original script to an exe without any modifications and dragged the 15 files to the desktop icon.
All 15 file names were changed, with the format:
series-date-001-episode.txt to test-series-date-001-episode.txt
The input part of the script reads:
separator =-<space> ;Char(s) separating the parts of the input filename, use <space> for space oneseparator=1 ;0=No 1=Yes Treat the separator as one unit? outpattern =<4><2>test<2>-<1> ;Pattern of the output filename inpattern =<1>- <2>- <3>- <4> ;Pattern of the input filename, not in use, just to explain!
If I'm reading the code correctly I would expect this to do nothing to the files in this case as the separator is - and not -<space>
If it accepted the spacer it should end up with file names of the form:
episode-datetestdate-series.
Regards
Tony
|
|
|
|
|
Logged
|
|
|
|
|
skrommel
|
 |
« Reply #18 on: November 28, 2005, 03:56:33 PM » |
|
 The topmost script does not handle <space>, and it also handles the separator chars individually. I just need to know if there's bug in the renaming or the dragging and dropping. Skrommel
|
|
|
|
|
Logged
|
|
|
|
|
jovejupiter
|
 |
« Reply #19 on: November 28, 2005, 04:07:45 PM » |
|
Hi Skrommel,
The original script renames all of the files in the same way (none are missed out) but the sequence of the parts in the new file names is incorrect.
Changing the input parameters results in the rename working correctly for some files but some are left unchanged.
Cheers
Tony
|
|
|
|
|
Logged
|
|
|
|
|