|
Answer» Hi folks,
I'm just a beginner here with MS-Dos, but recently I've learned some neat WAYS of doing things through CMD that have saved me quite some time. ONE example is a large file file rename. My job requires me to rename image files for products according to theire UPC. By using a the ren or rename function and some vlookup in excel I am able to rename a bunch of files by simply doing a directory dump and COPYING that into excel. I then match those file names (who usually have model numbers) up to the corresponding UPCs. I then RUN a copy and paste formula in excel that read something like this ="ren "&A39&" "&c39&".jpg" and copy that formula into all my cells. Now I have text in each cell that reads something like this ren W0102 COFFRET ACCESSOIRES.jpg 746775023492.jpg I then proceed to copy all my the column with all the rename formulas in text and paste it in CMD and voila, all my file are renamed. Now for my question, can I do something similar to what I have just described to take the spaces out of my file names? This would be helpful as when my original file has space I have to go through and take them out as if they were there my rename formula would not work. My files would be located in C:\Users\Eddie\Desktop\Images So is there anyway I can go into a directory and take the spaces out of each file name with a DOS script or COMMAND? Thank you for reading through that meaty bit of writing!Run the script and if you are happy with how it works remove 'echo' from the start of the 7th line.
Code: [Select]@echo off setlocal enabledelayedexpansion cd /d "C:\Users\Eddie\Desktop\Images" for /f "delims=" %%A in ('dir /b *.jpg') do ( set oldfilename=%%A set newfilename=!oldfilename: =! echo ren "!oldfilename!" "!newfilename!" ) echo. echo all done pause
|