|
Post by leu4life on Oct 9, 2007 23:01:35 GMT
I'm writin' a program which used to be a: drive but it will be on a cd rom instead but unlike a: drive you never know what letter the cd rom will be. What would i use like a variable, which could be used in front of the file i needed instead of a:\autoexec.bat it would be variable\autoexec.bat. but i'm not sure what that would be. thanks in advance
|
|
|
Post by Ildûrest on Oct 9, 2007 23:21:50 GMT
This is not easy to do. Actually with QuickBasic 7.1 (aka PDS) there is a CURDIR$ variable that should contain the drive letter. But with earlier QuickBasic versions and with QBasic this isn't available. Your options would then include parsing the output of DIR, or using some DOS interrupts.
So it's possible, but you wouldn't do it unnecessarily. Which begs the question, do you really need it? If this program is, for instance, on your CD drive under the root directory, and wants to open or run autoexec.bat in the same directory, all it needs to use is "autoexec.bat".
Even if the program is on D:\programs\whatever.exe and wants to open D:\data\datafile.dat, it will suffice to use "..\data\datafile.dat".
If that doesn't help, explain the problem in a bit more detail and we'll see if there's a simple way of solving it. And if not we'll solve it in whatever way we can.
|
|
|
Post by leu4life on Oct 9, 2007 23:56:52 GMT
well the funny thing is that everything that is going to be on the cd is in a folder called programs but there are multiple directories and subdirectories within that main programs directory. At first I was tryin //programs/d330/biosflash.exe and cd\ cd /programs/d330 biosflash.exe
which seemed to work in sometimes but not all the time and can get very confusing. so your saying if i use ..\programs\d330\biosflash.exe it should work like that. unfortunately i only have qb 4.5 so i can't use that curdir$ command. although it would be handy. if this is what you are saying then that is awesome and i will do just that. sorry i am not the greatest when it comes to this and i appreciate all of your help.
|
|
|
Post by leu4life on Oct 10, 2007 0:26:23 GMT
uggggghhh.. yet another fork in the road. i download 7.1 to make things easier for me and that is going good but now all the batch files and config.sys files i have to edit also have a:\whatever.exe and a:\d330\whatever.exe callings. damn. i can't use a qbasic command in these although i wish i could so would what you suggested work for the files too u think?
|
|
|
Post by Mikrondel on Oct 11, 2007 6:47:24 GMT
Quick tutorial on directories... you can skip to the bottom if you really want.
Let's start from this: the directory separator is always \ under DOS (and it's the foolproof one in Windows, although in some contexts you can use / instead - but for this problem definitely avoid the /).
In any directory, . means that directory itself, and .. means its parent directory. For instance, C:\my\stuff\. is C:\my\stuff and C:\my\stuff\.. is equivalent to C:\my.
The environment (in Windows that means the DOS Window) always has a current directory. CURDIR$ will return this. The command CHDIR (which can be shortened to CD) changes the current directory.
There are two types of paths; relative and absolute. Absolute paths start with either a drive letter or a \; relative paths do not. A:\Autoexec.bat is an absolute path. \ is an absolute path. prog.exe is a relative path. ..\programs\d330\biosflash.exe is a relative path.
Relative paths are assumed to be within the current directory. If you are in D:\programs\xyz (that is, that is your current directory) then executing cd ..\d330 is equivalent to executing cd D:\programs\xyz\..\d330 which itself is equivalent to cd D:\programs\d330 because of the ... Note that this action changes your current directory. If you instead did ..\d330\biosflash.exe it would be equivalent to D:\programs\xyz\..\d330\biosflash.exe which is equivalent to D:\programs\d330\biosflash.exe which runs the program without changing the current directory - unless biosflash.exe itself changes the directory.
Paths that start with a \ are semi-relative; they assume the current drive but ignore the current directory. CD \ changes your directory to the root of the current drive; while CD \programs\d330 changes to that directory on the current drive.
PRACTICAL POINTS
Filenames in DOS can have a maximum of 8 letters in the name and 3 letters in the extension (i.e. after the dot), and they're not allowed spaces or certain symbols. biosflash.exe is too long for a DOS filename. You can either rename it with Windows, or refer to it as biosfl~1.exe from QB, or use CMD /C to run it (ask if you want further help with that).
Now, usually when a program starts, the current directory is set to the directory the program is in (unless you override this with a shortcut). If any of your programs (such as biosflash) rely on this, you may need to CD to their directory before running them.
What I would suggest is to simply always prefix your directories with a \ and CD to them, then run the program you wish to run. This should then only cause a problem if for some reason the current drive is changed.
E.g. cd \programs\d330 biosflash.exe
|
|
|
Post by leu4life on Oct 11, 2007 21:09:39 GMT
AWESOME! thank you for putting time into this question. this seems like it would definitely help. i just got home from work but i'm so excited to try this. THANK YOU AGAIN! ;D
|
|
clippy
Junior Member
Posts: 32
|
Post by clippy on Oct 25, 2007 20:23:22 GMT
The following code requires QB4.5 and it's library. Also make sure you have QB.BI in the QB folder:
DEFINT A-Z '$INCLUDE: 'QB.BI' DIM Registers AS RegTypeX PRINT "Which drive (A, B, C, etc.)? "; DO: Drive$ = UCASE$(INKEY$): LOOP UNTIL LEN(Drive$) PRINT Cur$ = GetDir$(Drive$) IF LEN(Cur$) THEN PRINT "The current directory is: "; Drive$; Cur$ ELSE : PRINT "Invalid drive!" END IF
FUNCTION GetDir$ (Drive$) STATIC Temp$, Drive, Zero 'local variables IF LEN(Drive$) THEN 'did they pass a drive? Drive = ASC(UCASE$(Drive$)) - 64 ELSE : Drive = 0 END IF Temp$ = SPACE$(65) 'DOS stores the name here Registers.AX = &H4700 'get directory service Registers.DX = Drive 'the drive goes in DL Registers.SI = SADD(Temp$) 'show DOS where Temp$ is 'Registers.DS = SSEG(Temp$) 'use this with BASIC PDS Registers.DS = -1 'use this with QuickBASIC CALL InterruptX(&H21, Registers, Registers) 'call DOS with DosInt
IF Registers.flags AND 1 THEN 'must be an invalid drive GetDir$ = "" ELSE : Zero = INSTR(Temp$, CHR$(0)) 'find the zero byte GetDir$ = ":\" + LEFT$(Temp$, Zero - 1) END IF END FUNCTION
This InterruptX routine can find out what drives are valid and displays the current default path on valid drives. Sorry it will not work in QB versions lower than 4.
You could use the function in a loop to find all drives and default directories without a DOS or QB error!
|
|