How to construct batch or macro in Win OS

  • Thread starter Thread starter Ouabache
  • Start date Start date
  • Tags Tags
    Batch Os
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 2K views
Messages
1,349
Reaction score
10
In a windows (98,XP,VISTA) OS, is there a simple procedure to create a macro to rename files by adding a string of character(s) at the beginning (or end) of each existing filename within a folder?

I often run into repetitive tasks on my computer(s), for example; renaming files within
a folder in a sequence. I have a folder with 120 songs in it and don't want the OS manager to sort them alphabetically, but in a specific order designated by number e.g. 1,2,3...120
When I created each file, I began numbering them this way. However when I was done, the file system sequenced them in a way I didn't appreciate.. e.g. 100-120 is listed before 20-99, things like that... So I have begun to rename my files, with a leading 3 digit sequence.. 001,002,...120

This is the tedious task that I would like write a batch or macro to accomplish the renaming.
I recall being able to create small macros similar to this, in UNIX on the university mainframe.
 
Last edited:
Physics news on Phys.org
One thing you could do is to use a text editor. Use something like this:

dir /b >t.bat

That gets you a list of files. You can then use a text editor's macro recording to construct the rename statement and then replay it.
 
.. or maybe use the editors search/replace with wildcards and regular expressions
 
silverfrost said:
One thing you could do is to use a text editor. Use something like this:

dir /b >t.bat

That gets you a list of files. You can then use a text editor's macro recording to construct the rename statement and then replay it.

Thanks for your suggestion. I just tried a sample directory with using this modified syntax:
dir /b >folder_list.txt and see what you mean about it listing the file names in a text file (alphabetically). (where "> " is used to redirect the dir list output to a file instead of the terminal window). Now I need to teach myself about recording macros.

You've also alerted me that DOS command language is alive an well in modern Window's OS's.
I will review some of these. e.g. http://www.windowsvistauserguide.com/vista_dos_commands.htm".
Also http://commandwindows.com/batchfiles-iterating.htm" seems like a useful idea for my application.
 
Last edited by a moderator:
Yes, the old DOS batch files are alive and well, as you have found out. There is also something new, Windows Power Shell, which is available for Win Server 2003 and later, and Win XP SP3, and Vista. Using Power Shell you can write what are called cmd-lets. I don't know much about them other than they are tied into .NET Framework and can be used and written to do batch-file sorts of things.

If that's of interest, here's link: http://support.microsoft.com/kb/926139
 
other recommendations:

1) Download free Visual Studio or eclipse or perl and make compile the source in your preferred language

2) Write a macro in excel using vba that should also do the job