topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 11:38 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: File Renaming question  (Read 6045 times)

sajman99

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 664
    • View Profile
    • Donate to Member
File Renaming question
« on: January 04, 2010, 02:38 PM »
I need help to increment/decrement file names ranging from 7001-7100. Note that I don't have a complete continous set of 7001-7100 but only have some of the files (ie. 7005, 7006, 7009, 7012...).

I like and use both ReNamer and Ken Rename. In both apps there is a serialize mode which allows the user to start at a specific number and then sequence from there, but AFAIK that only works if there is a continuous set of files.

All I want to accomplish is to leave what I already have and decrement everything by a value of 1. So for example, decrementing 7005 becomes 7004, 7012 becomes 7011, etc.

Does anybody know how to accomplish this task with any software? btw I know I can do it manually one file at a time but that takes lots of time when dealing with many files.

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #1 on: January 04, 2010, 04:09 PM »
I'd cobble together a one-time batch file (DecRename.bat), one line per file:

rename file7005 file7004
rename file7006 file7005
rename file7009 file7008
rename file7012 file7011
etc

Lot's of ways to make the batch file.
- Get a list of the current files, from a command prompt "dir>filelist.txt"
- Edit filelist.txt to get just a list of filenames.
- Paste the list into a column in Excel.  Use a formula to decrement the file number (easy if it's always the same two digits) in another column.  In a third column use a concatenation formula:  +"rename "&firstcolumncell&" "&secondcolumncell  
- Copy the third column and paste it into DecRename.bat
- Run DecRename.bat in the directory with the files  

If you can quickly edit the filelist and do the stuff in Excel this shouldn't take long if the filenumbers are always the same distance from the end of the filename string.  If the files are in numerous multiple folders you could generate a list with full paths using something different than the dir command.

This occurred to me first.  There's probably an easier way...
« Last Edit: January 04, 2010, 04:10 PM by AndyM »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #2 on: January 04, 2010, 04:26 PM »
Bulk Rename Utility has a regular expression facility but I'm not sure if you can do math on the matches to do the increment/decrement.

Only thing I'd say, if you use a script or batch, is for a decrement run, make sure to sort low to high and start with the lowest number and end with the highest.  The reverse for an increment run. IOW the sequence of processing should avoid overwriting existing files(obvious true, but easy to forget once you start messing with the implementation.)

If the filenames are actual numbers only then it should be pretty easy to get a directory listing and do a sort by various means as AndyM suggested.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #3 on: January 04, 2010, 04:43 PM »
what's the file naming convention here - do we assume the files are all named 7XXX.XTN, or is there some other convention involved?

Are they all in a single folder?

in subfolders?

sajman99

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 664
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #4 on: January 04, 2010, 05:12 PM »
Actually it was a hypothetical just so I can try to understand the concept. :-[ But let's say the file names are all 4 digits beginning with 7--in the range of 7001 and 7100 /.jpgs in the same folder.
« Last Edit: January 04, 2010, 05:22 PM by sajman99 »

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #5 on: January 04, 2010, 07:36 PM »
this will do what you want (in AHK)

fileselectfolder, mypath, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}

Loop, %mypath%\*.jpg
{
    stringtrimright, FName, a_loopfilename, 4
    fname:= floor(Fname - 1)
    Mylist.= a_loopfilefullpath . "~" . a_loopfiledir . "\" . fname . "`." . a_LoopFileExt . "`n"
}

sort, mylist, U

loop, parse, mylist, `n
{
    stringsplit, F2, a_loopfield, ~
    filemove, %F21%, %F22%, 1
}
exitapp

code loops through the nominated directory and creates a list of files.  it then sorts the list in ascending order (to avoid overwriting another file incorrectly), then moves the files to the new name

note that this very basic - it assumes all filenames are numeric (so alpha filenames may skew the results), and it won't start/stop at a given point (it will just plow through the whole directory)

anyways, it should give you an idea....

sajman99

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 664
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #6 on: January 05, 2010, 12:48 PM »
Thanks very much for the help. :)

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #7 on: January 06, 2010, 05:58 AM »
I just want to mention that ReNamer can do this too  :Thmbsup:

Here is an quick ReNamer script which will increase all numbers in an file name after an string:

     //Because some renamed names already exists, we will add an special sign '#' into the new name to get an unique name.
     //First rename the files with this PascalScript rule,
1. step)
File 7001.txt   File 7002#.txt
File 7002.txt   File 7003#.txt
File 7003.txt   File 7004#.txt
File 7004.txt   File 7005#.txt
File 7010.txt   File 7011#.txt
File 7100.txt   File 7101#.txt


    // then do an second run and
    //use an replace rule to remove that #-sign: Replace: Replace all "#" with "" (skip extension)
2. step)
File 7002#.txt   File 7002.txt
File 7003#.txt   File 7003.txt
File 7004#.txt   File 7004.txt
File 7005#.txt   File 7005.txt
File 7011#.txt   File 7011.txt
File 7101#.txt   File 7101.txt

Code: Text [Select]
  1. //PascalScript for den4b's ReNamer (http://www.den4b.com/projects.php), 2010 by Stefan
  2. //Purpose: Find number in file name and increase/decrease them.
  3. //This simple script works only for an file name pattern like:
  4. //Name 7001.txt  => Name 7002.txt
  5. //Name 7025.txt  => Name 7026.txt
  6. //For more tasks the script has to be modified, if you have the need please visit the ReNamer forum at http://www.den4b.com/forum/
  7.  
  8. var
  9. SubPatterns: TStringsArray;
  10.  
  11. Begin
  12.   SubPatterns:=SubMatchesRegEx(WideExtractBaseName(FileName),'(.+?)(\d+)',false);
  13.   if Length(SubPatterns) <=0 then exit;
  14.  
  15.      //Because some renamed names already exists, we will add an special sign '#' into the new name to get an unique name.
  16.      //First rename the files with this PascalScript rule, then do an second run and
  17.     //use an replace rule to remove that #-sign: Replace: Replace all "#" with "" (skip extension)
  18.     FileName := SubPatterns[0] + IntToStr(StrToInt(SubPatterns[1]) + 1) + '#' + WideExtractFileExt(FileName); //increment
  19.   //FileName := SubPatterns[0] + IntToStr(StrToInt(SubPatterns[1]) - 1) + '#' + WideExtractFileExt(FileName); //decrement
  20. End.
« Last Edit: January 06, 2010, 06:35 AM by AbteriX »

sajman99

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 664
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #8 on: January 06, 2010, 12:35 PM »
Thanks for telling, AbteriX. ReNamer is my favorite file renaming utility, but there's clearly lots I don't know about it. Needless to say, Bulk Rename Utility really overwhelmed me with all its options.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: File Renaming question
« Reply #9 on: January 06, 2010, 05:43 PM »
Thanks for telling, AbteriX. ReNamer is my favorite file renaming utility, but there's clearly lots I don't know about it. Needless to say, Bulk Rename Utility really overwhelmed me with all its options.

BRU can be a killer.  Most of the time unless I want to perform concurrent operations I just use the rename utility built into FreeCommander.  It has a simple numbering feature and macros for name, count etc..  The main downer for FC is it's 32 bit Delphi code.  Runs fine on 32 OS but on Vista64 it can be sluggish.  Sometimes I click on a file and it takes a second or two to move the highlight.