Difference between pages "FILE$ (function)" and "FILEEXISTS"

From QB64 Wiki
(Difference between pages)
Jump to navigation Jump to search
imported>Clippy
m
 
imported>Clippy
m
 
Line 1: Line 1:
The '''FILE$''' function can be used in place of the old Qbasic [[FILES]] statement to view a list of files. Displays long and short(8.3) DOS filenames with the last modified information. Function name returns the short filename while '''SHARED''' string variables '''LFN$''' and '''Path$''' return the long name and absolute path from the current root drive. The leading underscore should make it compatible with most older Qbasic program code run in '''QB64'''. The function allows mouse click file selection, letter press searches, file name exist verification without a screen display, and many of the DIR options available in DOS. Including sorting by name, extension, attributes and more! '''Your program screens are not changed after a display and the function can be integrated into a program using Putimage!'''
+
{{DISPLAYTITLE:_FILEEXISTS}}
 +
The '''_FILEEXISTS''' function determines if a designated file name exists and returns True or False.
  
{{WhiteStart}}                            '''FILE$ Function Features'''
 
  
        1) Only displays a file list when necessary. Otherwise one or no files found
+
{{PageSyntax}}
          work "silently". Can be used to check if a file exists without an error!
 
  
        2) Completely restores the program screen after a file list display! It is
+
::: IF _FILEEXISTS(''filename$'') THEN
          not necessary to create a new screen like you did after FILES. See Demo.
 
  
        3) Users can jump to the leading filename letter by pressing a letter key.
 
  
        4) Selection of files is done by a mouse click anywhere on a filename row.
+
* The ''filename'' parameter can be a literal or variable [[STRING|string]] value that can include a path.
          Clicking near the bottom or keypress can advance to the next page list.
+
* The function returns -1 when a file exists and 0 when it does not.
         
+
* The function reads the system information directly without using a [[SHELL]] procedure.
        5) Does not require '''*.*'''! Press Enter to display all files in current folder.
+
* The function can use the appropriate Operating System path separators. [[_OS$]] can determine the operating system.
          No program typing errors! Just press Enter after a valid path for list!
+
* '''This function does not guarantee that a file can be accessed or opened'''
  
        6) If it doesn't find a file, it returns a 0 length string. '''NO FILE ERRORS!'''
 
          Just check for empty or zero length string returns in your program.
 
  
        7) Includes various filename options for sorting as described below the code.
+
''See also:''
 
+
* [[_DIREXISTS]]
        8) To view the current sub-directories, use Spec$ = '''"/A:D"''' in any lettercase.
+
* [[SHELL]]
     
+
* [[_OS$]]
        9) Update: Display now '''highlights''' the mouse selection rows for clarity. Also
 
          Displays the present search path. Option '''/S''' will search all sub-directories.
 
          The file's actual '''Path$''' will be returned even if it was not displayed!
 
 
 
      10) The newest version sets up the entire process using two position parameters
 
          so that it can be viewed on your program screen area. See '''[[FILE$]]'''
 
{{WhiteEnd}}
 
 
 
<center>'''[http://i301.photobucket.com/albums/nn53/burger2227/FILE-ss2.jpg Screenshot]'''</center>
 
 
 
'''The function is NOT a QB64 authorized function!''' This program code is free to use in your programs! No claims are made as to the suitability of the code and the user is responsible for any damages. You are free to alter the code as you see fit.
 
 
 
<center>'''NOTE: IF [[$STATIC]] Metacommand is required, change function Arrays to [[STATIC]] and [[ERASE]] them at start and every loop!'''</center>
 
 
 
{{CodeStart}} '' ''
 
{{Cl|_TITLE}} "Demo of FILELIST$ Function by Ted Weissgerber 2010"
 
handle& = {{Cl|_NEWIMAGE}}(800, 600, 256) 'Demo code creates custom sized screen mode
 
{{Cl|SCREEN (statement)|SCREEN}} handle&
 
Align 15, 2, "SUPER " + QQ$("FILELIST$") + " SEARCH"
 
Align 10, 5, "The FILELIST$ function locates files from any input. Enter or " + QQ$("") + " same as " + QQ$("*.*")
 
Align 10, 6, "Shared variables Path$ and LFN$ return path and long name if available."
 
DO
 
  {{Cl|LOCATE}} 10, 20: {{Cl|PRINT}} {{Cl|SPACE$}}(70) 'entry below can enclose file names in quotes
 
  LINEPUT 14, 10, "Enter a filename Search spec: ", spec$
 
  {{Cl|IF...THEN|IF}} {{Cl|UCASE$}}(spec$) = "{{Cl|END}}" {{Cl|THEN}} {{Cl|EXIT DO}}
 
  filename$ = FILELIST$(spec$)
 
  {{Cl|LOCATE}} 13, 20: {{Cl|PRINT}} {{Cl|SPACE$}}(70)
 
  Align 11, 13, filename$
 
  {{Cl|LOCATE}} 15, 1: {{Cl|PRINT}} {{Cl|SPACE$}}(90)
 
  Align 15, 15, Path$ + spec$
 
  Align 10, 17, "Note that your " + QQ$("spec$") + " also returns the selected file name."
 
  {{Cl|LOCATE}} 20, 20: {{Cl|PRINT}} {{Cl|SPACE$}}(50)
 
  Align 13, 20, "LFN$ = " + LFN$ + " {{Cl|LEN}} =" + {{Cl|STR$}}({{Cl|LEN}}(LFN$))
 
  Align 11, 23, "Enter " + QQ$("{{Cl|END}}") + " to quit"
 
{{Cl|LOOP}}
 
{{Cl|SYSTEM}}
 
'----------------------------- End of Demo Code -------------------------------
 
 
 
{{Cl|SUB}} Align (c0l0r%, Tr0w%, t3xt$) 'auto centers printed text
 
Tc0l% = ({{Cl|_WIDTH (function)|_WIDTH}} \ 16) + 1 - ({{Cl|LEN}}(t3xt$) \ 2)
 
{{Cl|IF...THEN|IF}} Tc0l% <= 0 {{Cl|THEN}} Tc0l% = 2
 
{{Cl|COLOR}} c0l0r%: {{Cl|LOCATE}} Tr0w%, Tc0l%: {{Cl|PRINT}} t3xt$;
 
{{Cl|END SUB}}
 
 
 
{{Cl|SUB}} LINEPUT (c0l0r%, Tr0w%, t3xt$, r3turn$)
 
'Auto centering {{Cl|LINE INPUT}} entry allows quotation marks around filenames with spaces
 
Tc0l% = (({{Cl|_WIDTH (function)|_WIDTH}} \ 16) - 10) - ({{Cl|LEN}}(t3xt$) \ 2)
 
{{Cl|IF...THEN|IF}} Tc0l% <= 0 {{Cl|THEN}} Tc0l% = 2
 
{{Cl|COLOR}} c0l0r%: {{Cl|LOCATE}} Tr0w%, Tc0l%: {{Cl|PRINT}} t3xt$;
 
{{Cl|LINE INPUT}} ; "", r3turn$ 'semicolon in case bottom 2 rows
 
{{Cl|END SUB}}
 
 
 
{{Cl|FUNCTION}} QQ$ (t3xt$) 'Quote unQuote text in quotes
 
QQ$ = {{Cl|CHR$}}(34) + t3xt$ + {{Cl|CHR$}}(34)
 
{{Cl|END FUNCTION}}
 
 
 
 
 
' >>>>>>>>> Place INCLUDE file reference here when used as library <<<<<<<<<
 
 
 
{{CodeEnd}}
 
{{TextStart}}
 
'****** NOTE: FILELIST$ Function can also be included as an external library(see below) ******
 
 
 
{{Cb|FUNCTION}} FILELIST$ (Spec$)
 
{{Cb|SHARED}} Path$, LFN$ 'values also accessable by main program
 
{{Cb|REDIM}} LGFN$(25), SHFN$(25), Last$(25), DIR$(25), Paths$(25) '<<< {{Cb|$DYNAMIC}} only
 
{{Cb|IF...THEN|IF}} {{Cb|LEN}}({{Cb|ENVIRON$}}("OS")) = 0 {{Cb|THEN}} {{Cb|EXIT FUNCTION}} 'DIR X cannot be used on Win 9X
 
f% = {{Cb|FREEFILE}}
 
{{Cb|SHELL}} {{Cb|_HIDE}} "CD > D0S-DATA.INF" '********************** Optional TITLE <<<<<<<<<<
 
{{Cb|OPEN}} "D0S-DATA.INF" {{Cb|FOR (file statement)|FOR}} {{Cb|INPUT (file mode)|INPUT}} {{Cb|AS}} #f%
 
{{Cb|LINE INPUT (file statement)|LINE INPUT}} #f%, current$
 
{{Cb|CLOSE}} #f% ' ******************************************** {{Cb|END}} TITLE(see {{Cb|_TITLE}} below)
 
Spec$ = {{Cb|UCASE$}}({{Cb|LTRIM$}}({{Cb|RTRIM$}}(Spec$)))
 
{{Cb|IF...THEN|IF}} {{Cb|INSTR}}(Spec$, "/A:D") {{Cb|OR (boolean)|OR}} {{Cb|INSTR}}(Spec$, "/O:G") {{Cb|THEN}}
 
  DL$ = "DIR": BS$ = "\" 'directory searches only
 
{{Cb|ELSE}}: DL$ = {{Cb|SPACE$}}(3): BS$ = ""
 
{{Cb|END IF}}
 
mode& = {{Cb|_COPYIMAGE}}(0) 'save previous screen value to restore if files displayed.
 
' Get Specific file information if available
 
{{Cb|SHELL}} {{Cb|_HIDE}} "cmd /c dir " + Spec$ + " /X > D0S-DATA.INF" 'get data
 
Head$ = "      Short Name          Long Name                    Last Modified    "
 
tmp$ = " \ \  \          \  \                              \ \                  \"
 
{{Cb|OPEN}} "D0S-DATA.INF" {{Cb|FOR (file statement)|FOR}} {{Cb|INPUT (file mode)|INPUT}} {{Cb|AS}} #f% 'read the data file
 
{{Cb|DO...LOOP|DO}} {{Cb|UNTIL}} {{Cb|EOF}}(f%)
 
  {{Cb|LINE INPUT (file statement)|LINE INPUT}} #f%, line$
 
  {{Cb|IF...THEN|IF}} {{Cb|INSTR}}(line$, ":\") {{Cb|THEN}}
 
    Path$ = {{Cb|MID$}}(line$, {{Cb|INSTR}}(line$, ":\") - 1)
 
    {{Cb|IF...THEN|IF}} {{Cb|RIGHT$}}(Path$, 1) <> "\" {{Cb|THEN}} Path$ = Path$ + "\"
 
    setcode% = 0: filecode% = 0
 
  {{Cb|END IF}}
 
  {{Cb|IF...THEN|IF}} {{Cb|LEN}}(line$) > 25 {{Cb|AND (boolean)|AND}} {{Cb|MID$}}(line$, 1, 1) <> " " {{Cb|THEN}} 'don't read other info
 
    {{Cb|IF...THEN|IF}} format% = 0 {{Cb|THEN}}
 
      {{Cb|IF...THEN|IF}} {{Cb|MID$}}(line$, 20, 1) = "M" {{Cb|OR (boolean)|OR}} {{Cb|INSTR}}(line$, "<") = 25 {{Cb|THEN}}
 
        Sst% = 40: Lst% = 53: Dst% = 26: format% = 1 ' XP
 
      {{Cb|ELSE}}: Sst% = 37: Lst% = 50: Dst% = 23: format% = 2 'VISTA
 
      {{Cb|END IF}}
 
    {{Cb|END IF}}
 
    {{Cb|IF...THEN|IF}} {{Cb|LEN}}(line$) >= Lst% {{Cb|THEN}} filecode% = {{Cb|ASC}}({{Cb|UCASE$}}({{Cb|MID$}}(line$, Lst%, 1))) {{Cb|ELSE}} filecode% = 0
 
    D1R$ = {{Cb|MID$}}(line$, Dst%, 3) 'returns directories only with Spec$ = "/A:D" or "/O:G"
 
    {{Cb|IF...THEN|IF}} D1R$ <> "DIR" {{Cb|THEN}} D1R$ = {{Cb|SPACE$}}(3) 'change if anything else
 
    {{Cb|IF...THEN|IF}} D1R$ = DL$ {{Cb|AND (boolean)|AND}} filecode% >= setcode% {{Cb|THEN}}
 
      cnt% = cnt% + 1
 
      DIR$(cnt%) = D1R$: Paths$(cnt%) = Path$
 
      Last$(cnt%) = {{Cb|MID$}}(line$, 1, 20)
 
      {{Cb|IF...THEN|IF}} {{Cb|MID$}}(line$, Sst%, 1) <> {{Cb|SPACE$}}(1) {{Cb|THEN}}
 
        SHFN$(cnt%) = {{Cb|MID$}}(line$, Sst%, {{Cb|INSTR}}(Sst%, line$, " ") - Sst%)
 
        LGFN$(cnt%) = {{Cb|MID$}}(line$, Lst%)
 
      {{Cb|ELSE}}: SHFN$(cnt%) = {{Cb|MID$}}(line$, Lst%): LGFN$(cnt%) = ""
 
      {{Cb|END IF}}
 
      {{Cb|IF...THEN|IF}} {{Cb|LEN}}(Spec$) {{Cb|AND (boolean)|AND}} (Spec$ = {{Cb|UCASE$}}(SHFN$(cnt%)) {{Cb|OR (boolean)|OR}} Spec$ = {{Cb|UCASE$}}(LGFN$(cnt%))) {{Cb|THEN}}
 
        Spec$ = SHFN$(cnt%) + BS$: FILELIST$ = Spec$: LFN$ = LGFN$(cnt%) + BS$
 
        {{Cb|GOSUB}} {{Cb|KILL}}data ' verifies file exist query (no display)
 
      {{Cb|END IF}}
 
      {{Cb|IF...THEN|IF}} page% > 0 {{Cb|THEN}} ' pages after first
 
        {{Cb|IF...THEN|IF}} cnt% = 1 {{Cb|THEN}} {{Cb|GOSUB}} NewScreen
 
        {{Cb|COLOR}} 11: {{Cb|LOCATE}} , 3: {{Cb|PRINT USING}} tmp$; DIR$(cnt%); SHFN$(cnt%); LGFN$(cnt%); Last$(cnt%)
 
        {{Cb|IF...THEN|IF}} DIR$(cnt%) = "DIR" {{Cb|AND (boolean)|AND}} {{Cb|LEFT$}}(SHFN$(cnt%), 1) = "." {{Cb|THEN}} SHFN$(cnt%) = "": LGFN$(cnt%) = ""
 
      {{Cb|ELSE}} 'first page = 0
 
        {{Cb|IF...THEN|IF}} cnt% = 2 {{Cb|THEN}} 'only display to screen if 2 or more files are found
 
          FList& = {{Cb|_NEWIMAGE}}(640, 480, 256)
 
          {{Cb|SCREEN (statement)|SCREEN}} FList&: {{Cb|_TITLE}} current$: {{Cb|GOSUB}} NewScreen '********* Optional TITLE <<<<<<<
 
          {{Cb|COLOR}} 11: {{Cb|LOCATE}} , 3: {{Cb|PRINT USING}} tmp$; DIR$(1); SHFN$(1); LGFN$(1); Last$(1)
 
          {{Cb|_DISPLAY}}
 
          {{Cb|IF...THEN|IF}} DIR$(1) = "DIR" {{Cb|AND (boolean)|AND}} {{Cb|LEFT$}}(SHFN$(1), 1) = "." {{Cb|THEN}} SHFN$(1) = "": LGFN$(1) = ""
 
        {{Cb|END IF}}
 
        {{Cb|IF...THEN|IF}} cnt% > 1 {{Cb|THEN}}
 
          {{Cb|COLOR}} 11: {{Cb|LOCATE}} , 3: {{Cb|PRINT USING}} tmp$; DIR$(cnt%); SHFN$(cnt%); LGFN$(cnt%); Last$(cnt%)
 
          {{Cb|IF...THEN|IF}} DIR$(cnt%) = "DIR" {{Cb|AND (boolean)|AND}} {{Cb|LEFT$}}(SHFN$(cnt%), 1) = "." {{Cb|THEN}} SHFN$(cnt%) = "": LGFN$(cnt%) = ""
 
        {{Cb|END IF}}
 
      {{Cb|END IF}} 'page%
 
      {{Cb|IF...THEN|IF}} cnt% {{Cb|MOD}} 25 = 0 {{Cb|THEN}} 'each page holds 25 file names
 
        {{Cb|COLOR}} 14: {{Cb|LOCATE}} 28, 24: {{Cb|PRINT}} "Select file or click here for next."; '<<<< Prompt text can be changed
 
        {{Cb|GOSUB}} pickfile
 
        page% = page% + 1: cnt% = 0
 
        {{Cb|REDIM}} LGFN$(25), SHFN$(25), Last$(25), DIR$(25), Paths$(25) '<<< {{Cb|$DYNAMIC}} only
 
      {{Cb|END IF}} 'mod  25
 
    {{Cb|END IF}} 'DIR = DL$
 
  {{Cb|END IF}} 'len line$ > 25
 
{{Cb|LOOP}}
 
{{Cb|CLOSE}} #f%
 
last = 1: total% = cnt% + (page% * 25)
 
{{Cb|IF...THEN|IF}} total% = 0 {{Cb|THEN}} FILELIST$ = "": Spec$ = "": LFN$ = "": {{Cb|GOSUB}} {{Cb|KILL}}data: 'no files(no display)
 
{{Cb|IF...THEN|IF}} total% = 1 {{Cb|THEN}}
 
  Spec$ = SHFN$(1) + BS$: FILELIST$ = Spec$: LFN$ = LGFN$(1) + BS$: {{Cb|GOSUB}} {{Cb|KILL}}data 'one file(no display)
 
{{Cb|END IF}}
 
{{Cb|IF...THEN|IF}} DL$ = {{Cb|SPACE$}}(3) {{Cb|THEN}}
 
  {{Cb|COLOR}} 10: {{Cb|LOCATE}} 28, 65: {{Cb|PRINT}} total%; "Files"
 
{{Cb|ELSE}}: {{Cb|COLOR}} 10: {{Cb|LOCATE}} 28, 65: {{Cb|PRINT}} total%; "Folders"
 
{{Cb|END IF}}
 
{{Cb|COLOR}} 14: {{Cb|LOCATE}} 28, 24: {{Cb|PRINT}} "Select file or click here to Exit. "; '<<< Prompt text can be changed
 
pickfile:
 
{{Cb|_DEST}} FList&
 
ShowPath$ = {{Cb|RIGHT$}}(Path$, 78)
 
{{Cb|COLOR}} 15: {{Cb|LOCATE}} 29, 41 - ({{Cb|LEN}}(ShowPath$) \ 2): {{Cb|PRINT}} ShowPath$;
 
{{Cb|_DISPLAY}}
 
DO: Key$ = {{Cb|UCASE$}}({{Cb|INKEY$}}): {{Cb|_LIMIT}} 30
 
  {{Cb|DO...LOOP|DO}} {{Cb|WHILE}} {{Cb|_MOUSEINPUT}}
 
    Tcol% = (({{Cb|_MOUSEX}} - xpos%) \ 8) + 1 'mouse column with Putimage offset
 
    Trow% = (({{Cb|_MOUSEY}} - ypos%) \ 16) + 1 'mouse row with offset
 
    Pick = {{Cb|_MOUSEBUTTON}}(1) ' get left button selection click
 
  {{Cb|LOOP}}
 
  {{Cb|IF...THEN|IF}} Trow% > 2 {{Cb|AND (boolean)|AND}} Trow% < cnt% + 3 {{Cb|AND (boolean)|AND}} Tcol% > 0 {{Cb|AND (boolean)|AND}} Tcol% < 80 {{Cb|THEN}} 'when mouse in area
 
    R% = Trow% - 2
 
    {{Cb|IF...THEN|IF}} P% = 0 {{Cb|OR (boolean)|OR}} P% > cnt% + 3 {{Cb|THEN}} P% = R%
 
    {{Cb|IF...THEN|IF}} P% = R% {{Cb|THEN}}
 
      {{Cb|COLOR}} 15: {{Cb|LOCATE}} R% + 2, 3: {{Cb|PRINT USING}} tmp$; DIR$(R%); SHFN$(R%); LGFN$(R%); Last$(R%)
 
    {{Cb|ELSE}}
 
      {{Cb|COLOR}} 11: {{Cb|LOCATE}} P% + 2, 3: {{Cb|PRINT USING}} tmp$; DIR$(P%); SHFN$(P%); LGFN$(P%); Last$(P%)
 
    {{Cb|END IF}}
 
    {{Cb|_DISPLAY}}
 
    P% = R%
 
    {{Cb|IF...THEN|IF}} Pick {{Cb|THEN}}
 
      Spec$ = SHFN$(R%)
 
      {{Cb|IF...THEN|IF}} {{Cb|LEN}}(Spec$) {{Cb|THEN}}
 
        {{Cb|COLOR}} 13: {{Cb|LOCATE}} R% + 2, 3: {{Cb|PRINT USING}} tmp$; DIR$(R%); SHFN$(R%); LGFN$(R%); Last$(R%)
 
        {{Cb|_DISPLAY}}
 
        Spec$ = Spec$ + BS$: FILELIST$ = Spec$: Path$ = Paths$(R%)
 
        {{Cb|IF...THEN|IF}} {{Cb|LEN}}(LGFN$(R%)) {{Cb|THEN}} LFN$ = LGFN$(R%) + BS$ {{Cb|ELSE}} LFN$ = ""
 
        {{Cb|_DELAY}} 1.5: {{Cb|CLS}}: {{Cb|SCREEN (statement)|SCREEN}} mode&: {{Cb|GOSUB}} {{Cb|KILL}}data 'exit if user selection
 
      {{Cb|END IF}}
 
    {{Cb|END IF}} 'len spec
 
  {{Cb|END IF}} 'pick
 
  {{Cb|IF...THEN|IF}} {{Cb|LEN}}(Key$) {{Cb|THEN}} usercode% = {{Cb|ASC}}(Key$) {{Cb|ELSE}} usercode% = 0
 
  {{Cb|IF...THEN|IF}} usercode% > setcode% {{Cb|THEN}} setcode% = usercode% 'user can press letter to jump to
 
  {{Cb|IF...THEN|IF}} Pick {{Cb|AND (boolean)|AND}} Trow% > 27 {{Cb|THEN}} {{Cb|EXIT DO}}
 
{{Cb|LOOP}} {{Cb|UNTIL}} {{Cb|LEN}}(Key$)
 
{{Cb|_DELAY}} .4 'adjust delay for page scroll speed
 
DO: Key$ = {{Cb|INKEY$}}: {{Cb|LOOP}} {{Cb|UNTIL}} Key$ = ""
 
{{Cb|IF...THEN|IF}} last = 0 {{Cb|THEN}} {{Cb|RETURN}} 'exit if file no more data
 
FILELIST$ = "": Spec$ = "": LFN$ = ""
 
{{Cb|CLS}}: {{Cb|SCREEN (statement)|SCREEN}} mode& 'resets program screen to previous condition
 
{{Cb|KILL}}data:
 
{{Cb|CLOSE}} #f%: {{Cb|KILL}} "D0S-DATA.INF" 'kill D0S-DATA.INF file and exit
 
{{Cb|IF...THEN|IF}} FList& < -1 {{Cb|THEN}} {{Cb|_FREEIMAGE}} FList&
 
{{Cb|IF...THEN|IF}} Show& < -1 {{Cb|THEN}} {{Cb|_FREEIMAGE}} Show&
 
{{Cb|_AUTODISPLAY}} 'reset default settings
 
{{Cb|EXIT FUNCTION}}
 
{{Cb|RETURN}}
 
NewScreen: 'clear screen and set display format
 
{{Cb|LINE}} (0, 0)-(639, 499), 0, BF
 
{{Cb|COLOR}} 14: {{Cb|LOCATE}} 2, 3: {{Cb|PRINT}} Head$
 
{{Cb|LINE}} (4, 4)-(636, 476), 13, B: {{Cb|LINE}} (5, 5)-(635, 475), 13, B
 
{{Cb|RETURN}}
 
{{Cb|END FUNCTION}} '' ''     
 
{{TextEnd}}
 
 
 
<center>'''Refresh browser if full code is not displayed!'''
 
 
 
 
 
Updated for VISTA screen format 8/20/2010.
 
 
 
Updated for programs using $DYNAMIC Metacommand 9/16/2010.
 
 
 
Added option for current path to TITLE bar 11/16/2010
 
 
 
'''[http://i301.photobucket.com/albums/nn53/burger2227/FILE-ss2.jpg Function Screenshot]'''</center>
 
 
 
 
 
<center>'''CREATING A FILE$ $INCLUDE LIBRARY'''</center>
 
 
 
<center>The Function can be also be added to any program as a text library by saving it as a text BI file!</center>
 
 
 
<center>Just [[$INCLUDE]] the BI text file (grey area above) at the end of your program AFTER the SUB procedures. </center>
 
 
 
<center>To create a '''BI''' file use Notepad or another text editor, copy code in grey area  and Save as '''ALL FILES''' using ''anyname.BI''</center>
 
 
 
<center>'''NOTE: Once the program is compiled, the BI file is no longer needed with the stand alone EXE program!</center>
 
 
 
 
 
{{WhiteStart}}
 
 
 
                    '''FILE$(Spec$) OPTIONS''' (/X already used!)
 
Syntax:
 
                       
 
FILE$([drive:][path][filename] [/A[[:]attrib]] [/L] [/O[[:]sortorder]] [/Q] [/T[[:]timefield]])
 
 
 
NOTE: When path is specified, that path is returned to the SHARED Path$ variable.
 
 
 
              The FILE$ function can use the following options:
 
 
 
            '''/A''' List by attribute. Syntax: /A:attribute
 
                      :D Directories (use /A:D after any path or by itself)
 
                      :R Read-only files
 
                      :H Hidden files
 
                      :A Files ready for archiving
 
                      :S System files
 
                    - Prefix means not
 
 
 
            '''/L''' Use lowercase.
 
 
 
            '''/O''' List of files in sorted order. Syntax: /O:sortorder
 
                      :N By name (alphabetical is default)
 
                      :S By size (smallest first)
 
                      :E By extension (alphabetical)
 
                      :D By date/time (oldest first)
 
                      :G Group directories only (/O:G)
 
                      - Prefix to reverse order
 
 
 
            NOTE: Alphabetical keypress is disabled when using /O.
 
 
 
            '''/S''' Searches all directory and subdirectory files
 
 
 
            '''/T''' Time field displayed or used for sorting. Syntax: /T:timefield       
 
                      :A Last Access
 
                      :C Creation
 
                      :W Last Written
 
 
 
  DIR commands that don't work: /B, /C, /D, /N, /P, /Q, and /W. (/X already used)
 
           
 
              These options return nothing or do not change a search!
 
 
 
    '''To Search filenames with spaces, add CHR$(34) quote to each side of the spec file name!'''
 
 
 
                      file$ = FILE(CHR$(34) + Spec$ + CHR$(34))
 
 
 
 
 
'''NOTE: [[LINE INPUT]] allows quoted entries such as: "free cell.ico" for filenames with spaces.'''
 
{{WhiteEnd}}
 
 
 
 
 
<center>'''FILE$ Function can also be displayed on your program screen with Putimage!'''</center>
 
<center>First use Flist& as the source in: _PUTIMAGE , Flist&, newimagepage&</center>
 
<center>Then Putimage again at a position on screen larger than 640 X 480 to display</center>
 
<center> _DEST main&: _PUTIMAGE (x, y), newimagepage& </center>
 
<center>Where DEST main& is the main program screen. Add the code to the function.</center>
 
<center>'''Refresh the screen using the above format in both _DISPLAY instances.'''</center>
 
 
 
 
<center>'''[[FILE$| NEW Expanded Version of FILE$ sets a Program Screen or separate Window up Automatically!]]'''</center>
 
 
 
 
 
:''NOTE:'' The data file name "D0S-DATA.INF" uses a zero instead of an "O" in D0S and is deleted after a search!
 
 
 
 
 
''See also:
 
 
 
[[FILES]], [[SHELL]]
 
 
 
[[_HIDE]], [[_COPYIMAGE]], [[_PUTIMAGE]]
 
 
 
[[$INCLUDE]] ([[Metacommand]])
 
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Revision as of 23:59, 8 August 2013

The _FILEEXISTS function determines if a designated file name exists and returns True or False.


Syntax

IF _FILEEXISTS(filename$) THEN


  • The filename parameter can be a literal or variable string value that can include a path.
  • The function returns -1 when a file exists and 0 when it does not.
  • The function reads the system information directly without using a SHELL procedure.
  • The function can use the appropriate Operating System path separators. _OS$ can determine the operating system.
  • This function does not guarantee that a file can be accessed or opened


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page