SHELL

From QB64 Wiki
Revision as of 16:47, 22 September 2009 by imported>Clippy
Jump to navigation Jump to search

The SHELL statement allows a program to use OS commands.


Syntax: SHELL DOSCommand$


  • Commands are external DOS commands as strings enclosed in quotes or string variables.
  • Commands can be a mixture of STRINGs and string variables added together using the + concatenation operator.


Example: Function that returns the current program working path.


FUNCTION Path$ 'assign to a variable for later use in other folders!
SHELL "DIR *.BAS > DOS-DATA.INF" ' pipe all file & dir info into a text file
OPEN "DOS-DATA.INF" FOR INPUT AS #1
DO WHILE NOT EOF(1) ' just in case file is empty
LINE INPUT #1, line$ ' read each line of file
location = INSTR(1, line$, ":\") ' find the drive path notation
IF location THEN EXIT DO ' drive path notation found
LOOP
CLOSE #1
IF location THEN
line$ = MID$(line$, location - 1, LEN(line$) - location + 2)
Path$ = RTRIM$(line$) + "\" ' a QB useable directory path
ELSE : Path = "" ' returns zero length string if path not found
END IF
END FUNCTION


  • For a list of DOS commands see: MSDOS


See also: FILES, CHDIR, MKDIR, NAME, KILL


Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage