Im in need to exclude all the JavaScript files which has a header "XYZ" inside it. if the pattern "XYZ" is present inside the file, then the batch should rename the file as *.js.exclude. I have almost 189 JS files present inside the sources which are inside different sub folders as well. Any help to write a batch which can do the above are appreciated
Asked
Active
Viewed 44 times
1 Answers
0
use findstr
.
/m
to get the filenames
/s
to process subfolders too
(/i
to ignore capitalization, if needed)
Put a for
loop around it to rename the files:
use %%a
for the full path/filename
use %%~nxa
for filename and extension only
surround your filenames with quotes to handle paths/filenames with spaces
for the same reason, use "delims="
for /f "delims=" %%a in ('findstr /s /m "XYZ" *.js') do ECHO ren "%%a" "%%~nxa.exclude"
After debugging, remove ECHO
if the output is ok.

Stephan
- 53,940
- 10
- 58
- 91
-
Is this script that I can run directly from CMD with folder path kept or should I create a bat file with this script. Running from cmd is not working - Giving a message that %%a is unexpected – Rahid May 19 '16 at 08:53
-
How can I run this as a .BAT file ?? I would need to run this a tool which can take the predefined path and do the above – Rahid May 19 '16 at 09:05