Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Weshuggah
- Posts: 7
- Joined: 16 Dec 2020 11:56
#1
Post
by Weshuggah » 05 Feb 2021 05:43
Hello,
This code below changes .dll files into .bak files in BaseFolder and its subfolders.
I just want to exclude files whose folder containing them has a specific name, let's say there is a subfolder called "DoNotModify".
Code: Select all
set folder=My\BaseFolder\
pushd "!folder!"
set "folderpath=!cd!"
if not "!folder:~-1!"=="\" set "folder=!folder!\"
for /R %%f in (*.dll) do (
ren "%%f" *.bak
)
popd
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 05 Feb 2021 08:49
Use string replacement to test if the folder exists within the folder path.
Code: Select all
for /R %%G in (*.dll) do (
set "foldercheck=%%~dpG"
IF "!foldercheck:DoNotModify=!"=="!foldercheck!" ren "%%~G" *.bak
)
Last edited by
Squashman on 05 Feb 2021 09:21, edited 2 times in total.
Reason: Fixed true/false logic
-
Weshuggah
- Posts: 7
- Joined: 16 Dec 2020 11:56
#3
Post
by Weshuggah » 05 Feb 2021 09:11
Hmm for some reason with this nothing happens, even if subfolder name is different, no files are being renamed.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 05 Feb 2021 09:38
You should probably change the rename to
The "n" modifier is the file name only. No path no extension.