| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 119126 | 2011-07-06 04:54:00 | Batch renaming files to DOS-compatible 8-char length | Chilling_Silence (9) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1215144 | 2011-07-06 04:54:00 | Hi all, I'm having no end of issues trying to get this to work. So, I have a .zip file which I'm extracting at scheduled times (It gets updated via another script and dumped to this machine). I'm getting all the files outta it, but the problem is they're long filenames (Such as "reallyLongFile.txt"). I wanna have them renamed to something like "really01.txt", but I can't work out how to do this? There's about 5 to 10 files extracted from the .zip file each time, so I really need it to do all the files in a specific directory... Any ideas? Many thanks Chill. |
Chilling_Silence (9) | ||
| 1215145 | 2011-07-06 05:19:00 | Any reason you can't just use a bash script for this? :pf1mobmini: |
Erayd (23) | ||
| 1215146 | 2011-07-06 05:22:00 | Coz it's all done in a 100% windows environment unfortunately ;) | Chilling_Silence (9) | ||
| 1215147 | 2011-07-06 05:32:00 | Powershell! | inphinity (7274) | ||
| 1215148 | 2011-07-06 06:27:00 | This? www.snapfiles.com |
pctek (84) | ||
| 1215149 | 2011-07-06 07:05:00 | Does that ReNamer do things via batch script / command line? It just launched the GUI for me when I tried to fire it with -h or /? How would you accomplish this with Powershell? |
Chilling_Silence (9) | ||
| 1215150 | 2011-07-06 07:28:00 | What about applying the name change at the source machine, before they get zipped. Copy the files to an empty directory (to reduce the chance of filename collisions), then use whatever DOS command to rename to the 8.3 equivalent which may already be part of the Windows filesystem. As another thought... wasn't there a switch in PKZIP to store the 8.3 equivalent? If so, you could modify the switches when calling PKZIP / PKUNZIP to get the desired result? |
Paul.Cov (425) | ||
| 1215151 | 2011-07-06 08:47:00 | setlocal enabledelayedexpansion set counter=1 for %%A in (*.txt) do set fname=%%A && move %%A %fname:~0,5%-0!counter!.txt && set /a counter+=1 numbering will get a bit weird if more than 9 files but there isn't really an elegant way to deal with zero-padding. |
fred_fish (15241) | ||
| 1215152 | 2011-07-06 09:16:00 | improvement to deal with padding :) this will do you up to 99 setlocal enabledelayedexpansion set counter=0 set padding=0 for %%A in (*.txt) do ( set fname=%%A set /a counter+=1 if !counter! gtr 9 set padding= move %%A %fname:~0,5%-!padding!!counter!.txt ) |
fred_fish (15241) | ||
| 1215153 | 2011-07-06 11:06:00 | Awesome, I'll give that a whirl tomorrow, thanks so much! :) | Chilling_Silence (9) | ||
| 1 2 | |||||