string substituation within for loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Viper9000
Posts: 2
Joined: 02 May 2010 23:56

string substituation within for loop

#1 Post by Viper9000 » 03 May 2010 00:15

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: string substituation within for loop

#2 Post by !k » 03 May 2010 01:14

Use %%~nxD instead of %%D. See details in the command for Help.

Viper9000
Posts: 2
Joined: 02 May 2010 23:56

Re: string substituation within for loop

#3 Post by Viper9000 » 03 May 2010 01:51

Hello,

@!K: Thank you, it works.

Viper

Post Reply