Announcement

Collapse
No announcement yet.

Get Sorted Directory Contents with Long File Names?

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

  • Get Sorted Directory Contents with Long File Names?

    Anyone have a routine which will sort & print a directories long file names to a text file?

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

  • #2
    check out http://www.powerbasic.com/support/pb...ad.php?t=23451

    this won't work under a pure dos environment but in windows....


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      There are drivers to provide LFN support to plain DOS, if you should
      need such a thing.

      ------------------
      Tom Hanlin, PowerBASIC Staff
      Opinions expressed may not be those of my employer or myself

      Comment


      • #4
        > By Tom H.
        > There are drivers...

        Where? Didn't know they existed.


        ------------------
        There are no atheists in a fox hole or the morning of a math test.
        If my flag offends you, I'll help you pack.

        Comment


        • #5
          Do a web search for DOSLFN and/or LFNDOS. You can also find drivers
          that will let the LFN support work under versions of NT that don't
          automatically provide DOS-level LFN support.

          Also see PBLFN322.zip and PBLFNupd.zip :

          http://www.powerbasic.com/files/pub/pbdos/library/

          ------------------
          Tom Hanlin, PowerBASIC Staff
          Opinions expressed may not be those of my employer or myself

          Comment


          • #6
            'Can anyone get this to work with long file names?

            'this routine will sort & print directory contents to a file
            'with the directory's name * .dir i.e. Windows.dir

            dim R$(3000) 'Dimension Max number of possible file name entries.
            option base 1 'Set array base offset to one instead default of zero.
            A$=COMMAND$
            gtfile:
            IF A$<>"" THEN GOTO GOTA
            A$=CURDIR$
            ' INPUT "FULL PATH TO DIRECTORY";a$
            ' INPUT PATH REPLACED BY COMMAND LINE ENTRY i.e. DIRECT C: does C: directory
            A$=RTRIM$(A$):A$=LTRIM$(A$)
            ' if a$="" then goto gtfile 'loop now obsolete
            GOTA:
            a$=ucase$(a$):A$=RTRIM$(A$):A$=LTRIM$(A$)
            L=LEN(A$)
            IF MID$(A$,L,1)<>"\" THEN A$=A$+"\"
            PRINT
            PRINT "READING ";A$
            c=1 'Initialize counter to one.
            f$=dir$(a$,16) 'Make first call to dir$ with correct file attributes
            R$(C)=f$ 'Put results of first call into in the Array.
            C=C+1
            do while f$<> "" 'Loop until no more matches

            f$=dir$ 'Get the next entry and print it.

            R$(C)=f$ 'Store it in the array

            C=C+1 'Increment the array pointer
            wend
            ' REM SET FILE NAMES
            A$=LTRIM$(A$):A$=RTRIM$(A$):L=LEN(A$):L=L-1
            for a=1 to L
            if mid$(a$,A,1)="\" then P=A
            next a
            NM$=mid$(a$,P+1,L-P):NM$=LTRIM$(NM$):NM$=RTRIM$(NM$):NM$=NM$+"."
            l=len(A$)
            if l=3 then nm$=mid$(a$,1,1)+"."
            ' REM SPLIT DIRECTORIES AND FILES FOR SORT
            FOR A=1 TO C
            L=LEN(R$(A))
            IF L=0 THEN GOTO NADA
            FOR Z=1 TO L
            IF MID$(R$(A),Z,1)="." THEN GOTO NOTHIS
            NEXT Z
            L=LEN(R$(A))
            TP$=" "
            R$(A)="!"+R$(A)+MID$(TP$,1,15-L)+"<DIR>
            NOTHIS:
            NADA:
            NEXT A
            ' REM SORT FILE
            n=1
            print"SORTING ";A$
            'rem shell sorter routine
            x=c:m=x-1
            itsm:
            m=int(m/2):if m<=0 then goto itsover
            k=x-m:j=1
            itsi:
            i=j
            itsl:
            l=i+m:if R$(i)<=R$(l) then goto itsj
            c$=R$(i):R$(i)=R$(l):R$(l)=c$:i=i-m:if i>=1 then goto itsl
            itsj:
            j=j+1:if j>k then goto itsm
            goto itsi
            itsover:
            ' REM SAVE TO DIR FILE
            CK$=UCASE$(A$)
            PT$=NM$+"DIR":PT$=LTRIM$(PT$):PT$=RTRIM$(PT$)
            OPEN PT$ FOR APPEND AS #1
            IF R$(1)="" THEN R$(1)=A$
            PRINT"WRITING ";NM$;"DIR"
            for y=1 to C
            CK$=R$(y):L=LEN(CK$)
            IF Y=1 THEN GOTO ITSDIR
            IF CK$="" THEN GOTO NOPE
            IF MID$(CK$,1,1)<>"!" THEN GOTO ITSFILE
            CK$=CK$+" "
            CK$=MID$(CK$,1,13)+"<DIR>
            IF CK$="" THEN GOTO NOPE
            ITSFILE:
            ' REM ADD SPACES
            L=LEN(CK$):IF MID$(CK$,1,1)="!" THEN CK$=MID$(CK$,2,L-1):GOTO ITSDIR
            'FOR A=1 TO L
            'IF MID$(CK$,A,1)="." THEN GOTO ADDSPACE
            'NEXT A
            'ADDSPACE:
            'FS$=MID$(CK$,1,A-1):ES$=MID$(CK$,A,L-(A-1))
            'FS$=FS$+" ":FS$=MID$(FS$,1,8):CK$=FS$+ES$
            ITSDIR:
            IF CK$="" THEN GOTO NOPE
            PRINT #1, CK$
            nope:
            next y
            CLOSE #1
            PRINT
            PRINT"Today, ";nm$;"DIR";", Tomorrow, THE WORLD!!!"
            STOP



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

            Comment


            • #7
              Okay, as I understand it, you want to get all the long file
              names in a directory, sort it and write the sorted data to a
              disk file. You might try this. I'm typing off the cuff so there
              may be some typos...This code is not tested so use accordingly.

              Code:
                      dim r$(3000)
                      path$ = "c:\windows\"    'or whatever
                      mask$ = "*.*"
              
                      sfn$ = dir$(path$ + mask$)
                      do until sfn$ = ""
                      lfn$ = longfilename$(sfn$)  'You may need to add the path
                      incr i                      'don't know.
                      r$(i) = lfn$                'add the path if needed
                      sfn$ = dir$
                      loop
                      
                      array sort r$(1) for i
                      
                      open "somefile.txt" for binary as #1
                      for x = 1 to i
                      put$ #1,f$(x) + crlf$
                      next x
                      close #1
                      end
              
              function longfilename$(sfn$)
              	sfn$ = remove$(sfn$,chr$(0))
              	sfn$ = sfn$ + chr$(0)
              
              	lfn$ = string$(260,chr$(255))
              
              	reg 1, &h7160
              	reg 3, 2
              	reg 5, strptr(sfn$)
              	reg 8, strseg(sfn$)
              	reg 6, strptr(lfn$)
              	reg 9, strseg(lfn$)
              	call interrupt &h21
              
              	lfn$ = remove$(lfn$,chr$(255))
              	function = lfn$
              	end function
              Anyway, that's how I would do it.


              ------------------
              There are no atheists in a fox hole or the morning of a math test.
              If my flag offends you, I'll help you pack.

              Comment


              • #8
                DIR /B > Filename.txt


                /O gives you sort options

                ------------------
                If you aim at nothing...you will hit it.

                If something I say can be taken 2 ways and 1 of them ticks you off...I meant the other one.

                [This message has been edited by Roger Garstang (edited October 26, 2004).]
                sigpic
                Mobile Solutions
                Sys Analyst and Development

                Comment


                • #9
                  How simple is that? Would you happen to have a listing of all the
                  msdos command line syntax. Have been working in dos since the early
                  80's and this is something I've never seen or heard before. Go figure. Anybody got a listing?

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

                  Comment


                  • #10
                    Code:
                    C:\ dir /?
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      go to a DOS prompt and type help. If you have the DOS help system on your computer, it will give you a listing of the available DOS commands. If you type help dir then it would give you a list of syntax for dir options.
                      regards,

                      ------------------
                      ian[dot][email protected]
                      :) IRC :)

                      Comment


                      • #12

                        On 25 Oct 04, Lee Scott wrote:

                        Hello Lee,

                        > Anyone have a routine which will sort & print a directories long file
                        > names to a text file?

                        ftp://ftp.pbhq.de/pbsource.ger/dir95.bas

                        Read the files in an array, use PowerBASICs ARRAY SORT and write the
                        result to a file.

                        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)
                        fax/bbs: +49-30-47300910 (VFC, V34+, X75, ISDN, CCB, 9600-128000bps)
                        ## CrossPoint/Agent R/C2478, via PBNEWS v0.40g (news.pbhq.de)
                        http://www.gohel.de - http://www.gohel.net - http://www.pbhq.com

                        Comment


                        • #13
                          Pocket PC REF...best book ever made.

                          ISBN 1-885071-16-7

                          I have the eight edition. They may have made more, but I doubt it
                          since most PCs don't need the HDD spec, pin-outs and Windoze hides
                          DOS.

                          It even lists the undocumented switches for commands...which most
                          of them you can probably search for on the web now, but nice to have
                          them all handy with a complete history of DOS and its files sizes.

                          It also shows what switches work with the different versions of DOS, etc.

                          =======
                          Looked it up and they have a 12th Edition now. If you buy it, let me know what
                          new stuff they added.

                          ------------------
                          If you aim at nothing...you will hit it.

                          If something I say can be taken 2 ways and 1 of them ticks you off...I meant the other one.

                          [This message has been edited by Roger Garstang (edited October 26, 2004).]
                          sigpic
                          Mobile Solutions
                          Sys Analyst and Development

                          Comment


                          • #14
                            There's a 13th Edition of the Pocket PCRef available now...
                            http://www.bluewillow.com/pdt_pocketpcref.htm

                            I just ordered it. Thanks Roger, for pointing out that updated editions are available! My old seventh edition was getting rickety...



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

                            Comment


                            • #15
                              Amazon has it $1 cheaper, plus $.50 cheaper postage.

                              ------------------
                              If you aim at nothing...you will hit it.

                              If something I say can be taken 2 ways and 1 of them ticks you off...I meant the other one.
                              sigpic
                              Mobile Solutions
                              Sys Analyst and Development

                              Comment

                              Working...
                              X