Bat file to rename .js file to another format and back to .js


I faced a lot of issues with my mail exchange server quarantining my js files when i mail it my client. The way out of it was by renaming the .js file to .bak. But as the number of js files increased, it became a tedious process. So I thought of creating a bat file which could do two operations for me:

  1. Convert the .js files to .bak files
  2. Convert the .bak files to .js files

Here is the code you can use for these operations:

Convert .js to .bak (create_jstobak.bat):

@echo on
echo “This will convert all the .bak files to javascript(.js) files
rem Set CURRENTDIR=%CD%
rem ren “%CURRENTDIR%\javascript_files\*.bak” “*.js”
for /f “delims=” %%i in (‘dir /ad/s/b’) do ren “%%i\*.bak” “*.js”
 pause

Convert .bak to .js (create_baktojs.bat):

@echo on
echo “This will convert all the javascript(.js) files to .bak files
rem Set CURRENTDIR=%CD%
rem ren “%CURRENTDIR%\javascript_files\*.js” “*.bak”
for /f “delims=” %%i in (‘dir /ad/s/b’) do ren “%%i\*.js” “*.bak”
 pause

Remember:

  • Correct the path given in the snippet above
  • You can convert it to any other extension like .x or .y or .xyz instead of using bak
  • Save the above text in a notepad file as a “.bat” file.
  • Place the bat file in the appropriate location. Accordingly change the path mentioned in Line no. 4

Hope this helps!!

Feel free to leave a reply here...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s