Monday, September 01, 2014
Text Size

Batch Process to rename multiple files using Windows DOS

Applies to:
  • Microsoft Windows 7 Professional
  • Ms-DOS Command Prompt (6.1.7601)

A quick article on how to rename multiple files using the command prompt and a bit of string manipulation. This example will rename files which contain the string " (Copy)" and replace it with nothing (so removes it). The challenge here is the space character and delimiting by a string.

The Gist

  1.  -- What I have 
  2.  Image00001 (Copy).jpg 
  3.  Image00002 (Copy).jpg 
  5.  -- What I want 
  6.  Image00001.jpg 
  7.  Image00002.jpg 

Before I continue, the undo may work in MS Windows (Control key + Z) but don't count on it. I'm going to use a short batch process but to save time on the different ways of doing this, the example below uses a command prompt to a) create a batch file b) use it to rename the files c) delete the batch file.

MS-DOS: Copy folders without overwriting files

A quick note on how to copy files and folders over without overwriting existing files. It's easy to say "Yes" and replace all files. What I need is something that synchronizes files on an internal hard drive to an external one. I wanted it to copy only the files that were new in the original folder and only copy those over (reason being, the archive is 4 terabytes and backing up only the changed files would speed things up).

Applies to:
  • Microsoft Windows XP
  • Microsoft Windows 7
  • Microsoft Windows 8
  • for Vista and Windows 2008 without XCOPY, try ROBOCOPY.

We're going to use MS-DOS because I'm that old.

A for loop within a for loop in MS-DOS

A quick note for myself as I'd forgotten how to do this (we're talking technology belonging to the 90s - MS-DOS v6.22). The example wants to loop through a directory and then loop through the line it finds.

I use another technology for automation but sometimes the simpler solution is the one I make for other people to use. Explaining MS-DOS batch programs is a lot easier and colleagues trust these more than my all-in-one GUI applications.

Note: we're using the code in a DOS Batch program so our variables have to be prefixed with a double-percent rather than just the one:

Determine if a program is run by another user

During a critical business period, we monitor the use of a program which only one user can be using at a time. We encountered the issue where the user who would go in to check for any errors, would forget to tell everyone else that they are no longer using the program when they are done.

The program is on a server to which our standard credentials cannot use the "OPENFILES" command on the server to determine who is using a specific program. We wanted IT staff to be able to check for this without disrupting other staff, all our IT staff are admins on standard workstations.

We don't have access to the server but what we do have is admin access to the workstations connected to that server. In order for the following to work, we had to pass the following criteria:
  • Administrator rights on remote workstation.
  • Need to know the computer name or IP address of the remote workstation.

Open a command prompt

  1.  tasklist /s <computername> 

Prefix Line Numbers in a Text File

Prefixing lines with their respective line number in a text file using a Microsoft Windows Operating System... I've just googled this as I couldn't remember how I did this last time and a number of people showing off their MS-DOS batch skills have proposed stupid extensive solutions when all you need is one command-line.

Working with programming languages, I often need to write the accompanying documentation. Within the documentation, I may want to refer to a line of code within a text file. I also find myself copying amounts of code into the same document and then needing lines prefixed so that I can explain the code.

Change contents of "original_file.txt"

  1.  The first line of my code 
  2.  The second line of my code 
  3.  The third line of my code 
To "results_file.txt"

  1.  1:  The first line of my code 
  2.    2:  The second line of my code 
  3.    3:  The third line of my code 


Latest Posts

  • Joes Quicklist Weblinks (JQW)

    • Mon 01-Sep-14
      Hi from France Download's link for the J3.1.1 version of JQW is broken ... have a nice day, Thanks ...
  • Joes Word Cloud (JWC)

    • Sat 23-Aug-14
      Salut Joe, Thank you again for helping me. I had installed V2.2 for Joomla 2.5. Finally, as you ...
    • Wed 20-Aug-14
      Salut Nathalie! I could only access the under construction page of your website, so I'm not 100% sure.
    • Tue 19-Aug-14
      Hi Joe, Thank you for your prompt reply. Below, an "image" of the cloud on my website : "pour ante ...
    • Mon 18-Aug-14
      Hi Nathalie, Thanks for the message. The module does not see Virtuemart text but that sounds like ...