HIDE: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
Line 16: | Line 16: | ||
''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 (WindowsNT or above) in SCREEN 12: | ||
{{CodeStart}} | {{CodeStart}} | ||
SUB LFN | {{Cl|SCREEN}} {{Text|12|#F580B1}} | ||
{{Text|LFN|#55FF55}} | |||
{{Cl|END}} | |||
{{Cl|SUB}} {{Text|LFN|#55FF55}} | |||
{{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}} | |||
{{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}} | |||
{{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 | |||
{{Cl|IF}} {{Cl|LOF}}({{Text|1|#F580B1}}) {{Cl|THEN}} | |||
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}} | |||
tmp$ = {{Text|<nowiki>"\ \ \ \ &"</nowiki>|#FFB100}} {{Text|<nowiki>' print using template format</nowiki>|#919191}} | |||
{{Cl|COLOR}} {{Text|14|#F580B1}}: {{Cl|LOCATE}} {{Text|2|#F580B1}}, {{Text|4|#F580B1}}: {{Cl|PRINT}} Header$ | |||
{{Cl|DO...LOOP|DO UNTIL}} {{Cl|EOF}}({{Text|1|#F580B1}}) | |||
{{Cl|LINE INPUT (file statement)|LINE INPUT}} #1, line$ | |||
{{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}} | |||
cnt% = cnt% + {{Text|1|#F580B1}} | |||
last$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|1|#F580B1}}, {{Text|17|#F580B1}}): DIR$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|23|#F580B1}}, {{Text|3|#F580B1}}) | |||
{{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}} | |||
SHFN$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|37|#F580B1}}, {{Cl|INSTR}}({{Text|37|#F580B1}}, line$, {{Cl|SPACE$}}({{Text|1|#F580B1}})) - {{Text|1|#F580B1}}) | |||
LGFN$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|50|#F580B1}}) | |||
{{Cl|ELSE}}: SHFN$ = {{Cl|MID$ (function)|MID$}}(line$, {{Text|50|#F580B1}}): LGFN$ = {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|<nowiki>' found short name only</nowiki>|#919191}} | |||
{{Cl|END IF}} | |||
{{Cl|IF}} cnt% {{Cl|MOD}} {{Text|24|#F580B1}} = {{Text|0|#F580B1}} {{Cl|THEN}} {{Text|<nowiki>' pause every 24 files</nowiki>|#919191}} | |||
{{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|DO}}: {{Cl|_LIMIT}} {{Text|30|#F580B1}}: {{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} <> {{Text|<nowiki>""</nowiki>|#FFB100}} | |||
{{Cl|CLS}}: {{Cl|COLOR}} {{Text|14|#F580B1}}: {{Cl|LOCATE}} {{Text|2|#F580B1}}, {{Text|4|#F580B1}}: {{Cl|PRINT}} Header$ | |||
{{Cl|END IF}} | |||
{{Cl|COLOR}} {{Text|11|#F580B1}}: {{Cl|LOCATE}} (cnt% {{Cl|MOD}} {{Text|24|#F580B1}}) + {{Text|3|#F580B1}}, {{Text|4|#F580B1}} | |||
{{Cl|PRINT USING}} tmp$; DIR$; SHFN$; LGFN$ | |||
{{Cl|LOCATE}} (cnt% {{Cl|MOD}} {{Text|24|#F580B1}}) + {{Text|3|#F580B1}}, {{Text|58|#F580B1}}: {{Cl|PRINT}} last$ | |||
{{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}} | ||
Revision as of 23:01, 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 (WindowsNT or above) 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
- SHELL, _DONTWAIT
- FILELIST$ (function) (FILES function, member-contributed)