Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to convert short paths to long paths?  (Read 499753 times)

0 Members and 1 Guest are viewing this topic.

nubia

    Topic Starter


    Rookie

    How to convert short paths to long paths?
    « on: February 05, 2009, 09:01:19 PM »
    Does anyone know of a way to convert short paths to long paths?
    if I issue the dos command
    Code: [Select]
    ftype FirefoxHTMLMy output is:
    Code: [Select]
    FirefoxHTML=C:\PROGRA~1\MOZILL~1\FIREFOX.EXE -requestPending -osint -url "%1" ???

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: How to convert short paths to long paths?
    « Reply #1 on: February 05, 2009, 09:14:28 PM »
    But why? The short path is valid.

    nubia

      Topic Starter


      Rookie

      Re: How to convert short paths to long paths?
      « Reply #2 on: February 05, 2009, 09:34:59 PM »
      I really need the long path for a java program I'm working on.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: How to convert short paths to long paths?
      « Reply #3 on: February 05, 2009, 11:33:03 PM »
      There is a function in Windows for that. But if you tack it into java you will have code that can not port across platforms. Which is one reason for musing java.

      Maybe the quick fix is to shell out to DOS and use a VB script to convert the files names. There is a function in VB script for this. I think.

      Dias de verano

      • Guest
      Re: How to convert short paths to long paths?
      « Reply #4 on: February 06, 2009, 12:46:02 PM »
      There is a function in Windows for that. But if you tack it into java you will have code that can not port across platforms. Which is one reason for musing java.

      Maybe the quick fix is to shell out to DOS and use a VB script to convert the files names. There is a function in VB script for this. I think.

      Code: [Select]
      @echo off
      @echo set oArgs = Wscript.Arguments>"%TEMP%\LongFileName.vbs"
      @echo wscript.echo LongName(oArgs(0))>>"%TEMP%\LongFileName.vbs"
      @echo Function LongName(strFName)>>"%TEMP%\LongFileName.vbs"
      @echo Const ScFSO = "Scripting.FileSystemObject">>"%TEMP%\LongFileName.vbs"
      @echo Const WScSh = "WScript.Shell">>"%TEMP%\LongFileName.vbs"
      @echo.   With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")>>"%TEMP%\LongFileName.vbs"
      @echo.     .TargetPath = CreateObject(ScFSO).GetFile(strFName)>>"%TEMP%\LongFileName.vbs"
      @echo.     LongName = .TargetPath>>"%TEMP%\LongFileName.vbs"
      @echo.   End With>>"%TEMP%\LongFileName.vbs"
      @echo End Function>>"%TEMP%\LongFileName.vbs"

      set sfn=C:\PROGRA~1\MOZILL~2\firefox.exe

      for /f "Tokens=*" %%a in ( ' cscript //nologo "%TEMP%\LongFileName.vbs" %sfn% ' ) do set lfn=%%a

      echo %lfn%


      nubia

        Topic Starter


        Rookie

        Re: How to convert short paths to long paths?
        « Reply #5 on: February 06, 2009, 07:52:02 PM »
        WOW! :o
        This looks really hopeful.
        I wish I understood it or how to use it.
        I copied it and put it into a batch file and ran it but it flashed by so fast I could not see any output.
        Remember I am a new B.
        N.

        nubia

          Topic Starter


          Rookie

          Re: How to convert short paths to long paths?
          « Reply #6 on: February 06, 2009, 08:41:16 PM »
          OK I looked into my \Local Settings\Temp folder and found LongFileName.vbs.
          Which looks like this:
          Code: [Select]
          set oArgs = Wscript.Arguments
          wscript.echo LongName(oArgs(0))
          Function LongName(strFName)
          Const ScFSO = "Scripting.FileSystemObject"
          Const WScSh = "WScript.Shell"
             With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")
               .TargetPath = CreateObject(ScFSO).GetFile(strFName)
               LongName = .TargetPath
             End With
          End Function
          Then I copied and pasted into a HTML file like this:
           
          Code: [Select]
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
          <head>
          <title>shortToLong</title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>

          <body>
          <script language="VBScript" type="text/vbscript">
          set oArgs = Wscript.Arguments
          wscript.echo LongName(oArgs(0))
          Function LongName(strFName)
          Const ScFSO = "Scripting.FileSystemObject"
          Const WScSh = "WScript.Shell"
             With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")
               .TargetPath = CreateObject(ScFSO).GetFile(strFName)
               LongName = .TargetPath
             End With
          End Function
          </script>
          </body>
          </html>
          When I try to view in a browser I get an error (No Surprise since I don't really know what I'm doing)
          I've attached a screen shot of my error.
          Thanks for your help.


          [attachment deleted by admin]

          nubia

            Topic Starter


            Rookie

            Re: How to convert short paths to long paths?
            « Reply #7 on: February 06, 2009, 10:21:36 PM »
            Well I figured it out. It works!! I'm so happy.
            Thank You Dias de verano!
            In the command line I type:
            Code: [Select]
            cscript LongFileName.vbs "C:/PROGRA~1/MOZILL~1\firefox.exe>vb.txtAnd sure enough the vb.txt file is written with
            Code: [Select]
            Microsoft (R) Windows Script Host Version 5.6
            Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

            C:\Program Files\Mozilla Firefox\firefox.exe
            If there was some way to suppress the writing of the first two lines that would be nice but not necessary.
            Again Thank You!
             :)


            Dias de verano

            • Guest
            Re: How to convert short paths to long paths?
            « Reply #8 on: February 07, 2009, 12:52:07 AM »
            If there was some way to suppress the writing of the first two lines that would be nice but not necessary.

            Incidentally, you don't need that single quote mark before the short filename.

            To run a VBscript with cscript.exe, without those 2 lines, you can add the //Nologo switch after the cscript command thus:

            cscript //Nologo LongFileName.vbs C:/PROGRA~1/MOZILL~1\firefox.exe>vb.txt

            Alternatively, you can beforehand get cscript.exe to save the //Nologo option by doing this:

            cscript //Nologo //S

            Afterwards, when you run any script with cscript.exe, on the same computer system, the //Nologo option is default and need not be included in the command. However this has the disadvantage that if the command is used on another system the option may or may not have been thus saved, and therefore the output of the script is unpredictable. So you should always include the //Nologo switch when supplying the script and command to other people (or explain all of the above, whichever seems appropriate!)

            To restore the default behaviour to cscript.exe:

            cscript //Logo //S

            Use either switch to force the desired behaviour when running a script.

            Although I have used capital letters N and L in the switches, they are not case sensitive.

            type cscript /? at the prompt to see full details of options.

            Code: [Select]
            C:\>cscript //nologo //S
            Command line options are saved.

            C:\>cscript //logo //S
            Microsoft (R) Windows Script Host Version 5.7
            Copyright (C) Microsoft Corporation. All rights reserved.

            Command line options are saved.

            C:\>cscript //nologo //S
            Command line options are saved.
            « Last Edit: February 07, 2009, 04:22:16 AM by Dias de verano »

            nubia

              Topic Starter


              Rookie

              Re: How to convert short paths to long paths?
              « Reply #9 on: February 09, 2009, 06:20:53 PM »
              Again Thank You -You have been more than helpful.
              I really appreciate the time and effort you have taken to help me.
              Nubia.