hi there,
I have some files in a directory.
files are named this way :
~xxxx~.xls
Ans I would like to rename the files as :
xxxx - directoryname.xls
Assuming that by "directoryname" you mean the
last subfolder name in the fully qualified path to
the file, and assuming that you mean the tilde (~)
characters are constant as the first and final characters
of the base name (excluding extension) of each file, try this:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
FOR %%F IN ("C:\Path to\Your XLS files\*.XLS") DO CALL :_RENAME "%%F"
GOTO :EOF
:_RENAME
SET BN=%~n1
SET BN=%BN:~0,-1%
SET BN=%BN:~1%
SET STR=%1
:LOOP
FOR /f "tokens=1* delims=\" %%A IN (%STR%) DO (
IF NOT "%%B"=="" SET FLD=%%A
SET STR="%%B"
GOTO :LOOP
)
:: Remove ECHO/{demo} to activate REN command
ECHO/{demo}REN %1 "%BN% - %FLD%.*"
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting:
http://www.allenware.com/find?UsualSuspects
Replace the path specification:
"C:\Path to\Your XLS files\*.XLS"
with the correct path to your own XLS files (ensure you "quote"
any path specification that includes [Space]s), or pass it as a
parameter. Remove the ECHO/{demo} where shown to
activate the REN command when you are satisfied that
the demo does what you want.
--
William Allen
Free interactive Batch Course
http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples
http://www.allenware.com/icsw/icswref.htm
Header email is rarely checked. Contact us at
http://www.allenware.com/