Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

directory console programs

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

  • directory console programs

    code was posted under another forum subject just decided to put it here.
    the code for both programs was modified a little to make the outcome easier to sort, if the output is redirected to a file.
    credit goes to Pierre Bellisle and Michael Mattias for helping me.
    these programs will find a hidden subdirectory then display its contents, you must specify the hidden directory specifically to get a listing.
    working on that hidden directory listing stuff.



    program 1
    Code:
    'compiled with pbcc 4.03
    
    #COMPILE EXE
    '#DIM ALL
    #INCLUDE "WIN32API.INC"
    FUNCTION PBMAIN () AS LONG
    
    MAINDIR$=CURDIR$
    DIRLIST$=TRIM$(COMMAND$)
    IF LEN(DIRLIST$)=0 THEN DIRLIST$=MAINDIR$
    
    TRY
    CHDIR DIRLIST$
    CATCH
    junk$=CURDIR$(MAINDIR$)
    STDOUT "            directory = "+DIRLIST$
    STDOUT "            timestamp = "+DATE$+" "+TIME$
    
    STDOUT "            ------no directory was found---------------"
    STDOUT "            ------end of directory listing-------------"
    
    EXIT TRY
    
    FINALLY
    STDOUT "            directory = "+CURDIR$
    STDOUT "            timestamp = "+DATE$+" "+TIME$
    STDOUT "            ------files inside directory---------------"
    
    FILES&=0
    SUBDIRECTORIES&=1
    
    A$ = DIR$("*.*", (0 OR 1 OR 2 OR 3 OR 4 OR 32))
    WHILE LEN(A$)
    FILES&=1
    STDOUT A$
    A$ = DIR$
    WEND
    IF FILES&=0 THEN STDOUT "            ------no files found-----------------------"
    STDOUT "            ------subdirectories inside directory------"
    
    
    A$ = DIR$("*.*",16)
    WHILE LEN(A$)
    IF (GETATTR(A$) AND 16) THEN SUBDIRECTORIES&=1:STDOUT "<DIR> "+A$
    
    A$ = DIR$
    WEND
    IF SUBDIRECTORIES&=0 THEN STDOUT "            ------no subdirectories found--------------"
    STDOUT "            ------end of directory listing-------------"
    EXIT TRY
    
    
    END TRY
    
    
    END FUNCTION
    Last edited by Paul Purvis; 19 Sep 2007, 03:17 AM.
    p purvis

  • #2
    directory program 2

    directory program number 2

    Code:
    'compiled with pbcc 4.03
    
    
    #COMPILE EXE
    #REGISTER NONE
    '#Dim All
    
    '------------------------------------------------------------------------------
    ' Include files
    '------------------------------------------------------------------------------
    
    #INCLUDE "Win32API.inc"
    
    '------------------------------------------------------------------------------
    ' Global variables
    '------------------------------------------------------------------------------
    GLOBAL gStartPath  AS STRING  ' path to start search from
    GLOBAL sWhichfiles AS STRING
    GLOBAL iFilecount AS LONG
    
    
    '------------------------------------------------------------------------------
    ' Return properly formatted file date + time as string
    '------------------------------------------------------------------------------
    FUNCTION GetFileDateTime(dt AS FILETIME) AS STRING
      LOCAL lpsystime AS SYSTEMTIME
      LOCAL szDate    AS ASCIIZ * 64 ' date buffer, %LDT_SIZE = 64 bytes
      LOCAL szTime    AS ASCIIZ * 64 ' time buffer, %LDT_SIZE = 64 bytes
    
      ' convert given date to correct format
      FileTimeToLocalFileTime dt, dt
      FileTimeToSystemTime dt, lpsystime
    
      GetDateFormat %LOCALE_USER_DEFAULT, %DATE_SHORTDATE, BYVAL VARPTR(lpsystime), BYVAL %NULL, szDate, SIZEOF(szDate)
      GetTimeFormat %LOCALE_USER_DEFAULT, %TIME_FORCE24HOURFORMAT OR %TIME_NOSECONDS, BYVAL VARPTR(lpsystime), _
            BYVAL %NULL, szTime, SIZEOF(szTime)
      szDate=TRIM$(szDate)
      szTime=TRIM$(szTime)
      IF MID$(szDate,2,1)="/" THEN szDate="0"+szDate
      IF MID$(szDate,5,1)="/" THEN szDate=MID$(szDate,1,3)+"0"+MID$(szdate,4,6)
      IF MID$(szTime,2,1)=":" THEN szTime="0"+szTime
      IF RIGHT$(szTime,2)="PM" THEN szTime=LEFT$(szTime,5)+"p" ELSE szTime=LEFT$(szTime,5)+"a"
      FUNCTION = MID$(szDate,7,4)+"-"+MID$(szdate,1,2)+"-"+MID$(szdate,4,2) + "  " + szTime
    END FUNCTION
    
    '------------------------------------------------------------------------------
    ' Browse for start-folder
    '------------------------------------------------------------------------------
    FUNCTION GetFolder (BYVAL hParent AS DWORD) AS STRING
      LOCAL PathID AS DWORD
      LOCAL bInf AS BROWSEINFO
      LOCAL szPath AS ASCIIZ * %MAX_PATH
    
      bInf.hWndOwner = hParent 'Set some properties for the BFF dialog
      bInf.ulFlags   = %BIF_RETURNONLYFSDIRS OR %BIF_DONTGOBELOWDOMAIN
      bInf.lpszTitle = VARPTR(szPath)
    
      PathID = SHBrowseForFolder(bInf) 'Show the Browse-For-Folder dialog
    
      IF PathID THEN
        IF SHGetPathFromIDList(BYVAL PathID, szPath) THEN
          gStartPath = EXTRACT$(szPath, CHR$(0))
          FUNCTION   = gStartPath
        END IF
        CoTaskMemFree PathID 'Free allocated memory
      END IF
    END FUNCTION
    
    '------------------------------------------------------------------------------
    ' Recursive file search procedure
    '------------------------------------------------------------------------------
    SUB ReadDirs (BYVAL path AS STRING)
    
      LOCAL hSearch AS DWORD               ' Search handle
      LOCAL tmpSize AS QUAD                ' QUAD, in case of huge files...
      LOCAL WFD     AS WIN32_FIND_DATA     ' FindFirstFile structure
      LOCAL curpath AS ASCIIZ * %MAX_PATH  ' What to search for
      curpath = path + sWhichfiles                   ' This is what we want to find
    
      hSearch = FindFirstFile(curpath, WFD)       ' Get search handle, if success
      IF hSearch <> %INVALID_HANDLE_VALUE THEN    ' Loop through directory for files
        DO
          IF (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) _  ' If not directory bit is set
              <> %FILE_ATTRIBUTE_DIRECTORY THEN ' (files only here...)
    
            tmpSize = WFD.nFileSizeHigh * (%MAXDWORD + 1) + WFD.nFileSizeLow
    
            temp$=USING$("& & & &",GetFileDateTime(WFD.ftLastWriteTime),RIGHT$("                    "+FORMAT$(tmpSize, "#,###"),20),TRIM$(Path)+WFD.cFileName)
            STDOUT temp$
            INCR iFilecount
          END IF
        LOOP WHILE FindNextFile(hSearch, WFD)
        FindClose hSearch
      END IF
      curpath = path + "*"
      hSearch = FindFirstFile(curpath, WFD)
      IF hSearch <> %INVALID_HANDLE_VALUE THEN
        DO
          IF (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) = %FILE_ATTRIBUTE_DIRECTORY _
              AND (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_HIDDEN) = 0 THEN  ' If dirs, but not hidden..
            IF WFD.cFileName <> "." AND WFD.cFileName <> ".." THEN          ' Not these..
              ReadDirs path + RTRIM$(WFD.cFileName, $NUL) + "\"
            END IF
          END IF
        LOOP WHILE FindNextFile(hSearch, WFD)
        FindClose hSearch
        END IF
    END SUB
    
    
    '------------------------------------------------------------------------------
    ' Main entry point for the application
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN () AS LONG
        iFilecount=0&
        sCurrentdir$=CURDIR$
        sCommandtemp$=UCASE$(COMMAND$)
        sWhichfiles="*"
        sFile$=""
        sGetdirectory$=""
    
        IF LEN(sCommandtemp$)=0 THEN GOTO DIRSTART
    
        sFile$=" "+STRREVERSE$(sCommandtemp$)
        TEMP&=0&
        TEMP&=INSTR(sFile$,ANY ":/\")
        IF TEMP&=0& THEN
                 sGetdirectory$=sCurrentdir$
                 sFile$=TRIM$(STRREVERSE$(sFile$))
           ELSE
           sFile$=STRREVERSE$(sFile$)
           sGetdirectory$=LEFT$(sFile$,(LEN(sFile$)-TEMP&+1))
           sFile$=RIGHT$(sFile$,(TEMP&-1))
           sFile$=TRIM$(sFile$)
        END IF
    
        IF MID$(sGetdirectory$,2,1)<>":" THEN GOTO AROUND1
        TRY
        CHDRIVE MID$(sGetdirectory$,1,1)
        CATCH
        STDOUT "no drive found  = "+MID$(sGetdirectory$,1,1)+":"+" command tail given"+COMMAND$
        FUNCTION=2
        EXIT FUNCTION
    
        END TRY
        AROUND1:
    
        TRY
        CHDIR  sGetdirectory$
        CATCH
        STDOUT "no directory found = "+sGetdirectory$+" command tail given "+COMMAND$
    
        FUNCTION=3
        EXIT FUNCTION
        END TRY
    
    
    DIRSTART:
    
        IF LEN(sFile$)>0 THEN sWhichfiles=sFile$
    
        REM  the logic here is try a subdirectory first then if no subdirectory
        REM      look for files at from the directory specified and below
        TRY
            CHDIR RTRIM$(CURDIR$, ANY "\/") + "\"+sFile$
          CATCH
            gStartPath=RTRIM$(CURDIR$, ANY "\/") + "\"
            ReadDirs gStartPath
          EXIT TRY
          FINALLY
            sWhichfiles="*"
            gStartPath=RTRIM$(CURDIR$, ANY "\/") + "\"
            ReadDirs gStartPath
        END TRY
    
    
        REM returning to initial directory
        IF MID$(sCurrentdir$,2,1)=":" THEN CHDRIVE MID$(sCurrentdir$,1,1)
        CHDIR(sCurrentdir$)
        FUNCTION=0
    
        REM no files found
        IF iFilecount=0& THEN STDOUT " ": FUNCTION=1
    
        END FUNCTION
    p purvis

    Comment


    • #3
      update to dirslist.bas, the directory program 2 i posted above
      fixed date problem above, made files with no time set to equal zero, added seconds to time, and a parameter for military time

      this newest code should fix a date and time problem as listed before

      i also fixed the code to show a file date and time where the date and time are not set for a file to 0000-00-00 for dates and 00:00:00a for tiime.

      i added seconds to the time of the file.

      i added a feature to retrieve dates in military time
      place /mt on the command line otherwise you will get non-military time.

      if you want the windows style of time returned like 01:15p , just edit inside the function to remove the colon and seconds



      Code:
      'compiled with pbcc 4.04
      'dirslist.bas
      'a program to list the files in a directory
      '
      'add a parameter on the command line to make the time returned in military time otherwise non military
      '
      #COMPILE EXE
      #REGISTER NONE
      '#Dim All
      
      '------------------------------------------------------------------------------
      ' Include files
      '------------------------------------------------------------------------------
      
      #INCLUDE "Win32API.inc"
      
      '------------------------------------------------------------------------------
      ' Global variables
      '------------------------------------------------------------------------------
      GLOBAL gStartPath  AS STRING  ' path to start search from
      GLOBAL gsWhichfiles AS STRING
      GLOBAL giFilecount AS LONG
      GLOBAL gitimestyle AS LONG
      
      
      '------------------------------------------------------------------------------
      ' Return properly formatted file date + time as string
      '------------------------------------------------------------------------------
      'the below code should be removed
      'FUNCTION GetFileDateTime(dt AS FILETIME) AS STRING
      '  LOCAL lpsystime AS SYSTEMTIME
      '  LOCAL szDate    AS ASCIIZ * 64 ' date buffer, %LDT_SIZE = 64 bytes
      '  LOCAL szTime    AS ASCIIZ * 64 ' time buffer, %LDT_SIZE = 64 bytes
      '  local dtconverted as FILETIME
      '  ' convert given date to correct format
      '  FileTimeToLocalFileTime dt, dtconverted
      '  FileTimeToSystemTime dtconverted, lpsystime
      '
      '  GetDateFormat %LOCALE_USER_DEFAULT, %DATE_SHORTDATE, BYVAL VARPTR(lpsystime), BYVAL %NULL, szDate, SIZEOF(szDate)
      '  GetTimeFormat %LOCALE_USER_DEFAULT, %TIME_FORCE24HOURFORMAT OR %TIME_NOSECONDS, BYVAL VARPTR(lpsystime), _
      '        BYVAL %NULL, szTime, SIZEOF(szTime)
      '  szDate=TRIM$(szDate)
      '  szTime=TRIM$(szTime)
      '  IF MID$(szDate,2,1)="/" THEN szDate="0"+szDate
      '  IF MID$(szDate,5,1)="/" THEN szDate=MID$(szDate,1,3)+"0"+MID$(szdate,4,6)
      '  IF MID$(szTime,2,1)=":" THEN szTime="0"+szTime
      '  IF RIGHT$(szTime,2)="PM" THEN szTime=LEFT$(szTime,5)+"p" ELSE szTime=LEFT$(szTime,5)+"a"
      '  FUNCTION = MID$(szDate,7,4)+"-"+MID$(szdate,1,2)+"-"+MID$(szdate,4,2) + "  " + szTime
      'END FUNCTION
      
      FUNCTION NEWFileDateTime(NEWdt AS FILETIME ) AS STRING
        LOCAL iYear AS LONG, iMonth AS LONG, iDay AS LONG, iHour AS LONG, iMinute AS LONG, iSecond AS LONG
        LOCAL sysT AS SYSTEMTIME
        LOCAL locT AS FILETIME
        CALL FileTimeToLocalFileTime(NEWdt, locT)
        CALL FileTimeToSystemTime(locT, sysT)
      
         ampm$="a"
       IF gitimestyle& THEN
         REM use military time
            IF sysT.wHour>11 THEN ampm$="p"
                mytimestyle$=RIGHT$("00" + TRIM$(STR$(sysT.wHour)),2) + ":" + RIGHT$("00" + TRIM$(STR$(sysT.wMinute)),2)  + ":" + RIGHT$("00" + TRIM$(STR$(sysT.wSecond)),2)+ ampm$
           ELSE
         'rem use non military time
            IF sysT.wHour<12 THEN
              temp&=sysT.wHour
              IF temp&=0 THEN temp&=12
              mytimestyle$=RIGHT$("00" + TRIM$(STR$(temp&)),2) + ":" + RIGHT$("00" + TRIM$(STR$(sysT.wMinute)),2) + ":" + RIGHT$("00" + TRIM$(STR$(sysT.wSecond)),2)+ ampm$
            ELSE
             ampm$="p"
             temp&=sysT.wHour-12
             IF temp&=0 THEN temp&=12
             mytimestyle$=RIGHT$("00" + TRIM$(STR$(temp&)),2) + ":" + RIGHT$("00" + TRIM$(STR$(sysT.wMinute)),2)  + ":" + RIGHT$("00" + TRIM$(STR$(sysT.wSecond)),2)+ ampm$
         END IF
       END IF
        FUNCTION =   RIGHT$("0000"+TRIM$(STR$(sysT.wYear)),4) + "-" +  RIGHT$("00"+TRIM$(STR$(sysT.wMonth)),2) + "-" +RIGHT$("00"+TRIM$(STR$(sysT.wDay)),2) + "  " + mytimestyle$
      END FUNCTION
      
      '------------------------------------------------------------------------------
      ' Browse for start-folder
      '------------------------------------------------------------------------------
      FUNCTION GetFolder (BYVAL hParent AS DWORD) AS STRING
        LOCAL PathID AS DWORD
        LOCAL bInf AS BROWSEINFO
        LOCAL szPath AS ASCIIZ * %MAX_PATH
      
        bInf.hWndOwner = hParent 'Set some properties for the BFF dialog
        bInf.ulFlags   = %BIF_RETURNONLYFSDIRS OR %BIF_DONTGOBELOWDOMAIN
        bInf.lpszTitle = VARPTR(szPath)
      
        PathID = SHBrowseForFolder(bInf) 'Show the Browse-For-Folder dialog
      
        IF PathID THEN
          IF SHGetPathFromIDList(BYVAL PathID, szPath) THEN
            gStartPath = EXTRACT$(szPath, CHR$(0))
            FUNCTION   = gStartPath
          END IF
          CoTaskMemFree PathID 'Free allocated memory
        END IF
      END FUNCTION
      
      '------------------------------------------------------------------------------
      ' Recursive file search procedure
      '------------------------------------------------------------------------------
      SUB ReadDirs (BYVAL path AS STRING)
      
        LOCAL hSearch AS DWORD               ' Search handle
        LOCAL tmpSize AS QUAD                ' QUAD, in case of huge files...
        LOCAL WFD     AS WIN32_FIND_DATA     ' FindFirstFile structure
        LOCAL curpath AS ASCIIZ * %MAX_PATH  ' What to search for
        LOCAL newWFD     AS WIN32_FIND_DATA     ' FindFirstFile structure
        curpath = path + gsWhichfiles                   ' This is what we want to find
      
        hSearch = FindFirstFile(curpath, WFD)       ' Get search handle, if success
        IF hSearch <> %INVALID_HANDLE_VALUE THEN    ' Loop through directory for files
          DO
            IF (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) _  ' If not directory bit is set
                <> %FILE_ATTRIBUTE_DIRECTORY THEN ' (files only here...)
      
              tmpSize = WFD.nFileSizeHigh * (%MAXDWORD + 1) + WFD.nFileSizeLow
              newwfd.ftlastwritetime=wfd.ftlastwritetime
            '  the old print string using the old get file date and time function
            '  temp$=USING$("& & & &",GetFileDateTime(WFD.ftLastWriteTime),RIGHT$("                    "+FORMAT$(tmpSize, "#,###"),20),TRIM$(Path)+WFD.cFileName)
            '  STDOUT temp$
              temp$=USING$("& & & &",NEWFileDateTime(newWFD.ftLastWriteTime),RIGHT$("                    "+FORMAT$(tmpSize, "#,###"),20),TRIM$(Path)+WFD.cFileName)
              STDOUT TEMP$
      
              INCR giFilecount
            END IF
          LOOP WHILE FindNextFile(hSearch, WFD)
          FindClose hSearch
        END IF
        curpath = path + "*"
        hSearch = FindFirstFile(curpath, WFD)
        IF hSearch <> %INVALID_HANDLE_VALUE THEN
          DO
            IF (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) = %FILE_ATTRIBUTE_DIRECTORY _
                AND (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_HIDDEN) = 0 THEN  ' If dirs, but not hidden..
              IF WFD.cFileName <> "." AND WFD.cFileName <> ".." THEN          ' Not these..
                ReadDirs path + RTRIM$(WFD.cFileName, $NUL) + "\"
              END IF
            END IF
          LOOP WHILE FindNextFile(hSearch, WFD)
          FindClose hSearch
          END IF
      END SUB
      
      
      '------------------------------------------------------------------------------
      ' Main entry point for the application
      '------------------------------------------------------------------------------
      FUNCTION PBMAIN () AS LONG
          sCommandtemp$=TRIM$(UCASE$(COMMAND$))
      
          gitimestyle=0& ' 1& equals military time style with seconds 0& equals non military time style
          IF INSTR(sCommandtemp$,"/MT")>0 THEN
               gitimestyle=1&
               sCommandtemp$=REMOVE$(sCommandtemp$, "/MT")
               sCommandtemp$=TRIM$(sCommandtemp$)
          END IF
      
          IF sCommandtemp$="/?" THEN
          PRINT "DIRSLIST - list files found in a folder(directory) and all folders below"
          PRINT "   examples for command line use"
          PRINT "   DIRSLIST"
          PRINT "   DIRSLIST C:\"
          PRINT "   DIRSLIST C:\*.TXT"
          PRINT "   DIRSLIST *.TXT"
          PRINT "   DIRSLIST ?"
          PRINT "   DIRSLIST *.TXT /MT        /mt uses the military format for time"
          EXIT FUNCTION
          END IF
          
          
          
          giFilecount=0&
          sCurrentdir$=CURDIR$
      
          gsWhichfiles="*"
          sFile$=""
          sGetdirectory$=""
      
          IF LEN(sCommandtemp$)=0 THEN GOTO DIRSTART
      
          sFile$=" "+STRREVERSE$(sCommandtemp$)
          TEMP&=0&
          TEMP&=INSTR(sFile$,ANY ":/\")
          IF TEMP&=0& THEN
                   sGetdirectory$=sCurrentdir$
                   sFile$=TRIM$(STRREVERSE$(sFile$))
             ELSE
             sFile$=STRREVERSE$(sFile$)
             sGetdirectory$=LEFT$(sFile$,(LEN(sFile$)-TEMP&+1))
             sFile$=RIGHT$(sFile$,(TEMP&-1))
             sFile$=TRIM$(sFile$)
          END IF
      
          IF MID$(sGetdirectory$,2,1)<>":" THEN GOTO AROUND1
          TRY
          CHDRIVE MID$(sGetdirectory$,1,1)
          CATCH
          STDOUT "no drive found  = "+MID$(sGetdirectory$,1,1)+":"+" command tail given"+COMMAND$
          FUNCTION=2
          EXIT FUNCTION
      
          END TRY
          AROUND1:
      
          TRY
          CHDIR  sGetdirectory$
          CATCH
          STDOUT "no directory found = "+sGetdirectory$+" command tail given "+COMMAND$
      
          FUNCTION=3
          EXIT FUNCTION
          END TRY
      
      
      DIRSTART:
      
          IF LEN(sFile$)>0 THEN gsWhichfiles=sFile$
      
          REM  the logic here is try a subdirectory first then if no subdirectory
          REM      look for files at from the directory specified and below
          TRY
              CHDIR RTRIM$(CURDIR$, ANY "\/") + "\"+sFile$
            CATCH
              gStartPath=RTRIM$(CURDIR$, ANY "\/") + "\"
              ReadDirs gStartPath
            EXIT TRY
            FINALLY
              gsWhichfiles="*"
              gStartPath=RTRIM$(CURDIR$, ANY "\/") + "\"
              ReadDirs gStartPath
          END TRY
      
      
          REM returning to initial directory
          IF MID$(sCurrentdir$,2,1)=":" THEN CHDRIVE MID$(sCurrentdir$,1,1)
          CHDIR(sCurrentdir$)
          FUNCTION=0
      
          REM no files found
          IF giFilecount=0& THEN STDOUT " ": FUNCTION=1
      
          END FUNCTION
      Last edited by Paul Purvis; 14 Dec 2007, 07:08 PM.
      p purvis

      Comment


      • #4
        the above program does not list all files, reviewing for errors
        paul
        p purvis

        Comment


        • #5
          discussion area
          http://powerbasic.com/support/pbforu...ad.php?t=35885


          here is a rewrite or better said over write.
          the first program would not list all files.
          this program list more files
          code was taken from a mix of threads

          it does not look pretty but it runs nice.
          there is a lot of duplicate code that could have possibly been done away with more functions but this way i did not have to spend much time separating the utc/gmt time from the local time routines.
          the program's file listing goes to the stdout device
          on the command line you can choose military time, utc/gmt time, all files or separate read only, hidden, and system files.

          the biggest change is how the program acquires the files and penetrates the subdirectories
          files with no date set will be given a date/time of 0000-00-00 00:00:00a

          this program was written for the purpose of sorting a file listing where this program has redirected its display to that file to be sorted.
          all columns are fixed in length except for the file name making sorting of file list easier.

          here is a listing of a help page for dirslist.exe that can be gotten for a short time at
          http://pdptemp.dyndns.org/zipcode/

          DIRSLIST - list files found in a folder(directory) and all folders below
          examples for command line use
          DIRSLIST
          DIRSLIST C:\
          DIRSLIST C:\*.TXT
          DIRSLIST *.TXT
          DIRSLIST *. retreive all files having no periods in the file name
          DIRSLIST * retreive all files
          DIRSLIST p* retreive all files that start with a p
          DIRSLIST P*. retreive all files start with a p and have no period
          DIRSLIST *p* retreive all files that have a p in the name
          DIRSLIST *.* retreive all files
          ----------------------DIRSLIST USEFULE PARAMETERS-----------------------
          /? this help page
          /MT uses the military format for time
          /ALL gets all files
          /HIDDEN gets hidden files only
          /READ gets readonly files only
          /SYSTEM gets system files only
          /IT file date times are in GMT/UTC time
          /GMT file date times are in GMT/UTC time
          /UTC file date times are in GMT/UTC time
          /FC file date times are createion time
          /FA file date times are last accessed time
          /FW file date times are last written to time, the default time used
          /TODAY file with date times of today only
          /MONTH file with date times of the current month only
          /Mx file with date times in a certain month x months back
          /Bx file with date times between today and 1st of month, x months back
          /COUNT displays the number of files at the bottom of the listing
          /COUNTONLY displays only the number of files matched
          /NFA remove the file attributes from the listing
          /NFS remove the size of the file from the listing
          /NFT remove the time of the file from the listing
          /NFD remove the time and date of the file from the listing
          /RAW listing only the file name
          Code:
          'DIRSLIST.BAS
          'compiled with pbcc 8.04
          
          #COMPILE EXE "DIRSLIST.EXE"
          #REGISTER NONE
          
          #DIM ALL
          #INCLUDE "Win32Api.Inc"
          
          DECLARE FUNCTION PathMatchSpec LIB "SHLWAPI.DLL" ALIAS "PathMatchSpecA"(pszFile AS ASCIIZ, pszSpec AS ASCIIZ) AS LONG
          
          'for date functions
          %LOCALE_USA    = 1033
          
          'for wildmatch function
          %No_Match = 0
          %Match    = 1
          
          GLOBAL gitimestyle AS LONG
          GLOBAL giflagfile AS LONG
          GLOBAL giflaghiddenonlyfile AS LONG
          GLOBAL giflagreadonlyfile AS LONG
          GLOBAL giflagsystemonlyfile AS LONG
          GLOBAL giflaglastwritetime AS LONG
          GLOBAL giflagaccesstime AS LONG
          GLOBAL giflagcreationtime AS LONG
          GLOBAL giflagnotime AS LONG
          GLOBAL giflagnodate AS LONG
          GLOBAL giflagfilesize AS LONG
          GLOBAL giflagattribute AS LONG
          GLOBAL gsfileattribute AS STRING
          GLOBAL giflagtoday AS LONG
          GLOBAL gsflagtoday AS STRING
          GLOBAL giflagmonth AS LONG
          GLOBAL gsflagmonth AS STRING
          GLOBAL gsfiledateforuse AS STRING
          GLOBAL gtmonthstart AS SystemTime
          GLOBAL gtmonthfilecomparetime AS Systemtime
          GLOBAL giflagmonthpast AS LONG
          GLOBAL giinternationaltime AS LONG
          GLOBAL giflagcountonly AS LONG
          GLOBAL giflagcount AS LONG
          
          
          TYPE MYTIME
            wYear AS WORD
            wMonth AS WORD
            wDayOfWeek AS WORD
            wDay AS WORD
            wHour AS WORD                           ' )
            wMinute AS WORD                         ' ) time elements ignored here
            wSecond AS WORD                         ' )
            wMilliseconds AS WORD                   ' )
          END TYPE
          
          
          'this function sets the gtmonthstart variable used for date compare purposes
           FUNCTION monthbackuse(subtractmths AS LONG) AS STRING
           LOCAL st AS SYSTEMTIME
           LOCAL wtemp AS WORD
            GetLocalTime st
            st.wday=1??
            st.wHour=0??
            st.wMinute=0??
            st.wSecond=0??
            st.wMilliseconds=0??
            wtemp=st.wmonth
             WHILE subtractmths
                DECR subtractmths
                wtemp=wtemp-1??
                IF wtemp<1?? THEN
                   wtemp=12??
                   st.wyear=st.wyear-1??
                END IF
                st.wmonth=wtemp
              WEND
               FUNCTION=RIGHT$("0000"+TRIM$(STR$(st.wYear)),4) + "-" +  RIGHT$("00"+TRIM$(STR$(st.wMonth)),2)
          END FUNCTION
          
          FUNCTION monthback(subtractmths AS LONG) AS STRING
           LOCAL st AS SYSTEMTIME
           LOCAL wtemp AS WORD
            GetLocalTime st
            st.wday=1??
            st.wHour=0??
            st.wMinute=0??
            st.wSecond=0??
            st.wMilliseconds=0??
            wtemp=st.wmonth
             WHILE subtractmths
                DECR subtractmths
                wtemp=wtemp-1??
                IF wtemp<1?? THEN
                   wtemp=12??
                   st.wyear=st.wyear-1??
                END IF
                st.wmonth=wtemp
              WEND
              gtmonthstart=st
          END FUNCTION
          
          
          
          
          FUNCTION filedatetimeGMT(somefile AS STRING) AS STRING
          LOCAL hFile         AS DWORD
          LOCAL FindData   AS WIN32_FIND_DATA
          LOCAL Sys_Time AS SystemTime
          LOCAL AMPM AS STRING
          LOCAL mytimestyle AS STRING
          LOCAL temp AS LONG
          LOCAL tmpSize AS QUAD                ' QUAD, in case of huge files...
          LOCAL sizeoffile AS STRING
          LOCAL FileAttribute AS STRING
          LOCAL sfiledatetime AS STRING
          
          FUNCTION=""
          hFile = FindFirstFile(BYVAL STRPTR(SomeFile), FindData) 'Get file data, file time included
          IF hFile <> %INVALID_HANDLE_VALUE THEN 'We have an handle coresponding to the file
          
             IF giflagfilesize=0& THEN
                tmpSize = FindData.nFileSizeHigh * (%MAXDWORD + 1) + FindData.nFileSizeLow
                sizeoffile=RIGHT$("                 "+FORMAT$(tmpSize, "#,###"),17)+" "
                ELSE
                sizeoffile=""
             END IF
          
          
          
          
           '       FUNCTION="Creation: " & _
           '                FileTimeToInternationalTime(FindData.ftCreationTime) & $CRLF & _
           '                "Last access: " & _
           '                FileTimeToInternationalTime(FindData.ftLastAccessTime) & $CRLF & _
           '                "Last write: " & _
           '                FileTimeToInternationalTime(FindData.ftLastWriteTime)
          ' convert to international time
          'FileTimeToSystemTime FindData.ftLastWriteTime, Sys_Time
          IF  giflagcreationtime=1&  THEN FileTimeToSystemTime FindData.ftCreationTime, Sys_Time
          IF  giflagaccesstime=1&    THEN FileTimeToSystemTime FindData.ftLastAccessTime, Sys_Time
          IF  giflaglastwritetime=1& THEN FileTimeToSystemTime FindData.ftLastWriteTime, Sys_Time
          
          gtmonthfilecomparetime=Sys_Time
          
          
          ' FUNCTION = _
          '   FORMAT$(Sys_Time.wyear, "0000") & "/" & FORMAT$(Sys_Time.wMonth,  "00") & "/" & _
          '   FORMAT$(Sys_Time.wDay,    "00") & " " & FORMAT$(Sys_Time.wHour,   "00") & ":" & _
          '   FORMAT$(Sys_Time.wMinute, "00") & ":" & FORMAT$(Sys_Time.wSecond, "00") & " " & _
          '   "(" & FORMAT$(Sys_Time.wMilliSeconds, "000") & " milliseconds) " & _
          '   CHOOSE$(Sys_Time.wDayOfWeek + 1, "Sunday", "Monday", "Tuesday", "Wednesday", _
          '                                   "Thursday", "Friday", "Saturday")
          ' FUNCTION = _
          '   FORMAT$(Sys_Time.wyear, "0000") & "-" & FORMAT$(Sys_Time.wMonth,  "00") & "-" & _
          '   FORMAT$(Sys_Time.wDay,    "00") & "  " & FORMAT$(Sys_Time.wHour,   "00") & ":" & _
          '   FORMAT$(Sys_Time.wMinute, "00") & ":" & FORMAT$(Sys_Time.wSecond, "00") & "t " & _
          '   CHOOSE$(Sys_Time.wDayOfWeek + 1, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
          
          ampm="a"
          IF gitimestyle THEN
             REM use military time
                    IF Sys_Time.wHour>11 THEN
                          ampm="p"
                    END IF
                    mytimestyle=RIGHT$("00" + TRIM$(STR$(Sys_Time.wHour)),2) + _
                    ":" + RIGHT$("00" + TRIM$(STR$(Sys_Time.wMinute)),2)  + _
                    ":" + RIGHT$("00" + TRIM$(STR$(Sys_Time.wSecond)),2)+ _
                    ampm+ " "+CHOOSE$(Sys_Time.wDayOfWeek + 1, "sun", "mon", "tue", "wed", "thu", "fri", "sat")
          
               ELSE
             'rem use non military time
                IF Sys_Time.wHour<12 THEN
                  temp=Sys_Time.wHour
                  IF temp=0 THEN temp=12
                  mytimestyle=_
                  RIGHT$("00" + TRIM$(STR$(temp)),2) + ":" + _
                  RIGHT$("00" + TRIM$(STR$(Sys_Time.wMinute)),2) + ":" + _
                  RIGHT$("00" + TRIM$(STR$(Sys_Time.wSecond)),2)+ _
                    ampm+ " "+CHOOSE$(Sys_Time.wDayOfWeek + 1, "sun", "mon", "tue", "wed", "thu", "fri", "sat")
                ELSE
                 ampm="p"
                 temp=Sys_Time.wHour-12
                 IF temp=0 THEN temp=12
                 mytimestyle=_
                 RIGHT$("00" + TRIM$(STR$(temp)),2) + ":" + _
                 RIGHT$("00" + TRIM$(STR$(Sys_Time.wMinute)),2)  + ":" + _
                 RIGHT$("00" + TRIM$(STR$(Sys_Time.wSecond)),2)+ _
                  ampm+ " "+CHOOSE$(Sys_Time.wDayOfWeek + 1, "sun", "mon", "tue", "wed", "thu", "fri", "sat")
               END IF
           END IF
          
          
            FileAttribute = ""
               ' IF (FindData.dwFileAttributes AND %Normal)   THEN FileAttribute = FileAttribute & "N" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %ReadOnly) THEN FileAttribute = FileAttribute & "R" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %Hidden)   THEN FileAttribute = FileAttribute & "H" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %System)   THEN FileAttribute = FileAttribute & "S" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %Archive)  THEN FileAttribute = FileAttribute & "A" ELSE FileAttribute = FileAttribute & " "
          
            gsfileattribute=fileattribute
            fileattribute=fileattribute+" "
            IF giflagattribute THEN fileattribute=""
          
          
           sfiledatetime=RIGHT$("0000"+TRIM$(STR$(Sys_Time.wYear)),4) + _
                       "-" +  RIGHT$("00"+TRIM$(STR$(Sys_Time.wMonth)),2) + _
                       "-" +RIGHT$("00"+TRIM$(STR$(Sys_Time.wDay)),2) + _
                       " " + mytimestyle+"U "
          
           gsfiledateforuse=LEFT$(sfiledatetime,10)
          
           IF giflagnotime=1& THEN
               sfiledatetime=RIGHT$("0000"+TRIM$(STR$(Sys_Time.wYear)),4) + _
                       "-" +  RIGHT$("00"+TRIM$(STR$(Sys_Time.wMonth)),2) + _
                       "-" +RIGHT$("00"+TRIM$(STR$(Sys_Time.wDay)),2) + " "
          END IF
          
          IF  Sys_Time.wYear=1601 THEN
               sfiledatetime="0000-00-00 00:00:00a    U "
                IF giflagnotime=1& THEN  sfiledatetime="0000-00-00 "
          END IF
          
          
          IF giflagnodate THEN sfiledatetime=""
          
            FUNCTION =sfiledatetime+fileattribute+sizeoffile
          
           FindClose(hFile)
           END IF
          END FUNCTION
          
          
          
          
          
          FUNCTION  filedatetimeLOCAL(somefile AS STRING) AS STRING
          LOCAL hFile         AS DWORD
          LOCAL FindData   AS WIN32_FIND_DATA
          LOCAL AMPM AS STRING
          LOCAL mytimestyle AS STRING
          LOCAL temp AS LONG
          LOCAL tmpSize AS QUAD                ' QUAD, in case of huge files...
          LOCAL sizeoffile AS STRING
          LOCAL FileAttribute AS STRING
          LOCAL Loct AS FileTime
          LOCAL Syst AS SystemTime
          LOCAL sfiledatetime AS STRING
          
          
          FUNCTION=""
          hFile = FindFirstFile(BYVAL STRPTR(SomeFile), FindData) 'Get file data, file time included
          IF hFile <> %INVALID_HANDLE_VALUE THEN 'We have an handle coresponding to the file
             IF giflagfilesize=0& THEN
                tmpSize = FindData.nFileSizeHigh * (%MAXDWORD + 1) + FindData.nFileSizeLow
                sizeoffile=RIGHT$("                 "+FORMAT$(tmpSize, "#,###"),17)+" "
                ELSE
                sizeoffile=""
             END IF
          
          
          
          
           '       FUNCTION="Creation: " & _
           '                FileTimeToInternationalTime(FindData.ftCreationTime) & $CRLF & _
           '                "Last access: " & _
           '                FileTimeToInternationalTime(FindData.ftLastAccessTime) & $CRLF & _
           '                "Last write: " & _
           '                FileTimeToInternationalTime(FindData.ftLastWriteTime)
          ' convert to local time
          'FileTimeToLocalFileTime(FindData.ftLastWriteTime, Loct)
          
          IF  giflagcreationtime=1&  THEN FileTimeToLocalFileTime FindData.ftCreationTime, LocT
          IF  giflagaccesstime=1&    THEN FileTimeToLocalFileTime FindData.ftLastAccessTime, LocT
          IF  giflaglastwritetime=1& THEN FileTimeToLocalFileTime FindData.ftLastWriteTime, Loct
          
          FileTimeToSystemTime(locT, sysT)
          gtmonthfilecomparetime=sysT
          
          
          
          ' FUNCTION = _
          '   FORMAT$(Syst.wyear, "0000") & "/" & FORMAT$(Syst.wMonth,  "00") & "/" & _
          '   FORMAT$(Syst.wDay,    "00") & " " & FORMAT$(Syst.wHour,   "00") & ":" & _
          '   FORMAT$(Syst.wMinute, "00") & ":" & FORMAT$(Syst.wSecond, "00") & " " & _
          '   "(" & FORMAT$(Syst.wMilliSeconds, "000") & " milliseconds) " & _
          '   CHOOSE$(Syst.wDayOfWeek + 1, "Sunday", "Monday", "Tuesday", "Wednesday", _
          '                                   "Thursday", "Friday", "Saturday")
          ' FUNCTION = _
          '   FORMAT$(Syst.wyear, "0000") & "-" & FORMAT$(Syst.wMonth,  "00") & "-" & _
          '   FORMAT$(Syst.wDay,    "00") & "  " & FORMAT$(Syst.wHour,   "00") & ":" & _
          '   FORMAT$(Syst.wMinute, "00") & ":" & FORMAT$(Syst.wSecond, "00") & "t " & _
          '   CHOOSE$(Syst.wDayOfWeek + 1, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
          
          ampm="a"
          IF gitimestyle THEN
             REM use military time
                    IF Syst.wHour>11 THEN
                          ampm="p"
                    END IF
                    mytimestyle=RIGHT$("00" + TRIM$(STR$(Syst.wHour)),2) + _
                    ":" + RIGHT$("00" + TRIM$(STR$(Syst.wMinute)),2)  + _
                    ":" + RIGHT$("00" + TRIM$(STR$(Syst.wSecond)),2)+ _
                    ampm+ " "+CHOOSE$(SysT.wDayOfWeek + 1, "sun", "mon", "tue", "wed", "thu", "fri", "sat")
          
          
                  ELSE
             'rem use non military time
                IF Syst.wHour<12 THEN
                  temp=Syst.wHour
                  IF temp=0 THEN temp=12
                  mytimestyle=_
                  RIGHT$("00" + TRIM$(STR$(temp)),2) + ":" + _
                  RIGHT$("00" + TRIM$(STR$(Syst.wMinute)),2) + ":" + _
                  RIGHT$("00" + TRIM$(STR$(Syst.wSecond)),2)+ _
                   ampm+ " "+CHOOSE$(SysT.wDayOfWeek + 1, "sun", "mon", "tue", "wed", "thu", "fri", "sat")
                ELSE
                 ampm="p"
                 temp=Syst.wHour-12
                 IF temp=0 THEN temp=12
                 mytimestyle=_
                 RIGHT$("00" + TRIM$(STR$(temp)),2) + ":" + _
                 RIGHT$("00" + TRIM$(STR$(Syst.wMinute)),2)  + ":" + _
                 RIGHT$("00" + TRIM$(STR$(Syst.wSecond)),2)+ _
                  ampm+ " "+CHOOSE$(SysT.wDayOfWeek + 1, "sun", "mon", "tue", "wed", "thu", "fri", "sat")
               END IF
           END IF
          
          
            FileAttribute = ""
                ' IF (FindData.dwFileAttributes AND %Normal)   THEN FileAttribute = FileAttribute & "N" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %ReadOnly) THEN FileAttribute = FileAttribute & "R" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %Hidden)   THEN FileAttribute = FileAttribute & "H" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %System)   THEN FileAttribute = FileAttribute & "S" ELSE FileAttribute = FileAttribute & " "
                 IF (FindData.dwFileAttributes AND %Archive)  THEN FileAttribute = FileAttribute & "A" ELSE FileAttribute = FileAttribute & " "
          
            gsfileattribute=fileattribute
          
            fileattribute=fileattribute+" "
            IF giflagattribute THEN fileattribute=""
          
          sfiledatetime=RIGHT$("0000"+TRIM$(STR$(Syst.wYear)),4) + _
                       "-" +  RIGHT$("00"+TRIM$(STR$(Syst.wMonth)),2) + _
                       "-" +RIGHT$("00"+TRIM$(STR$(Syst.wDay)),2) + _
                       " " + mytimestyle+"  "
          
          gsfiledateforuse=LEFT$(sfiledatetime,10)
          
          IF giflagnotime=1& THEN
               sfiledatetime=RIGHT$("0000"+TRIM$(STR$(Syst.wYear)),4) + _
                       "-" +  RIGHT$("00"+TRIM$(STR$(Syst.wMonth)),2) + _
                       "-" +RIGHT$("00"+TRIM$(STR$(Syst.wDay)),2) + " "
          END IF
          
          IF  Syst.wYear=1601 THEN
               sfiledatetime="0000-00-00 00:00:00a     "
                IF giflagnotime=1& THEN  sfiledatetime="0000-00-00 "
          END IF
          
          IF giflagnodate THEN sfiledatetime=""
          
           FUNCTION =sfiledatetime+fileattribute+sizeoffile
          
           FindClose(hFile)
           END IF
          END FUNCTION
          
          '______________________________________________________________________________
          
          FUNCTION FileEnum(Root AS STRING, File() AS STRING, Filter AS STRING) AS LONG
           LOCAL  FileName    AS STRING
           LOCAL  Looper      AS LONG
           LOCAL  FolderCount AS DWORD
           STATIC FileCount   AS DWORD
           STATIC FolderDeep  AS DWORD
           LOCAL FILEDATE AS STRING
          
           INCR FolderDeep
           DIM SubFolder(0 TO 0) AS STRING
           IF ASC(Root, - 1) <> 92 THEN Root = Root & "\" 'Must end with a backslash
           SubFolder(0) = Root
           FileName = DIR$(SubFolder(0) & "*.*", %SubDir OR %ReadOnly OR %SYSTEM OR %HIDDEN)
          
          
          ' FileName = DIR$(SubFolder(0) & "*",0 OR 1 OR 2 OR 3 OR 4 OR 6 OR 7 OR 16 or 32)
            'Get folder or file
           IF LEN(FileName) THEN
             DO 'Do a loop for every entry in this folder
               IF (GETATTR(SubFolder(0) & FileName) AND %SUBDIR) THEN 'It's a subfolder
                 INCR FolderCount 'Keep track of how many subfolder
                 REDIM PRESERVE SubFolder(0 TO FolderCount)
                 SubFolder(FolderCount) = SubFolder(0) & FileName & "\" 'Keep folder name for later use
               ELSE 'GetAttr told us that it is a file
                   
                 
                 IF RIGHT$(filter,2)="*." THEN IF INSTR(FILENAME,".")=0& THEN FILENAME=FILENAME+"."
                 IF PathMatchSpec(BYVAL STRPTR(FileName), BYVAL STRPTR(Filter)) THEN 'Check against Filter
                   IF RIGHT$(filename,1)="." THEN filename=LEFT$(filename,(LEN(filename)-1))
                   
              
                   
                    ' REDIM PRESERVE File(0 TO FileCount)
          
                   IF giinternationaltime THEN
                       FILEDATE=FILEDATETIMEGMT(SubFolder(0) & FileName)
                       ELSE
                       FILEDATE=FILEDATETIMELOCAL(SubFolder(0) & FileName)
                   END IF
                    IF giflagtoday THEN
                        IF gsfiledateforuse<>gsflagtoday THEN GOTO ADDFILELOOP
                    END IF
                     IF giflagmonth THEN
                        IF MID$(gsfiledateforuse,1,7)<>gsflagmonth THEN GOTO ADDFILELOOP
                    END IF
          
                    IF giflagmonthpast THEN
                        IF gtmonthfilecomparetime<gtmonthstart THEN GOTO ADDFILELOOP
                    END IF
          
          
                   '  File(FileCount) = FILEDATE+ " "+SubFolder(0) & FileName
                    IF giflagsystemonlyfile+giflaghiddenonlyfile+giflagfile+giflagreadonlyfile=0& AND UCASE$(MID$(gsfileattribute,2,2))="  " THEN
                        IF giflagcountonly=0& THEN STDOUT FILEDATE+ SubFolder(0) & FileName
                        INCR FileCount 'Zero based array
                        GOTO ADDFILELOOP
                        END IF
          
                    IF giflagreadonlyfile=1& AND UCASE$(MID$(gsfileattribute,1,1))="R" THEN
                        IF giflagcountonly=0& THEN  STDOUT FILEDATE+ SubFolder(0) & FileName
                         INCR FileCount  'Zero based array
                         GOTO ADDFILELOOP
                       END IF
                    IF giflaghiddenonlyfile=1& AND UCASE$(MID$(gsfileattribute,2,1))="H" THEN
                        IF giflagcountonly=0& THEN  STDOUT FILEDATE+ SubFolder(0) & FileName
                         INCR FileCount  'Zero based array
                         GOTO ADDFILELOOP
                         END IF
                    IF giflagsystemonlyfile=1& AND UCASE$(MID$(gsfileattribute,3,1))="S" THEN
                         IF giflagcountonly=0& THEN  STDOUT FILEDATE+ SubFolder(0) & FileName
                          INCR FileCount  'Zero based array
                          GOTO ADDFILELOOP
                          END IF
                    IF giflagfile=1& THEN
                        IF giflagcountonly=0& THEN STDOUT FILEDATE+ SubFolder(0) & FileName
                        INCR FileCount  'Zero based array
                        GOTO ADDFILELOOP
                        END IF
                 'end if
                 END IF
               END IF
               ADDFILELOOP:
          
               FileName = DIR$ 'Get next file or folder
             LOOP WHILE LEN(FileName) 'Loop if something found
             DIR$ CLOSE
          
             FOR Looper = 1 TO FolderCount
               FileEnum SubFolder(Looper), File() , Filter 'Function call itself to get sub-folder files
             NEXT
           END IF
          
           DECR FolderDeep
           IF FolderDeep = 0 THEN 'Exiting from first call, function is not in recursive state
             FUNCTION = FileCount
             FileCount = 0 'Reset for subsequent call
           END IF
          
          END FUNCTION
          
          
          
          '______________________________________________________________________________
          
          
          FUNCTION PBMAIN()
           LOCAL sgetdirectory  AS STRING
           DIM   File(0 TO 0) AS STRING
           LOCAL sFilter       AS STRING
           LOCAL FileCount    AS DWORD
           LOCAL sCommandtemp AS STRING
           LOCAL imonthsback AS LONG
           LOCAL itemp AS LONG
           LOCAL iI AS LONG
           LOCAL sCurrentdir AS STRING
          
          giflaglastwritetime=1&
          giflagaccesstime=0&
          giflagcreationtime=0&
          giflagnotime=0&
          giflagnodate=0&
          giflagfilesize=0&
          giflagattribute=0&
          giflagtoday=0&
          gsflagtoday=""
          giflagmonth=0&
          gsflagmonth=""
          giflagmonthpast=0&
          
          
          
          
             sCommandtemp=" "+TRIM$(UCASE$(COMMAND$))+" "
          
              IF INSTR(sCommandtemp,"/FC")>0 THEN  ' display file creation dates
                   giflagcreationtime=1&
                   giflaglastwritetime=0&
                   giflagaccesstime=0&
                   sCommandtemp=REMOVE$(sCommandtemp, "/FC")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              IF INSTR(sCommandtemp,"/FA")>0 THEN    'display files last accessed dates
                   giflagaccesstime=1&
                   giflaglastwritetime=0&
                   giflagcreationtime=0&
                   sCommandtemp=REMOVE$(sCommandtemp, "/FA")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              IF INSTR(sCommandtemp,"/FW")>0 THEN     'display files last write dates
                   giflaglastwritetime=1&
                   giflagaccesstime=0&
                   giflagcreationtime=0&
                   sCommandtemp=REMOVE$(sCommandtemp, "/FW")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              IF INSTR(sCommandtemp,"/NFT")>0 THEN    'do not display the file time
                   giflagnotime=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/NFT")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
              IF INSTR(sCommandtemp,"/NFD")>0 THEN    'do not display the file date and time
                   giflagnodate=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/NFD")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
                IF INSTR(sCommandtemp,"/NFS")>0 THEN     'do not display the file size
                   giflagfilesize=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/NFS")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
          
              gitimestyle=0& ' 1& equals military time style with seconds 0& equals non military time style
              IF INSTR(sCommandtemp,"/MT")>0 THEN
                   gitimestyle=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/MT")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
             giinternationaltime=0& ' 1& equals display file dates in international time
              IF INSTR(sCommandtemp,"/IT")>0 THEN
                   giinternationaltime=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/IT")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
              IF INSTR(sCommandtemp,"/GMT")>0 THEN   ' another method to display file dates in international time
                   giinternationaltime=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/GMT")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              IF INSTR(sCommandtemp,"/UTC")>0 THEN    ' another method to display file dates in international time
                   giinternationaltime=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/UTC")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              giflaghiddenONLYfile=0& ' 1& equals list hidden files only
              IF INSTR(sCommandtemp,"/HIDDEN")>0 THEN
                   giflagattribute=0&
                   giflaghiddenONLYfile=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/HIDDEN")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              giflagsystemonlyfile=0& ' 1& equals list system files only
              IF INSTR(sCommandtemp,"/SYSTEM")>0 THEN
                   giflagattribute=0&
                   giflagsystemonlyfile=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/SYSTEM")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
               giflagreadonlyfile=0& ' 1& equals list readonly files only
              IF INSTR(sCommandtemp,"/READ")>0 THEN
                   giflagattribute=0&
                   giflagreadonlyfile=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/READ")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              giflagfile=0& ' 1& equals list all files
              IF INSTR(sCommandtemp,"/ALL")>0 THEN    '1& equal list all files hidden, system,readonly etc
                   giflagattribute=0&
                   giflagfile=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/ALL")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
              IF INSTR(sCommandtemp,"/NFA")>0 THEN   'do not dispaly the file attributes
                   giflagattribute=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/NFA")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              giflagcountonly=0& ' 1& equals do not display the files found
              giflagcount=0&    ' 1& equals display the number of files found
              IF INSTR(sCommandtemp,"/COUNTONLY")>0 THEN
                   giflagcountonly=1&
                   giflagcount=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/COUNTONLY")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
              
              IF INSTR(sCommandtemp,"/COUNT")>0 THEN  'display on the last line the number of files found
                   giflagcount=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/COUNT")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
              
                giflagtoday=0& ' 1& equals list files with dates of today only
              IF INSTR(sCommandtemp,"/TODAY")>0 THEN
                   giflagtoday=1&
                   gsflagtoday=MID$(DATE$,7,4)+"-"+MID$(DATE$,1,2)+"-"+MID$(DATE$,4,2)
                   sCommandtemp=REMOVE$(sCommandtemp, "/TODAY")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
          
              IF INSTR(sCommandtemp,"/MONTH")>0 THEN  'list files with dates of this month only
                   giflagmonth=1&
                   gsflagmonth=MID$(DATE$,7,4)+"-"+MID$(DATE$,1,2)
                   sCommandtemp=REMOVE$(sCommandtemp, "/MONTH")
                   sCommandtemp=TRIM$(sCommandtemp)
              END IF
              
              IF INSTR(sCommandtemp,"/B")>0 THEN    'list files between today and on the 1st x months back
                 imonthsback&=0&
                 iTEMP=INSTR(sCommandtemp,"/B")
                 IF INSTR("0123456789",MID$(sCommandtemp,itemp+2&,1&))<>0& THEN
                    FOR iI=iTEMP+2& TO LEN(sCommandtemp)
                      IF INSTR("01234567890",MID$(sCommandtemp,iI,1&))=0&  THEN EXIT FOR
                    NEXT iI
               
                    monthback(VAL(MID$(sCommandtemp,itemp+2&,iI-1&)))
                    giflagmonthpast=1&
                   sCommandtemp=REMOVE$(sCommandtemp, "/B"+MID$(sCommandtemp,itemp+2&,(iI-1&-iTEMP)))
                 END IF
              END IF
          
             IF INSTR(sCommandtemp,"/M")>0 THEN    'list files between today and on the 1st x months back
                 giflagmonth=0&
                 iTEMP=INSTR(sCommandtemp,"/M")
                 IF INSTR("0123456789",MID$(sCommandtemp,itemp+2&,1&))<>0& THEN
                    FOR iI=iTEMP+2& TO LEN(sCommandtemp)
                      IF INSTR("01234567890",MID$(sCommandtemp,iI,1&))=0&  THEN EXIT FOR
                    NEXT iI
                    giflagmonth=1&
                    gsflagmonth=monthbackuse(VAL(MID$(sCommandtemp,itemp+2&,iI-1&)))
                    sCommandtemp=REMOVE$(sCommandtemp, "/M"+MID$(sCommandtemp,itemp+2&,(iI-1&-iTEMP)))
                 END IF
             END IF
               IF INSTR(sCommandtemp,"/RAW")>0 THEN  ' only place file name in listing
                  giflagnotime=1&
                  giflagnodate=1&
                  giflagfilesize=1&
                  giflagattribute=1&
                  sCommandtemp=REMOVE$(sCommandtemp, "/RAW")
                  sCommandtemp=TRIM$(sCommandtemp)
              END IF
             
          
              sCommandtemp=TRIM$(sCommandtemp)
          
              IF sCommandtemp="/?" OR INSTR(sCommandtemp,"/") THEN
              PRINT "DIRSLIST - list files found in a folder(directory) and all folders below"
              PRINT "  examples for command line use"
              PRINT "  DIRSLIST"
              PRINT "  DIRSLIST C:\"
              PRINT "  DIRSLIST C:\*.TXT"
              PRINT "  DIRSLIST *.TXT"
              PRINT "  DIRSLIST *.    retreive all files having no periods in the file name"
              PRINT "  DIRSLIST *     retreive all files"
              PRINT "  DIRSLIST p*    retreive all files that start with a p"
              PRINT "  DIRSLIST P*.   retreive all files start with a p and have no period"
              PRINT "  DIRSLIST *p*   retreive all files that have a p in the name"
              PRINT "  DIRSLIST *.*   retreive all files"
              PRINT "----------------------DIRSLIST USEFULE PARAMETERS-----------------------"
              PRINT " /?         this help page"
              PRINT " /MT        uses the military format for time"
              PRINT " /ALL       gets all files"
              PRINT " /HIDDEN    gets hidden files only"
              PRINT " /READ      gets readonly files only"
              PRINT " /SYSTEM    gets system files only"
              PRINT " /IT        file date times are in GMT/UTC time"
              PRINT " /GMT       file date times are in GMT/UTC time"
              PRINT " /UTC       file date times are in GMT/UTC time"
              PRINT " /FC        file date times are createion time"
              PRINT " /FA        file date times are last accessed time"
              PRINT " /FW        file date times are last written to time, the default time used"
              PRINT " /TODAY     file with date times of today only"
              PRINT " /MONTH     file with date times of the current month only"
              PRINT " /Mx        file with date times in a certain month x months back"
              PRINT " /Bx        file with date times between today and 1st of month, x months back"
              PRINT " /COUNT     displays the number of files at the bottom of the listing"
              PRINT " /COUNTONLY displays only the number of files matched"
              PRINT " /NFA       remove the file attributes from the listing"
              PRINT " /NFS       remove the size of the file from the listing"
              PRINT " /NFT       remove the time of the file from the listing"
              PRINT " /NFD       remove the time and date of the file from the listing"
              PRINT " /RAW       listing only the file name"
                EXIT FUNCTION
              END IF
          
          
          sCurrentdir=CURDIR$
          sFilter="*.*"
          sGetdirectory=""
              IF LEN(sCommandtemp)=0 THEN GOTO DIRSTART
              sfilter=" "+STRREVERSE$(sCommandtemp)
              iTEMP=0&
              iTEMP=INSTR(sfilter,ANY ":/\")
              IF ITEMP=0& THEN
                       sgetdirectory=sCurrentdir
                       sfilter=TRIM$(STRREVERSE$(sfilter))
                    ELSE
                 sfilter=STRREVERSE$(sfilter)
                 sgetdirectory=LEFT$(sfilter,(LEN(sfilter)-iTEMP+1))
                 sfilter=RIGHT$(sfilter,(iTEMP-1))
                 sfilter=TRIM$(sfilter)
              END IF
          
              sgetdirectory=TRIM$(sgetdirectory)
              IF MID$(sgetdirectory,2,1)<>":" THEN GOTO AROUND1
              IF sgetdirectory="" THEN GOTO AROUND1
              TRY
              CHDRIVE MID$(sgetdirectory,1,1)
              CATCH
              STDOUT "no drive found  = "+MID$(sgetdirectory,1,1)+":"+" command tail given"+COMMAND$
              FUNCTION=2
              EXIT FUNCTION
          
              END TRY
              AROUND1:
          
              TRY
              IF sgetdirectory="" THEN CHDIR RTRIM$(CURDIR$, ANY "\/") + "\"+sgetdirectory ELSE CHDIR  sgetdirectory
              CATCH
              STDOUT "no directory found = "+sgetdirectory+" command tail given "+COMMAND$
          
              FUNCTION=3
              EXIT FUNCTION
              END TRY
          
          
          DIRSTART:
              REM  the logic here is try a subdirectory first then if no subdirectory
              REM      look for files at from the directory specified and below
              IF sfilter="*" THEN sfilter="*.*"
                  
              TRY
                  CHDIR RTRIM$(CURDIR$, ANY "\/") + "\"+sgetdirectory
                CATCH
                  sgetdirectory=RTRIM$(CURDIR$, ANY "\/") + "\"
                  IF sfilter="" THEN sfilter="*.*"
                  
                   FileCount = FileEnum(sgetdirectory, File(), sFilter)
                   EXIT TRY
                FINALLY
                  sfilter="*.*"
                  sgetdirectory=RTRIM$(CURDIR$, ANY "\/") + "\"
                   FileCount = FileEnum(sgetdirectory, File(), sFilter)
              END TRY
          
          
              REM returning to initial directory
              IF MID$(sCurrentdir,2,1)=":" THEN CHDRIVE MID$(sCurrentdir,1,1)
              CHDIR(sCurrentdir)
              FUNCTION=0
              IF giflagcount THEN STDOUT $CRLF+TRIM$(STR$(Filecount))+ " files found match "+sgetdirectory+sfilter
              REM if no files found
              IF Filecount=0& THEN STDOUT " ": FUNCTION=1
          
          END FUNCTION
          Last edited by Paul Purvis; 21 Dec 2007, 10:22 PM.
          p purvis

          Comment


          • #6
            An updated dirslist program.
            Basically the same code.
            Compiled in PBCC 6.03

            I added 2 more options
            /RAWNAME where it only list the file name. /RAW listed the directory with the filename
            /Wx where you can limit the listing to only filenames over a certain length

            I now also gives the sum total of the files sizes with the /COUNT AND /COUNTONLY options.

            Both source code and exe in zipped file.

            added
            If no files are found, then an ERRORLEVEL 1 is returned.
            You can use that ERRORLEVEL to create batch files like is shown at the pb forum location below.
            http://www.powerbasic.com/support/pb...d.php?p=412618
            Last edited by Paul Purvis; 31 Jul 2012, 01:58 AM.
            p purvis

            Comment


            • #7
              With the newer option to search for file names of x length long and to be less confusing by the average users.
              It was imperative that i lower the number of files with long file names.
              To do that i had to included some more options.
              The newest options are seen at the bottom of a listing when you put /? on the command tail.
              I tried to help the user or administrator in most cases, to exclude files in the windows system directory, hidden or system, directories, program files, program data, appdata directory(not the localappdata direectory), or all directories except the homepath directory of the user. I used the system/user environment to define those directories.
              I tested under vista because i had a easy access to a vista system and no easy access to a win 7 system.

              There may be a few kinks but i did my best for now to help you get a listing of long file names where the user is naming them or has some control over them. A Microsoft program had placed a few files names longer than 100 characters. Is that Microsoft programmer just pain dumb or what. There is just no reason in that and I can see a few other companies are not far behind Microsoft.

              Here is the new build and i deleted the previous one that i posted earlier.
              No options where dropped.
              Last edited by Paul Purvis; 1 Aug 2012, 07:20 PM.
              p purvis

              Comment


              • #8
                Made a correction in the program where the /RAWNAME option was causing a problem. All files where being displayed and none where filtered according to the options.

                The /HIDDEN and /SYSTEM options where not doing as i wanted with the new options /NOHIDDIR and /NOSYSDIR.
                Now you can get the hidden and/or system files if the files exist in a non hidden or system directory.

                There are some READONLY directory names and the program is treating them as normal directory names because I have found many of them are commonly used by a non administrator user, such as Favorites folder for Internet Explorer.

                I changed the option /READ to /READONLY to better match computer definitions. I am sorry if this has created any problems for anybody, as i did not want to change or remove any options.

                This should be the last version unless i had an error while typing in the code or see some other non desired effects with new computer systems.
                Attached Files
                Last edited by Paul Purvis; 2 Aug 2012, 08:33 PM.
                p purvis

                Comment


                • #9
                  seems this project will not end for me

                  some problems with spaces and quote marks in the directory/files filter used on the command line have been worked out

                  i placed code into abort with a ctrl-c
                  use the new command line parameter /NOBREAK to not allow a ctrl-c break and i added a new errorlevel code of 5 to the exit code

                  no "../" allowed in the directory names but a single "./" allowed for now
                  there are still likely issues with using .. and . in a directory name
                  i need to write a routine to handle these non specific directory names, that will have to be later

                  also the error for no drive was wrong and corrected

                  added a new parameter to allow only totaling of the file count /COUNTONLY
                  added in the size of the total files found when using /COUNT or /COUNTONLY

                  both /COUNT and /COUNTONLY add a line to the bottom listing
                  such as "||||| total bytes 1,823,088,718 in 149 files found X:\*.* |||||"
                  if you are sorting the listing after redirection , hopefully, this count line will always be at the top or bottom of a listing
                  something like this "dirslist /count *.bas | sort"
                  Attached Files
                  Last edited by Paul Purvis; 23 Aug 2012, 06:26 PM.
                  p purvis

                  Comment

                  Working...
                  X