8 Character Restriction - Mangle /path

  • 13 years ago
    Hey guys,

    I have a small project that needs to pass a /path/to/file parameter to an old DOS based program that I am not allowed to rewrite or bypass that has the old 8 character restriction(example: C:\PROGRA~1 for C:\Program Files).  I was curious if there was any sort of built in feature to do this for me with just passing the results of Dir?

    If need be, I can write logic to look at the amount of characters between each "\" and the amount of similar directories in alphabetical order to determine the number behind the "~".  I was hoping, though, that there was a function I could call that would do this for me so that I don't make a mistake in assuming what the 8 character representation should be.





  • 13 years ago

    Well if I had to solve the problem I wouldn't like to undergo the process of programming a fuction that converts a full path to 8 characters.

    I would suggest a more simpler and faster solution. Write the file that you are passing to the old dos programm to a path that already obeys the 8 characters restriction, e.g. c:\temp\data.txt

    You dont need any conversion then and the old dos program can be started with the same parameter every time.

     

    If this solution does not work for you, you may also have a look at the MSDOS command "Subst". Just use the path you would like to use but use a file name that follows the 8 chars restriction. Use the MSDOS Subst function to create a new drive letter for the full path. To clarify what I mean, just a small example:

    Full path to the file : "c:\averylongdirectoryname\withsomesubfoldersthathavealongnametoo\data.txt"

    subst h: "c:\averylongdirectoryname\withsomesubfoldersthathavealongnametoo"

    h:

    type h:\data.txt |more

     

  • 13 years ago
    Thanks for the response.

    The first method will not work for sure for a few reasons.  Even though this is only one function of the program, there are roughly 50+ people using it at any one time and so the chance of two or more people using the same function at the same time is high.  That would knock out using a root directory on the shared drive for sharing conflicts.  In addition, after the /path is given, many files are manipulated that are rather large, so copying to the local drive first is not practical(in fact I use SQL queries to connect and extract just relevant info).  Lastly, the DOS program exports many files and alters some of the original files, so that would force a writeback function afterwards which is more bandwidth and runs the risk of sharing problems.  I can passively connect to databases if I connect to them directly instead of copying to a local drive and back again.

    The subst function seems interesting, but since this is used by many different machines on a segmented network, I would need a way to select a drive letter and verify it is not used at all(ie. truly not used - not in disconnected status).  Different departments have different map drives and I can't have the program knock off one that a person just hasn't entered a user/pass yet.





  • 13 years ago

    Hi,

    There is a standard function for that in the Windows API: GetShortPathName.

    Check the Microsoft support site at http://support.microsoft.com/kb/175512 for more info.

    Erwin

     

  • 13 years ago

    I dont know if it helps but one more solution came to my mind.

    You need to manually write a small batch file once:

    d: 

    cd averylongpathname\withsomelongsubfoldernames\andanothersubfolder

    dosprog.exe .\data.txt

     

    Right click the batch file and change its compatibility settings to "Windows 95". This way, Windows XP (or whatever OS you are using) should be forced to use the old 8.3 file naming scheme.

  • 13 years ago
    ErwinB wrote:

    Hi,

    There is a standard function for that in the Windows API: GetShortPathName.

    Check the Microsoft support site at http://support.microsoft.com/kb/175512 for more info.

    Erwin

     



    Perfect!  That was what I was hoping to find instead of the quickly contructed mangle path routine I wrote.  Thanks a bunch.

    Zorro_ot:  Thanks for the suggestions.  Actually what you suggest is what I was trying to avoid ;-)  I like to have a program that is self contained and doesn't rely on batch scripts to function.  While sometimes I am forced to use them, I would much rather only release compiled code into a workplace.





Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic