How to construct batch or macro in Win OS

  • Thread starter Thread starter Ouabache
  • Start date Start date
  • Tags Tags
    Batch Os
Click For Summary
Creating a macro or batch file in Windows (98, XP, Vista) for renaming files can streamline repetitive tasks, such as adding a leading sequence to filenames. Users can utilize the command "dir /b > folder_list.txt" to generate a list of files, which can then be edited in a text editor to construct rename commands. DOS command language remains relevant in modern Windows OS, and tools like Windows PowerShell can also be employed for more complex batch operations. Learning to record macros in text editors or using VBA in Excel are additional methods suggested for automating the renaming process. Overall, various approaches exist to efficiently rename files in a specified order.
Ouabache
Science Advisor
Homework Helper
Messages
1,345
Reaction score
8
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:
Technology 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
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
4
Views
5K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 11 ·
Replies
11
Views
28K