I have a folder with a lot of files and folders inside it.

I would like to copy that to another location so the result is a folder with the same file and folder structure, but with all files in 8.3 format.

How to do it?

PS: Well, some files have extensions with more than 3 characters (e.x. home.sh3d, windows.theme etc.), so when I say about transforming all filenames to 8.3 I would like to say about transforming them to a 8.X format (i.e., to do not change extensions).

  • why? it seems like a really odd thing to need to do, maybe there's a better solution to your original problem?
    – cjb110
    Apr 16, 2014 at 7:35
  • man, there still have in this planet some kind of dilemma... the people continues using very old software and others continues developing software with old issues :( I already tried other ways, but for that particular case the solution are only doing that or changing the software.
    – kokbira
    Apr 16, 2014 at 7:48

2 Answers 2


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"  

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:+=_%

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.

  • Technically, I could replace the = in pure batch, but it would require iterating over every character of the filename, increasing the completion time by a factor of 50 or more.
    – trlkly
    May 2, 2014 at 14:11

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.


  • It does not help :( If you create a folder with files with long names, they still be with long names after processing ROBOCOPY /FAT command...
    – kokbira
    Jul 27, 2012 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .