How to construct batch or macro in Win OS

  • Thread starter Ouabache
  • Start date
  • Tags
    Batch Os
In summary, using a text editor, you can record a rename command to create a batch file to rename files in a specific order.
  • #1
Ouabache
Science Advisor
Homework Helper
1,346
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
  • #2
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.
 
  • #3
.. or maybe use the editors search/replace with wildcards and regular expressions
 
  • #4
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:
  • #5
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
 
  • #6
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
 

Related to How to construct batch or macro in Win OS

1. What is a batch or macro in Win OS?

A batch or macro in Win OS is a script or set of commands that can be executed in sequence to automate tasks in Windows operating system. It can be used to perform repetitive tasks or to customize the functionality of the system.

2. How do I create a batch or macro in Win OS?

To create a batch or macro in Win OS, you can use the built-in Windows programs like Notepad or Command Prompt. You can write the commands in a text file with a .bat extension for a batch file, or a .mcr extension for a macro file. Alternatively, you can use third-party software specifically designed for creating batch or macro files.

3. What are the benefits of using batch or macro in Win OS?

The use of batch or macro in Win OS can save time and effort by automating repetitive tasks. It can also reduce the chances of human error, increase productivity, and allow for customization of the system's functionality.

4. Can I run a batch or macro in Win OS on a schedule?

Yes, you can use the Windows Task Scheduler to run a batch or macro file on a specific schedule. This allows for more efficient automation of tasks, as you can set the script to run at a specific time or interval.

5. How do I edit or modify an existing batch or macro in Win OS?

To edit or modify an existing batch or macro in Win OS, you can open the file in a text editor and make the necessary changes. Alternatively, if you used a third-party software to create the file, you can open the program and make the changes within the interface. Make sure to save the changes before running the script again.

Similar threads

  • Programming and Computer Science
Replies
11
Views
1K
  • Computing and Technology
Replies
10
Views
3K
Replies
4
Views
5K
  • STEM Academic Advising
Replies
13
Views
2K
  • General Discussion
Replies
11
Views
25K
Back
Top