Batch File Renaming

May 19, 2009 at 17:01:34
Specs: Windows XP
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.

See More: Batch File Renaming

Report •

May 19, 2009 at 17:48:09
what have you tried?

Report •

May 20, 2009 at 00:36:19
<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

  set FN=!CD!
  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.


Report •

Related Solutions

Ask Question