Renaming Windows Files
Renaming Windows Files - Examples below use Zen-Cart files
In our example we will rename some files on Windows. The examples we will use are handy for ZenCart Admin. When renaming files in bulk it is easiest to use some form of batch rename process. When dealing with zen-cart image renaming you often need to do mass additions of _MED and _LRG but the synatx below will work for all of your needs. I find Windows Powershell to be the easiest way to accomplish this. Following are some examples:
To rename a single file using Windows Powershell:
[ this will take a “.php” file and rename it to “.php.original” ]
Windows Powershell Syntax:
Rename-Item tpl_main_page.php tpl_main_page.php.backup
To rename a directory full of files using Windows Powershell:
[ this will use the above example and apply it to an entire directory ]
Windows Powershell Syntax:
Get-ChildItem | ForEach-Object { rename-item $_.name $_.name.replace(”.php”,”.php.original “) }
Therefore To rename a directory of Images to include _MED or _LRG for Zen-Cart use the following:
Windows Powershell Syntax:
Get-ChildItem | ForEach-Object { rename-item $_.name $_.name.replace(”.jpg”,”_MED.jpg”) }
Windows Powershell Syntax:
Get-ChildItem | ForEach-Object { rename-item $_.name $_.name.replace(”.jpg”,”_LRG.jpg”) }
The same example for renaming a directory of Images to include _MED or _LRG for Zen-Cart using Windows Batch would be:
[ this is valid from a cmd line only, to use in a batch file (.bat or .cmd) you will need two % symbols, not one. i.e. %% wherever % is present in the line below ]
Windows Batch Syntax:
for /f %i in (’dir *.jpg /b’) do ren %i %~ni_MED.jpg
Windows Batch Syntax:
for /f %i in (’dir *.jpg /b’) do ren %i %~ni_LRG.jpg
If you would like other examples such as Perl, PHP, or VBScript just ask and I’ll toss them together.
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.



Comments
No comments yet.
Leave a comment