Using the DOS CD command to find the current path.

Joined: February 2nd, 2006, 10:38 pm

March 30th, 2010, 12:11 am #1

Use the DOS "CD" command and "pipe" the display info to a file:

SHELL "CD > DOS-INFO.inf"

OPEN "DOS-INFO.inf" FOR INPUT AS #1
IF LOF(1) THEN LINE INPUT #1, CurrentPath$
CLOSE #1

'This works in QB and QB64! QB64 returns long path names.
Quote
Like
Share

Joined: January 24th, 2014, 11:13 pm

January 24th, 2014, 11:31 pm #2

You may find it helpful to use DOS to find the path, but I use DOS to see if a data file exists. This relies on a few common variables I set beforehand:
I set direc$ as the data directory, i.e. "C:DATA", include the final .
temp$ would be the name of a temporary file, i.e. "TEMP.TMP"
I also set true and false as constants.
I would set ext$ as the extension of data files, i.e. "DAT" or maybe "HSC" if I am looking at a high score file.
Setting these as common variables, or constants I use the following function to check if a file exists.

So, setting all as constants I would say
CONST false = 0, true = NOT false
CONST direc$="C:DATA", ext$="HSC", temp$="TEMP.TMP"

FUNCTION filefound
CLOSE : OPEN direc$ + temp$ FOR OUTPUT AS #1: PRINT #1, "NOTHINGHERE!": CLOSE
SHELL "if exist " + direc$ + "*.* dir " + direc$ + "*.* > " + direc$ + temp$
OPEN direc$ + temp$ FOR INPUT AS #1: found = false
IF EOF(1) <> 0 THEN GOTO endfilefound
DO: INPUT #1, a$
IF LEFT$(a$, LEN(hifile$) + 1) = hifile$ + " " AND INSTR(a$, " " + ext$ + " ") > 0 THEN found = true
LOOP UNTIL EOF(1) <> 0
endfilefound:
CLOSE : KILL direc$ + temp$
filefound = found
END FUNCTION

I can extend this and use error handling to change direc$ if the folder doesn't exist.
This works in QB but not in QB64 as QB64 does not support ON LOCAL ERROR

This function is taken from a monopoly game I wrote in QB. In this case direc$ is a common variable, not a constant as it can be changed by the program. I also used two types of file exension, signfified as extd$ and extg$, and the 'x' varieable determined which applied.

FUNCTION filefound (f$, x)
IF x = 1 THEN e$ = extg$ ELSE e$ = extd$
ON LOCAL ERROR GOTO errorhandling
CLOSE : OPEN direc$ + temp1$ FOR OUTPUT AS #1: PRINT #1, "NOTHINGHERE!": CLOSE
SHELL "if exist " + direc$ + "*.* dir " + direc$ + "*.* > " + direc$ + temp1$
OPEN direc$ + temp1$ FOR INPUT AS #1: found = false
IF EOF(1) <> 0 THEN GOTO endfilefound
DO: INPUT #1, a$
IF LEFT$(a$, LEN(f$) + 1) = f$ + " " AND INSTR(a$, " " + e$ + " ") > 0 THEN found = true
LOOP UNTIL EOF(1) <> 0: GOTO endfilefound

errorhandling:
direc$ = "C:"
COLOR 13: PRINT : PRINT "DATA DIRECTORY NOT FOUND - CHANGED TO " + CHR$(34) + direc$ + CHR$(34)
RESUME 0

endfilefound:
CLOSE : KILL direc$ + temp1$
filefound = found
END FUNCTION
Quote
Like
Share

JT
JT

July 9th, 2014, 7:30 pm #3

There is a way to check for existing files within QB64 that is super easy
the function _FILEEXISTS()
Look it it, its super!
Quote
Share

Joined: June 1st, 2014, 12:21 pm

September 22nd, 2014, 5:00 am #4

Use the DOS "CD" command and "pipe" the display info to a file:

SHELL "CD > DOS-INFO.inf"

OPEN "DOS-INFO.inf" FOR INPUT AS #1
IF LOF(1) THEN LINE INPUT #1, CurrentPath$
CLOSE #1

'This works in QB and QB64! QB64 returns long path names.
It's much easier than messing around with temporary files, and it's cross-platform too.
Quote
Like
Share