Jump to content
Macro Express Forums

Inrease File Names By 1


alexmih

Recommended Posts

I have a folder of files that are all numers (66.jpg, 67.jpg) but I need to increase each file by one. How can I

 

1) sort in numeric order,

2) highlght top file with mouse

3) get that file name,

4) read into a numeric variable

5) increase the value (56 becomes 57)

6) rename the same file (no name conflict)

7) move cursor down to next file

 

REPEAT till end of folder??

 

I can code most of this except I doi not know how to do th first thing -- witrh a highlighted file, get the filename of the highlighted file.

 

Thanks

Link to comment
Share on other sites

I hope you realise you have to process the list of files from the highest number back to one? Suppose these files exist

01.jpg

02.jpg

03.jpg

04.jpg

Now renameing 01.jpg to 02.jpg conflicts with the existing file 02.jpg etc.

So rename 04->05, 03->04, 02->03, 01->02.

 

 

Sorting: click on the column header in your Explorer window (maybe using Get Control).

 

If sorting is the problem, try the built in Rename File or Files command. With a Repeat use the counter variable to rename the file directly.

Link to comment
Share on other sites

You might try something like the following. I did not test or debug this macro. You will need to adjust it for your purposes.

// Initialization
Variable Set Integer %N1% to 0

// The repeat loop puts the filenames in T1
Repeat with Folder
 // Get the filename without the path or extension and put it in T2
 Variable Set From File Path
 Variable Modify String: Convert %T2% to integer %N1%
 // Get the larger of N1 or N2
 If Variable %N1% > variable %N2%
   Variable Modify Integer: Copy %N1% to %N2%
 End If
Repeat End

// Here: N2 contains the highest numbered filename

Repeat Start (Repeat %N2% times)
 Variable Modify Integer: Copy %N3% to %N4%
 Variable Modify Integer: Inc (%N4%)
 
 // Rename one file at a time
 If File Exists "%N3%"
   Rename File or Files: "%N3%.jpg"
 End If
Repeat End

You can copy this and paste it into your macro:

<REM2:Initialization><IVAR2:01:01:0><REM2:><REM2:The repeat loop puts the filenames in T1><REP3:07:000002:000001:0001:0:01:c:\test><REM2:Get the filename without the path or extension and put it in T2><VFFILE:1:F:1:F:1:T:2:F:1:%T1%><TMVAR2:05:02:01:000:000:><REM2:Get the larger of N1 or N2><IFVAR2:5:01:4:N2><NMVAR:07:01:0:0000002:0:0000000><ENDIF><ENDREP><REM2:><REM2:Here: N2 contains the highest numbered filename><REM2:><REP3:01:%N2%:0000-1:%N2%:1:03:><NMVAR:07:03:0:0000004:0:0000000><NMVAR:08:04:0:0000004:0:0000000><REM2:><REM2:Rename one file at a time><IFOTH:01:2:c:\test\%N3%>.DOFILE:06:NN:c:\test\%N3%>c:\test.jpg\%N4.jpg%><ENDIF><ENDREP>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...