Consulting

Results 1 to 5 of 5

Thread: Solved: How Write Path for DOS Command

  1. #1

    Solved: How Write Path for DOS Command

    I have a .BAT file that I use to clear a Netscape cache that is located at
    C:\NetCache\Cache
    It works. Note that none of the names in the path exceed 8 characters.
    Now I have another similar .BAT file for clearing out the FoxFire cache, except the path has names with more than 8 characters:
    C:\Documents and Settings\Sid Bordelon.SID\Application Data\Mozilla\Firefox\Profiles\a1ao70jc.default\Cache\*.*
    My guesses about how to write the longer-than-8-chars names must be failing, because the .BAT file isn't clearing the cache. My most recent attempt at substitution is:
    C:\Docume~1\Sid Bor~1~SID\Applic~1\Mozilla\Firefox\Profiles\a1ao70jc~default\Cache\*.*
    Can anyone tell me how to change the names into 8-character equivalents?

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Good luck!!
    Somewhat kidding aside, you have the beginning of the right idea, but its a little stranger than that.

    If either portion of the 8.3 filename is longer than 8 or 3 (or they contain a space), you're gonna get a tilda and a number.
    Using your example of the folder name "Sid Bordelon.SID", the "Sid Bordelon" is longer than 8 characters and contains a space. Chances are your short filename is going to be "SidBor~1.SID", as it always keeps the first 3 letters of the extension (even for a folder like this). If you had a folder named C:\Sid.Bordelon\, that would instead be "sid~1.bor"
    It increments the number after the tilda if you have more than one file/folder with the same initial lettering. Easy, huh? There are 10000000 other rules for it too, which is why I try not to use them now!
    2 things you could do, in order of my (and mine only) suggested preference:
    1) Convert the .bat to a .vbs file. .vbs files are a lot better than .bat's, though it might take a bit of time converting them and getting used the exact syntax. worth the trouble, in my opinion
    2) You could use the following function to get them one at a time:[vba]Function ReturnShortName(ByVal LongName As String, Optional ByVal bFolder As Boolean, _
    Optional ByVal bFile As Boolean) As String
    Dim fso As Object, fl As Object
    Set fso = CreateObject("scripting.filesystemobject")
    If bFolder Then
    Set fl = fso.GetFolder(LongName)
    ReturnShortName = fl.ShortPath
    ElseIf bFile Then
    Set fl = fso.GetFile(LongName)
    ReturnShortName = fl.ShortPath & "\" & fl.ShortName
    End If
    Set fso = Nothing
    Set fl = Nothing
    End Function[/vba] Set bFolder = True if it is a folder you're looking for, and bFile = True if it is a filename you want. Just put [vba]Debug.Print ReturnShortName("C:\Documents and Settings\Sid Bordelon.SID\Application Data\Mozilla\Firefox\Profiles\a1ao70jc.default\Cache\", bFolder:=True)[/vba]in a sub, and similar lines as well, to get what you need!
    Matt

  3. #3
    Thanks for poiinting me in the right sirection, Matt. I'll play with it some more.

  4. #4
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    Just put quotes round the filename in the batch file and all will work fine.

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  5. #5
    Hey, Mark, thanx for the great advice. After months of trying I finally got it to work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •