HIDE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:


{{PageExamples}}
{{PageExamples}}
''Example:'' Subprogram that displays long and short filenames using the DIR /X option (WindowsNT or above) in SCREEN 12:
''Example:'' Subprogram that displays long and short filenames using the DIR /X option in SCREEN 12:
{{CodeStart}}
{{CodeStart}}
SUB LFN
{{Cl|SCREEN}} {{Text|12|#F580B1}}
IF LEN({{Cl|ENVIRON$}}("OS")) = 0 THEN EXIT SUB   ' /X not available Win 9X and ME
{{Text|LFN|#55FF55}}
SHELL {{Cl|_HIDE}} "cmd /c dir /x > DOS-DATA.INF" ' load display data to a file
{{Cl|END}}
OPEN "DOS-DATA.INF" FOR INPUT AS #1
 
IF {{Cl|LOF}}(1) THEN
{{Cl|SUB}} {{Text|LFN|#55FF55}}
  Header$ = SPACE$(10) + "Short" + SPACE$(16) + "Long" + SPACE$(20) + "Last Modified"
    {{Cl|IF}} {{Cl|LEN}}({{Cl|ENVIRON$}}({{Text|<nowiki>"OS"</nowiki>|#FFB100}})) = {{Text|0|#F580B1}} {{Cl|THEN}} {{Cl|EXIT SUB}} {{Text|<nowiki>' /X not available Win 9X and ME</nowiki>|#919191}}
  tmp$ = "\  \  \          \      &" ' print using template format
    {{Cl|SHELL}} {{Cl|_HIDE}} {{Text|<nowiki>"cmd /c dir /x > DOS-DATA.INF"</nowiki>|#FFB100}} {{Text|<nowiki>' load display data to a file</nowiki>|#919191}}
  COLOR 14: LOCATE 2, 4: PRINT Header$
    {{Cl|OPEN}} {{Text|<nowiki>"DOS-DATA.INF"</nowiki>|#FFB100}} {{Cl|OPEN#File_Access_Modes|FOR}} {{Cl|OPEN#File_Access_Modes|INPUT}} {{Cl|OPEN|AS}} #1
  DO UNTIL EOF(1)
    {{Cl|IF}} {{Cl|LOF}}({{Text|1|#F580B1}}) {{Cl|THEN}}
    {{Cl|LINE INPUT}} #1, line$
        Header$ = {{Cl|SPACE$}}({{Text|10|#F580B1}}) + {{Text|<nowiki>"Short"</nowiki>|#FFB100}} + {{Cl|SPACE$}}({{Text|16|#F580B1}}) + {{Text|<nowiki>"Long"</nowiki>|#FFB100}} + {{Cl|SPACE$}}({{Text|20|#F580B1}}) + {{Text|<nowiki>"Last Modified"</nowiki>|#FFB100}}
    IF LEN(line$) AND MID$(line$, 1, 1) <> SPACE$(1) THEN ' ignore other file data
        tmp$ = {{Text|<nowiki>"\  \  \          \      &"</nowiki>|#FFB100}} {{Text|<nowiki>' print using template format</nowiki>|#919191}}
      cnt% = cnt% + 1
        {{Cl|COLOR}} {{Text|14|#F580B1}}: {{Cl|LOCATE}} {{Text|2|#F580B1}}, {{Text|4|#F580B1}}: {{Cl|PRINT}} Header$
      last$ = MID$(line$, 1, 20): DIR$ = MID$(line$, 26, 3)
        {{Cl|DO...LOOP|DO UNTIL}} {{Cl|EOF}}({{Text|1|#F580B1}})
      IF MID$(line$, 40, 1) <> SPACE$(1) THEN ' found line with short and long name
            {{Cl|LINE INPUT (file statement)|LINE INPUT}} #1, line$
        SHFN$ = MID$(line$, 40, INSTR(40, line$, SPACE$(1)) - 1)
            {{Cl|IF}} {{Cl|LEN}}(line$) {{Cl|AND (boolean)|AND}} {{Cl|MID$ (function)|MID$}}(line$, {{Text|1|#F580B1}}, {{Text|1|#F580B1}}) <> {{Cl|SPACE$}}({{Text|1|#F580B1}}) {{Cl|THEN}} {{Text|<nowiki>' ignore other file data</nowiki>|#919191}}
        LGFN$ = MID$(line$, 53)
                cnt% = cnt% + {{Text|1|#F580B1}}
      ELSE : SHFN$ = MID$(line$, 53): LGFN$ = "" ' found short name only
                last$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|1|#F580B1}}, {{Text|17|#F580B1}}): DIR$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|23|#F580B1}}, {{Text|3|#F580B1}})
      END IF
                {{Cl|IF}} {{Cl|MID$ (function)|MID$}}(line$, {{Text|37|#F580B1}}, {{Text|1|#F580B1}}) <> {{Cl|SPACE$}}({{Text|1|#F580B1}}) {{Cl|THEN}} {{Text|<nowiki>' found line with short and long name</nowiki>|#919191}}
      IF cnt% MOD 25 = 0 THEN ' pause every 25 files
                    SHFN$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|37|#F580B1}}, {{Cl|INSTR}}({{Text|37|#F580B1}}, line$, {{Cl|SPACE$}}({{Text|1|#F580B1}})) - {{Text|1|#F580B1}})
        COLOR 14: LOCATE 29, 27 "Press a key for more files!"
                    LGFN$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|50|#F580B1}})
        DO: LOOP UNTIL INKEY$ <> ""
                {{Cl|ELSE}}: SHFN$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|50|#F580B1}}): LGFN$ = {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|<nowiki>' found short name only</nowiki>|#919191}}
        CLS: COLOR 14: LOCATE 2, 4: PRINT Header$
                {{Cl|END IF}}
      END IF
                {{Cl|IF}} cnt% {{Cl|MOD}} {{Text|24|#F580B1}} = {{Text|0|#F580B1}} {{Cl|THEN}} {{Text|<nowiki>' pause every 24 files</nowiki>|#919191}}
      COLOR 11: LOCATE (cnt% MOD 25) + 3, 4
                    {{Cl|COLOR}} {{Text|14|#F580B1}}: {{Cl|LOCATE}} {{Text|28|#F580B1}}, {{Text|27|#F580B1}}: {{Cl|PRINT}} {{Text|<nowiki>"Press a key for more files!"</nowiki>|#FFB100}}
      {{Cl|PRINT USING}} tmp$; DIR$; SHFN$; LGFN$
                    {{Cl|DO}}: {{Cl|_LIMIT}} {{Text|30|#F580B1}}: {{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} <> {{Text|<nowiki>""</nowiki>|#FFB100}}
      LOCATE (cnt% MOD 25) + 3, 58: PRINT last$
                    {{Cl|CLS}}: {{Cl|COLOR}} {{Text|14|#F580B1}}: {{Cl|LOCATE}} {{Text|2|#F580B1}}, {{Text|4|#F580B1}}: {{Cl|PRINT}} Header$
    END IF
                {{Cl|END IF}}
  LOOP
                {{Cl|COLOR}} {{Text|11|#F580B1}}: {{Cl|LOCATE}} (cnt% {{Cl|MOD}} {{Text|24|#F580B1}}) + {{Text|3|#F580B1}}, {{Text|4|#F580B1}}
END IF
                {{Cl|PRINT USING}} tmp$; DIR$; SHFN$; LGFN$
COLOR 10: LOCATE {{Cl|CSRLIN}} + 1, 27 "Total folders and files ="; cnt%
                {{Cl|LOCATE}} (cnt% {{Cl|MOD}} {{Text|24|#F580B1}}) + {{Text|3|#F580B1}}, {{Text|58|#F580B1}}: {{Cl|PRINT}} last$
CLOSE #1
            {{Cl|END IF}}
END SUB
        {{Cl|LOOP}}
    {{Cl|END IF}}
    {{Cl|COLOR}} {{Text|10|#F580B1}}: {{Cl|LOCATE}} {{Cl|CSRLIN}} + {{Text|1|#F580B1}}, {{Text|27|#F580B1}}: {{Cl|PRINT}} {{Text|<nowiki>"Total folders and files ="</nowiki>|#FFB100}}; cnt%
    {{Cl|CLOSE}} #1
{{Cl|END SUB}}
{{CodeEnd}}
{{CodeEnd}}



Latest revision as of 23:02, 29 March 2023

The _HIDE action is used to hide the console window opened by a SHELL statement.


Syntax

SHELL [_HIDE] StringCommandLine$


Description

  • Allows any command line window to be hidden from view without affecting the program.
  • _HIDE must be used when sending ("piping") screen information to a file.
  • Note: Some commands may not work without adding CMD /C to the start of the command line.


Examples

Example: Subprogram that displays long and short filenames using the DIR /X option in SCREEN 12:

SCREEN 12
LFN
END

SUB LFN
    IF LEN(ENVIRON$("OS")) = 0 THEN EXIT SUB ' /X not available Win 9X and ME
    SHELL _HIDE "cmd /c dir /x > DOS-DATA.INF" ' load display data to a file
    OPEN "DOS-DATA.INF" FOR INPUT AS #1
    IF LOF(1) THEN
        Header$ = SPACE$(10) + "Short" + SPACE$(16) + "Long" + SPACE$(20) + "Last Modified"
        tmp$ = "\   \  \          \      &" ' print using template format
        COLOR 14: LOCATE 2, 4: PRINT Header$
        DO UNTIL EOF(1)
            LINE INPUT #1, line$
            IF LEN(line$) AND MID$(line$, 1, 1) <> SPACE$(1) THEN ' ignore other file data
                cnt% = cnt% + 1
                last$ = MID$(line$, 1, 17): DIR$ = MID$(line$, 23, 3)
                IF MID$(line$, 37, 1) <> SPACE$(1) THEN ' found line with short and long name
                    SHFN$ = MID$(line$, 37, INSTR(37, line$, SPACE$(1)) - 1)
                    LGFN$ = MID$(line$, 50)
                ELSE: SHFN$ = MID$(line$, 50): LGFN$ = "" ' found short name only
                END IF
                IF cnt% MOD 24 = 0 THEN ' pause every 24 files
                    COLOR 14: LOCATE 28, 27: PRINT "Press a key for more files!"
                    DO: _LIMIT 30: LOOP UNTIL INKEY$ <> ""
                    CLS: COLOR 14: LOCATE 2, 4: PRINT Header$
                END IF
                COLOR 11: LOCATE (cnt% MOD 24) + 3, 4
                PRINT USING tmp$; DIR$; SHFN$; LGFN$
                LOCATE (cnt% MOD 24) + 3, 58: PRINT last$
            END IF
        LOOP
    END IF
    COLOR 10: LOCATE CSRLIN + 1, 27: PRINT "Total folders and files ="; cnt%
    CLOSE #1
END SUB

Explanation: The above routine can also be used to place the file name info into string arrays by using the count variable cnt% to determine the index. Long file names are normally returned by QB64. To keep older QBasic programs compatible, you may want to only use the short names when displaying the files on the screen.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link