Skip to content

Instantly share code, notes, and snippets.

@n3tn0de
Last active March 8, 2017 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n3tn0de/ffd02b07155a2e7f9e234df1024164a3 to your computer and use it in GitHub Desktop.
Save n3tn0de/ffd02b07155a2e7f9e234df1024164a3 to your computer and use it in GitHub Desktop.
change-extention-ignore

change-extention-ignore

Usage

change-extention-ignore.bat <directory> <target> <new-extention> [<ignored-files>]

To ignore more than one file specify the filenames separated by /.

Example

We want to change files' extention in ./Test/ from .txt to .bat, but preserve extention of test-ignore.txt.

Directory tree

├───Test
│       test-ignore.txt
│       test1.txt
│       test2.txt
│       test3.txt

Command arguments

> change-extention-ignore.bat Test *.txt .bat test-ignore.txt
test1.txt renamed to test1.bat
test2.txt renamed to test2.bat
test3.txt renamed to test3.bat
```
@echo off
rem Based on code from https://stackoverflow.com/questions/20670858/how-to-delete-all-files-in-a-folder-except-5-files
cd %1
setlocal EnableDelayedExpansion
for %%a in (%2) do (
if NOT "!exclude:/%%~a/" == "/%4/" (
echo %%~a renamed to %%~na%3
ren "%%~a" "%%~na%3"
)
)
endlocal
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment