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

Discussion Overview

The discussion revolves around creating a macro or batch file in Windows operating systems (specifically Windows 98, XP, and Vista) to rename files by adding a string of characters to the beginning or end of existing filenames. The context includes addressing the challenge of maintaining a specific numerical order for files, particularly for a collection of songs, and exploring various methods to automate this repetitive task.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant inquires about a simple procedure to create a macro for renaming files in a specific order, expressing frustration with the default alphabetical sorting of filenames.
  • Another participant suggests using a text editor to generate a list of files with the command "dir /b >t.bat" and then using the editor's macro recording feature to construct and replay rename statements.
  • There is a mention of using search/replace functions with wildcards and regular expressions in text editors as an alternative approach.
  • A participant confirms the effectiveness of the "dir /b" command and expresses interest in learning about recording macros, noting the relevance of DOS command language in modern Windows OS.
  • Discussion includes the introduction of Windows Power Shell as a newer tool for batch processing, with a participant mentioning its integration with the .NET Framework and potential for similar tasks.
  • Additional recommendations include downloading programming environments like Visual Studio or Eclipse, or using Perl, as well as writing a macro in Excel using VBA to accomplish the renaming task.

Areas of Agreement / Disagreement

Participants present multiple approaches to the problem, with no consensus on a single method. Various tools and techniques are suggested, indicating a range of opinions on the best solution.

Contextual Notes

Participants reference specific commands and tools without resolving the limitations or dependencies on user familiarity with those tools. The discussion does not clarify the effectiveness or efficiency of the proposed methods.

Who May Find This Useful

Individuals looking to automate file renaming tasks in Windows, particularly those familiar with batch files, text editors, or programming environments.

Ouabache
Science Advisor
Homework Helper
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:
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
 

Similar threads

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