Page 1 of 1

string substituation within for loop

Posted: 03 May 2010 00:15
by Viper9000
Hello,

i want to decrypt every file within a folder. For this task i need the filename without the directory part. So i tried the following:

@echo off

SET SrcDir=C:\scripts\SrcDir
SET DestDir=C:\scripts\DestDir

for %%D in ("%SrcDir%"\*.*) do (

SET FILE=%%D
SET FILE=%file:C:\Scripts\SrcDir\=%
TOOL.exe --output %DestDir%\dec_%file% --decrypt
)


%%D returns the full file path e.g C:\scripts\SrcDir\test.txt
Maybe it is possible to write something like that:
SET FILE=%file:%SrcDir%=%

Thank you for help.

Viper

Re: string substituation within for loop

Posted: 03 May 2010 01:14
by !k
Use %%~nxD instead of %%D. See details in the command for Help.

Re: string substituation within for loop

Posted: 03 May 2010 01:51
by Viper9000
Hello,

@!K: Thank you, it works.

Viper