Jump to content
Macro Express Forums

Removing part or parts of a filename


Gawwad

Recommended Posts

If I have a list of files that go something like this:

1 xxx aaaaa

2 xxx bbbbb

3 xxx cccccc

 

How would I make a macro to remove the numbers infront of the filename?

 

It's really annoying to do by hand when converting a load of my CDs to my computer and iPod...

Basic of the basics, do this:

Text Type: <CONTROL>a
Clipboard Copy
Variable Set String %T1% from Clipboard
Variable Modify String: Delete Part of %T1%
Text Type: %T1%

<TEXTTYPE:<CONTROL>a><CLIPC><TVAR2:01:03:><TMVAR2:11:01:00:001:002:><TEXTTYPE:%T1%>

 

Of course, depending on how the list is accessed (example in a program menu list vs. a list in a .txt or .doc file), you'll need to

add various other commands to make sure you get each line separately, but essentially, this is what you're looking for.

 

EDIT

Here is a real-world example of a macro I built to rename the files of a book on CD that I ripped in order to listen to it on my

SanDisk player. (Note: this macro is a lot shorter without all the Remarks)

// First, I make sure the top file is highlighted (I do this manually rather than using the macro)
// Repeat until all files have been renamed.
Repeat Until %T1% <> %T1%
 // Alt+f opens the File menu.  M opens the Rename window:
 Text Type: <ALT>fm<ENTER>
 Clipboard Empty
 Clipboard Copy
 Variable Set String %T1% from Clipboard
 // This book uses the - (hyphen) character to separate the Title, author, etc.from the track number.
 // If there is no hyphen, then I've reached the bottom of the list (an Icon file).
 // So if there is no hyphen, the macro can end.
 If Variable %T1% does not contain " -"
Break
 End If
 // I want to keep the track information, but don't want all the rest of it.
 Variable Set Integer %N1% from Position of Text in Variable %T1%
 Variable Modify String: Delete Part of %T1%
 Variable Modify String: Trim %T1%
 // Now I'm going to compare this track to the last track processed (saved in %T2%)
 // If this is the first run, then %T2% is blank.  However, if T1 = T2, I know I have 
 // already done this track, so either the macro failed, or I'm at the end.
 If Variable %T1% = variable %T2%
Break
 End If
 // Now I want to clear the track name, and put in my own track title that I'll be able to 
 // read on the tiny Sansa screen.
 Text Type: <DELETE>
 Text Type: WS Disk 01 - %T1%
 // And finally, I <ENTER> to save the new track name, 
 // and arrow down to the next item in the list.
 Text Type: <ENTER><ARROW DOWN>
 // Now I set T2 to T1 (as explained above).
 Variable Set String %T2% "%T1%"
Repeat End

<REM2:First, I make sure the top file is highlighted (I do this manually rather than using the macro)><REM2:Repeat until all files have been renamed.><REP3:08:000002:000001:0001:1:01:T1><REM2:Alt+f opens the File menu.  M opens the Rename window:><TEXTTYPE:<ALT>fm<ENTER>><CLIPE><CLIPC><TVAR2:01:03:><REM2:This book uses the - (hyphen) character to separate the Title, author, etc.from the track number.><REM2:If there is no hyphen, then I've reached the bottom of the list (an Icon file).><REM2:So if there is no hyphen, the macro can end.><IFVAR2:1:01:8: -><BREAK><ENDIF><REM2:I want to keep the track information, but don't want all the rest of it.><IVAR2:01:13:1:-><TMVAR2:11:01:00:001:N01:><TMVAR2:01:01:00:000:000:><REM2:Now I'm going to compare this track to the last track processed (saved in %T2%)><REM2:If this is the first run, then %T2% is blank.  However, if T1 = T2, I know I have ><REM2:already done this track, so either the macro failed, or I'm at the end.><IFVAR2:4:01:1:T2><BREAK><ENDIF><REM2:Now I want to clear the track name, and put in my own track title that I'll be able to ><REM2:read on the tiny Sansa screen.><TEXTTYPE:<DELETE>><TEXTTYPE:WS Disk 01 - %T1%><REM2:And finally, I <ENTER> to save the new track name, ><REM2:and arrow down to the next item in the list.><TEXTTYPE:<ENTER><ARROW DOWN>><REM2:Now I set T2 to T1 (as explained above).><TVAR2:02:01:%T1%><ENDREP>

 

This macro may be a little buggy, I never actually used it (turns out the copy of the disk I have is faulty, so I wasn't ever able to

listen to it (it's a manufactured original CD, not a burned copy), but you should be able to get a picture of how you can use this

method to alter your own tracks or other lists.

 

Without the Remarks it looks like this:

Repeat Until %T1% <> %T1%
 Text Type: <ALT>fm<ENTER>
 Clipboard Empty
 Clipboard Copy
 Variable Set String %T1% from Clipboard
 If Variable %T1% does not contain " -"
Break
 End If
 Variable Set Integer %N1% from Position of Text in Variable %T1%
 Variable Modify String: Delete Part of %T1%
 Variable Modify String: Trim %T1%
 If Variable %T1% = variable %T2%
Break
 End If
 Text Type: <DELETE>
 Text Type: WS Disk 01 - %T1%
 Text Type: <ENTER><ARROW DOWN>
 Variable Set String %T2% "%T1%"
Repeat End

<REP3:08:000002:000001:0001:1:01:T1><TEXTTYPE:<ALT>fm<ENTER>><CLIPE><CLIPC><TVAR2:01:03:><IFVAR2:1:01:8: -><BREAK><ENDIF><IVAR2:01:13:1:-><TMVAR2:11:01:00:001:N01:><TMVAR2:01:01:00:000:000:><IFVAR2:4:01:1:T2><BREAK><ENDIF><TEXTTYPE:<DELETE>><TEXTTYPE:WS Disk 01 - %T1%><TEXTTYPE:<ENTER><ARROW DOWN>><TVAR2:02:01:%T1%><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...