Batch script: Convert long folder name to short 8.3 name

When running Windows, i often had problems with long folder-names, especially on the command line.
Since Scala also has a problem with a JDK lying in a folder like “Program Files(x86)” i decided to write a little batch-helper to convert long folder names to the short 8.3-form.
Then i put the short name of my JDK folder into my environment variables, voilĂ  – i don’t need to move the JDK to satisfy Scalas needs ;)
The script works like this:

C:\>83conv C:\Program Files (x86)\Java\jdk1.6.0_20
C:\PROGRA~2\Java\JDK16~1.0_2

C:\>

The source:

@echo off
rem # Shorten long Windows pathname to 8.3 pathname
rem # e.g. C:\Program Files (x86)\Java\jdk1.6.0_20\lib --> C:\PROGRA~2\Java\JDK16~1.0_2\lib
if %1!==! goto WRONGPARAM
if NOT exist "%*" goto :NODIR
set filename="%*"
FOR /F "delims=" %%I in ('echo %filename%') do @echo %%~sI
goto :eof

:WRONGPARAM
echo Usage:
echo    83conv [PATH]
echo.

:NODIR
echo 83conv: Not a directory 1>&2
This entry was posted in General and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Sojwita
    Posted 9. May 2010 at 20:39 | Permalink

    Hey, cool script.

    Here is a similar script I use that shortens file names to upto 8 chars but keeping the extension.

    var string list, file, name, ext
    lf -n “*” “.” ($ftype==”f”) > $list
    while ($list “”)
    do
    lex “1″ $list > $file
    stex -p “^/^[" $file > $name
    stex "[^.^l" $name > $ext
    chex "8]” $name > $name
    set $name = $name + $ext
    system rename (“\”"+$file+”\”") (“\”"+$name+”\”")
    done

    This is in bscripting ( http://www.biterscripting.com ). Can do some cool funky stuff with it.

  2. Chandresh Prakash
    Posted 31. August 2011 at 05:52 | Permalink

    This script does not seem to work on my Windows XP Pro. The translation is incorrect:
    C:\SEU\Java\weblogic-10.3.4\wl-10.3.4\wlserver
    translates to
    C:\SEU\Java\WEBLOG~1.4\WL-103~1.4\wlserverrver

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>