Announcement

Collapse
No announcement yet.

SFN vs. LFN ??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SFN vs. LFN ??

    As a test, I did a reading of my C drive from Powerbasic, which yielded filenames such as:
    Kentuc~1,txt
    Indian~1.txt
    Indian~2.txt

    and so on. I have a routine which will look for those names and return the long file name.

    A problem surfaced today. What if the name "Robert~1.txt" is actually the full name? Because of the "~" character, my routine keeps attempting to obtain the long file name of this. Does anyone know how to obtain a file name and also along with it a indicator of some sort to show if it is the Full name or short name? That way, if it is the short name, I can obtain the full name, if it is already the full name, go to the next name?

    It hangs here, I have set to keep trying until it gets the long file name. Any suggestions? Would it work to just try to get the LFN only once, and if that fails, assume the "~" is part of the name and that it is the complete name?

    Thank you.

    Robert



    [This message has been edited by Robert E. Carneal (edited February 18, 2005).]

  • #2
    Why not get the short filename, get the long filename, and compare them?

    I don't know which routine you're using to get long file names, but there must be a way to insert a check for an empty string somewhere in there if there is no lfn found.

    ------------------

    Comment


    • #3
      This might work for you (needs Windows or in pure DOS an API
      like DOSLFN.) The function returns the long pathname, if one
      exists, or else the short pathname is returned.

      FUNCTION getlongname (BYVAL shortpathname AS STRING) PUBLIC AS STRING

      dim longname AS STRING * 1024
      shortpathname = shortpathname + chr$(0)
      longptr??? = VARPTR32(longname)
      shortptr??? = STRPTR32(shortpathname)

      FUNCTION = ""

      ! push ds
      ! lds si, shortptr???
      ! les di, longptr???
      ! mov cx, 2
      ! mov ax, &H7160
      ! int &H21
      ! pop ds
      ! jnc exitsuccess

      EXIT FUNCTION

      exitsuccess:

      FUNCTION = REMOVE$(longname, CHR$(0))

      END FUNCTION

      ------------------
      Bob Green
      FileRecovery.Biz

      [This message has been edited by Bob Green (edited February 18, 2005).]
      Bob Green
      FileRecovery.Biz

      Comment


      • #4

        On 18 Feb 05, Robert E. Carneal wrote:

        Hello Robert,

        > A problem surfaced today. What if the name "_Robert~1.txt_" is
        > actually the full name? Because of the "~" character, my routine
        > keeps attempting to obtain the long file name of this. Does anyone
        > know how to obtain a file name and also along with it a indicator of
        > some sort to show if it is the Full name or short name? That way, if
        > it is the short name, I can obtain the full name, if it is already
        > the full name, go to the next name?

        Very old stuff, but it works ...

        Code:
        '************************************************************************
        '
        '  NAME95.BAS  Konvertierung von Dateinamen von/nach DOS8.3 <-> LFN
        '              Konvention mit PowerBASIC 3.2
        '
        '  entwickelt von Thomas Gohel  FidoNet :  Thomas [email protected]:2410/330.1
        '  Version: 1.00                InterNet:   mailto:[email protected][email protected]</A> 
        '  Stand  : 16.11.1996          Homepage:  http://www.pbhq.de/ 
        '
        '*************************************************************************
        
        DECLARE FUNCTION GetStrLoc (BYVAL INTEGER) AS INTEGER
        
        CLS
        PRINT "Erzeuge LFN-Files  : "; Win95Open$("C:\Testfile1.Test")
        PRINT "Erzeuge LFN-Files  : "; Win95Open$("C:\Testfile2.Test")
        PRINT "Erzeuge LFN-Files  : "; Win95Open$("C:\Testfile3.Test")
        PRINT "---------------------------------------------"
        PRINT "Ermittele LFN alias: "; Win95Pfad$("C:\TESTFI~1.TES")
        PRINT "Ermittele LFN alias: "; Win95Pfad$("C:\TESTFI~2.TES")
        PRINT "Ermittele LFN alias: "; Win95Pfad$("C:\TESTFI~3.TES")
        PRINT "---------------------------------------------"
        PRINT "Ermittele DOS alias: "; Dos83Pfad$("C:\Testfile1.Test")
        PRINT "Ermittele DOS alias: "; Dos83Pfad$("C:\Testfile2.Test")
        PRINT "Ermittele DOS alias: "; Dos83Pfad$("C:\Testfile3.Test")
        
        FUNCTION Dos83Pfad$(BYVAL DirLFN$) public
                DIM LFNBuffer AS STRING * 128
                DirLFN$ = DirLFN$ + CHR$(0)
        
                ! push ds
                ! lea  di, LFNBuffer$
                ! push ds                         ; ES I auf Stack, erspart außer-
                ! push di                         ; das leidige Umkopieren
        
                ! les  di, DirLFN$                ; Handle von DirLFN$ holen
                ! push di                         ; auf Stack
                ! call GetStrLoc                  ; Adresse holen
                ! mov  ds, dx                     ; Quelle auf DS:SI umkopieren
                ! mov  si, ax                     ;
        
                ! pop  di                         ; ES I umkopiert vom Stack holen
                ! pop  es                         ;
        
                ! mov  ax, &h7160                 ; Make DOS 8.3 Names
                ! mov  ch, 0
                ! mov  cl, 1
                ! int  &h21
                ! pop  ds
                i% = INSTR(1, LFNBuffer$, CHR$(0))
                Dos83Pfad$ = LEFT$(LFNBuffer$, i%-1)
        END FUNCTION
        
        FUNCTION Win95Pfad$(BYVAL DirLFN$) public
                DIM LFNBuffer AS STRING * 128
                DirLFN$ = DirLFN$ + CHR$(0)
        
                ! push ds
                ! lea  di, LFNBuffer$
                ! push ds                         ; ES I auf Stack, erspart außer-
                ! push di                         ; das leidige Umkopieren
        
                ! les  di, DirLFN$                ; Handle von DirLFN$ holen
                ! push di                         ; auf Stack
                ! call GetStrLoc                  ; Adresse holen
                ! mov  ds, dx                     ; Quelle auf DS:SI umkopieren
                ! mov  si, ax                     ;
        
                ! pop  di                         ; ES I umkopiert vom Stack holen
                ! pop  es                         ;
        
                ! mov  ax, &h7160                 ; Make Win95 Names
                ! mov  ch, 0
                ! mov  cl, 2
                ! int  &h21
                ! pop  ds
                i% = INSTR(1, LFNBuffer$, CHR$(0))
                Win95Pfad$ = LEFT$(LFNBuffer$, i%-1)
        END FUNCTION
        
        FUNCTION Win95Open$(BYVAL Filename$)
                Filename$ = Filename$ + CHR$(0)
                ! push ds
                ! les  di, Filename$              ; Handle von Filename$ holen
                ! push di                         ; auf Stack
                ! call GetStrLoc                  ; Adresse holen
                ! mov  ds, dx                     ; Quelle auf DS:SI umkopieren
                ! mov  si, ax                     ;
                ! mov  ax, &h716C
                ! mov  bx, &h0002
                ! mov  cx, &h0000
                ! mov  dx, &h0012
                ! mov  di, 1
                ! int  &h21
                ! pop  ds
                ! mov  bx, ax                      ; und File wieder schliessen
                ! mov  ah, &h3E
                ! int  &h21
                Win95Open$ = Dos83Pfad$(Filename$)
        END FUNCTION
        If you need some other LFN stuff, too:
        http://www.pbhq.de/cgi-bin/pbsearch.exe?description=lfn
        http://www.pbhq.de/cgi-bin/pbsearch....cription=DIR95

        Regards,

        --------------
        / h o m a s
        ------------------
        email : [email protected] / mailto:[email protected][email protected]</A> (PGP-Key available)
        www : http://www.gohel.de / http://www.pbhq.de (PowerBASIC)
        chat : irc://irc.pbhq.de/#pbhq.cafe (Online-Chat for PB users only!)
        bbs : telnet://bbs.pbhq.de (historical access to the PBSOUND HQ BBS)
        ## CrossPoint/Agent R/C2478, via PBNEWS v0.56g (news.pbhq.de)
        http://www.gohel.de - http://www.gohel.net - http://www.pbhq.com

        Comment


        • #5
          >What if the name "Robert~1.txt" is actually the full name

          The PB/DLL version 6.0 IDE did that.. load a file, even if it had a long name )the short name appeared in the OPEN dialog), when you saved it, it got saved as the short name.

          <U>Very</U> confusing for me until I figured out what was going on....

          (Updated in PB/DLL 6.10 which added 'real' long file name support)
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Sorry, Michael, I rewrote that several times trying to make it clearer. I guess I should have said what if the file name uses the "~" character as part of the name, and it doesn't mean the name is longer? How do I determine that?

            Robert

            [This message has been edited by Robert E. Carneal (edited February 18, 2005).]

            Comment


            • #7
              My comment was totally, absolutely gratuitous and has nothing to do with your problem.. it just demonstrates "how" once could get a 'real' file name which only looks like the short file name version of a long file name.

              But on your problem.. I would assume that your "get the long name" function which uses int &h71 could be modified to return an error code...I'm not an assembly-language type, but it seems to me...
              Code:
               jnc exitsuccess
              .. implies the function only succeeded in obtaining a long name if the carry flag is clear, and it failed if the carry flag is set.

              Maybe you should check the carry flag carefully. If the function succeeds and the 'long name' comes back with a tilde in it, then the 'real' name of the file really does contain a tilde.

              But you should get an opinion from someone with an MS-DOS INT 0x71 reference guide.

              MCM
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                I wish I could buy a "MS-DOS INT 0x71 reference guide." I think the error problem is me, the programmer.

                I have it set to check a file name and if the tilde is inside the name, it auto-assumes it is a SFN and needs to get the LFN. When it gets the "LFN", it is checked again. If it still has the Tilde, do it again until it successfuly gets a name without the Tilde.

                When I don't program it that way, I seem to miss a lot of LFN filenames. So I am trying a few ideas, maybe I will hit one that will tell me the file name with a Tilde is indeed the LFN.

                Thanks, guys.

                Robert

                ------------------

                Comment


                • #9
                  > have it set to check a file name and if the tilde is inside the name, it auto-assumes it is a SFN and needs to get the LFN.

                  So why not just check 'em all?

                  Don't check the file name for speed purposes: by the time you get doing screwing around checking lengths and for the presence of exactly one tilde exactly two characters short of the 'dot' with a numeric digit one character before the dot, the filename could have been "LFN'd" already.


                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Michael-

                    That's probably what I will do. This is the first time I have had to write an application AND be backward compatiable to at least DOS in Windows 98Fe.

                    For the first time since I have gotten Powerbasic, I find myself wishing for an "All-Windows emulator" that will simulate earch version of Windows so I wouldn't have to find someone who has W98Fe, Win98Se, WinME, etc.

                    Thank you.

                    Robert

                    ------------------

                    Comment


                    • #11
                      > I wish I could buy a "MS-DOS INT 0x71 reference guide."
                      http://www-2.cs.cmu.edu/afs/cs/user/...WWW/files.html

                      Merry Christmas.

                      ------------------

                      Comment


                      • #12
                        Merry Christmas.
                        Thank you.

                        Robert

                        ------------------

                        Comment

                        Working...
                        X