Saturday, September 20, 2014
   
Text Size
Login

Batch Process to rename multiple files using Windows DOS

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

What?
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 
  4.   
  5.  -- What I want 
  6.  Image00001.jpg 
  7.  Image00002.jpg 

How?
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.

AHK Countdown Tooltip

Applies to:
  • Microsoft Windows 7 Enterprise
  • AutoHotkey (see code for AHK version)

What?
Someone suggested an app that counts the days I have left serving my notice. I thought I'd go one better and have it calculate to the nearest second. I call this latest app "byeBU" and this is version 0.4 Beta (unofficial app).

Why?
Something to do...

How?

MS-DOS: Copy folders without overwriting files

What?
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.

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

A for loop within a for loop in MS-DOS

What?
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.

Why?
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.

How?
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:

Autohotkey Count Number of Files/Folders in a Directory

What?
So this is an article to list methods of retrieving the number of files in a folder/directory.

Why?
Why can't we just use a loop and file pattern native to the Autohotkey programming language:

  1.  UserFolder:="C:" 
  2.  -- UserFolder := RegExReplace( MyInputField, "\\$")  ; gets rid of trailing slash if required 
  3.   
  4.  -- Method #1 
  5.  count := 0 
  6.  Loop, %UserFolder%\*.*, 0, 1  
  7.    count++ 
  8.   
  9.  -- note for future use: 
  10.  ; if A_LoopFileAttrib contains H,R,S 
  11.  ;     continue 
This works fine at home on your local host on a local drive. Try using this over a networked drive and more time will be spent counting the files then the actual processing (or whatever your script is trying to do).

Subcategories

Latest Posts