Computing.Net > Forums > Programming > Batch File Renaming

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Renaming

Reply to Message Icon

Name: btklassen
Date: May 19, 2009 at 17:01:34 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I have a set of numbered folders (001, 002, etc.) each of which contain a series of data files. These data files do not necessarily have unique names (ie. the same filename may be used for a different file in the 001 and 002 folders). What I'd like to do is run a batch for all folders (which could be placed into a master folder if needed) that accesses all files in the folders and renames them to include the folder name as a prefix. For example, the file 1Kl1 in folder 001 should be renamed 001_1Kl1 and the file 1Kl1 in folder 002 should be renamed 002_1Kl1. There are hundreds of folders so I'd like the batch to apply to all folders at once if possible.



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: May 19, 2009 at 17:48:09 Pacific
Reply:

what have you tried?


0

Response Number 2
Name: Mechanix2Go
Date: May 20, 2009 at 00:36:19 Pacific
Reply:

<B>:: prepend folder NUM NNN to files inside
:: prefixn Wed 20-05-2009 14:05:55.60

@echo off & setLocal EnableDelayedExpansion

pushd c:\files

for /f "tokens=* delims= " %%a in ('dir/s/b/ad') do (
  pushd %%a
  call :sub1
    for /f "tokens=* delims= " %%i in ('dir/b/a-d') do (
    echo ren %%i !FN!_%%i
    )
)

goto :eof

:sub1
  set FN=!CD!
  :loop
  for /f "tokens=1* delims=\" %%f in ("!FN!") do (
    if "%%g" neq "" (
    set FN=%%g
    goto :loop
    )
  ) 
goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Renaming

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/18676.html

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/8204.html

Automated batch-file renaming www.computing.net/answers/programming/automated-batchfile-renaming/13367.html