Go Back   PCMech Forums > Windows Support > Windows Legacy Support (XP and earlier)

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-24-2005, 05:31 PM   #1
Member (10 bit)
 
David_Jones's Avatar
 
Join Date: May 2000
Location: New Zealand
Posts: 546
DOS Batch File (!) - Run across folders, include a 'space', and append filename

Hi All,

I have a very small batch file that I have gotten to a certain point, but am not sure how to extend.

The entire batch file is on one line thus (called MyNamer):

FOR %%V IN (%1) DO FOR /F "tokens=1-6 delims=/: " %%J IN ("%%~tV") DO IF EXIST 20%%L%%K%%J-%%M%%N%%O%%~xV (ECHO Cannot rename %%V) ELSE (Rename "%%V" 20%%L%%K%%J-%%M%%N%%O%%~xV)

Credit for this should go to someone from whom I copied the basic structure, but I cannot recall the source - thanks if it was you!

Basically, this renames files matching the passed string (%1) using the format:

YYYYMMDD-HHMM.EXT

where EXT is whatever extension the file already had.

This is fine.

However, I would like to do the following two things (each independent of the other) that I cannot work out:

1) I would like to be able to run this across a folder and all it's sub-folders.

For example, if I have a folder C:\Temp and it contains a subfolder C:\Temp\David then I would like to be able to run the following:

MyNamer C:\Temp\*.*

and have that rename all files in C:\Temp and also the files in C:\Temp\David. Currently is does not cover the subfolders.


2) Change the format from "YYYYMMDD-HHMM.EXT" to "YYYYMMDD - HHMM.EXT". In other words put in a couple of spaces.


I could do this quite easily using VBA, but I would prefer to avoid that route if at all possible, and it does seem that it should be doable in a batch file!

Any help on any of those would be much appreciated.

Thanks,

David.

Last edited by David_Jones; 11-24-2005 at 05:36 PM.
David_Jones is offline   Reply With Quote
Old 11-24-2005, 06:12 PM   #2
Member (10 bit)
 
David_Jones's Avatar
 
Join Date: May 2000
Location: New Zealand
Posts: 546
As is so typical, I was given a solution to the 'spaces' issue a few minutes ago, having sat on this for a week!

Basically, you just enclose the spaces in quotes

FOR %%V IN (%1) DO FOR /F "tokens=1-6 delims=/: " %%J IN ("%%~tV") DO IF EXIST 20%%L%%K%%J" "-" "%%M%%N%%O" "-" "%%V (ECHO Cannot rename %%V) ELSE (Rename "%%V" 20%%L%%K%%J" "-" "%%M%%N%%O" "-" "%%V)

So, the only thing I now need is to be able to run it across folders, and their sub-folders automatically.

Any help on that one would be very welcome.

Thanks,

David.
David_Jones is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:11 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2