|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
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. |
|
|
|
|
|
#2 |
|
Member (10 bit)
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|