Copy files with original folder structure, but to 8.3 format
You can always try using the for
command with the parameter modifiers. If the files have a short filename at all, the following command should work when typed in the Run dialog box or on the command line:
cmd /c for %F /d /r in ("input\*.*") do @xcopy /i "%~F" "temp%~spF%~snF%~xF"
Replace input
with your real folder name, of course. This will put all the short filenames in the temp
, but inside of one or more other folders. Simply keep opening folders until you get to the input
folder, rename it to whatever you want to call it, and move it where you want it. Then delete the temp
folder.
If you don't have any short filenames, you'll have to generate them yourself instead. Using your preferred method, copy all your file from the input folder to the destination. Then copy and paste the following into Notepad:
@echo off
cd "%~1"
for /r /d %%F in (*.*) do call :START "%%~F"
for /r %%F in (*.*) do call :START "%%~F"
pause
GOTO :EOF
:START
setlocal
set path=%~d1%~p1
set name=%~n1
set ext=%~x1
set short=%name: =%
set short=%short:.=%
set short=%short:~0,6%
set short=%short:,=_%
set short=%short:[=_%
set short=%short:]=_%
set short=%short:+=_%
:LOOP
set /a num += 1
if /i %num% GEQ 10 set short=%short:~0,5%&& echo +10
if /i %num% GEQ 100 set short=%short:~0,4%&& echo +100
if /i %num% GEQ 1000 set short=%short:~0,3%&& echo +1000
if exist "%path%%short%~%num%%ext%" GOTO LOOP
move "%~1" "%path%%short%~%num%%ext%"
echo "%path%%short%~%num%%ext%"
Save it as "8dotX.bat" (including the quotes). To run it, drag the copied folder onto it, and all the files and folders in it will be renamed.
Note, this isn't 100% complete, in that filenames that are already short will still be renamed, and the equals sign (=) will not be replaced with _ as it would be in DOS. The former is because handling it correctly would make the batch file take at least twice as long to complete, and the latter is because it can't be done in pure BATCH. It also is limited to only 9999 files with the same beginning letters, and does not bother with changing the filenames to uppercase. I think these limitation will still work with your use case.
ROBOCOPY
will allow you to specify the /FAT
flag for the destination which will use 8.3 file names. I'm not sure how it will act with longer extensions. But it's just a copy so it won't hurt to experiment.
http://ss64.com/nt/robocopy.html