Discussion:
handling "~" within a string - MS Basics
(too old to reply)
who where
2011-11-22 07:44:15 UTC
Permalink
I am modifying an old QB45 program to find some information embedded
within the folder "C:\Program Files\whatever" which of course in DOS
8.3-speak becomes "C:\Progra~1\whatever".

If I attempt to directly set up a string with the required path and
file name, the ~ character is omitted and the file open fails. The
same happens if I fabricate the string using CHR$(126). Even
executing a CD command to the required folder via SHELL has the same
limitation.

Is there a workaround for this?
Auric__
2011-11-22 17:42:28 UTC
Permalink
Post by who where
I am modifying an old QB45 program to find some information embedded
within the folder "C:\Program Files\whatever" which of course in DOS
8.3-speak becomes "C:\Progra~1\whatever".
If I attempt to directly set up a string with the required path and
file name, the ~ character is omitted and the file open fails. The
same happens if I fabricate the string using CHR$(126). Even
executing a CD command to the required folder via SHELL has the same
limitation.
Is there a workaround for this?
Post your actual code. This should not be happening. (Doesn't happen to me
under WinXP using QBasic or QBX 7.1; don't have QB4.x installed to test on.)

What happens if you just do this?
CHDIR "\PROGRA~1"
SHELL "CD"
--
- We were just talking about you.
- That's relieving. Usually you're screaming about us.
who where
2011-11-23 05:59:12 UTC
Permalink
On Tue, 22 Nov 2011 17:42:28 +0000 (UTC), "Auric__"
Post by Auric__
Post by who where
I am modifying an old QB45 program to find some information embedded
within the folder "C:\Program Files\whatever" which of course in DOS
8.3-speak becomes "C:\Progra~1\whatever".
If I attempt to directly set up a string with the required path and
file name, the ~ character is omitted and the file open fails. The
same happens if I fabricate the string using CHR$(126). Even
executing a CD command to the required folder via SHELL has the same
limitation.
Is there a workaround for this?
Post your actual code. This should not be happening. (Doesn't happen to me
under WinXP using QBasic or QBX 7.1; don't have QB4.x installed to test on.)
What happens if you just do this?
CHDIR "\PROGRA~1"
SHELL "CD"
Part of the problem I am facing is that there appears to be no *easy*
way to ascertain what is the CURRENT PATH in the QB45 IDE, or if there
is I haven't discovered it.

The QB operation isn't on the C: drive, which may have complicated
things. What I was doing is of the form:

CD$ = "something"
SHELL CD$

to try and get the current path to point to C:\Progra~1\whatever, as
direct statements like

PF$ = "C:\Progra~1\whatever"
OPEN PF$+"\folder1\file1" FOR INPUT AS #1

or

PF$ = "C:\Progra~1\whatever\folder1\file1"
OPEN PF$ FOR INPUT AS #1

didn't work while the current drive was E:. If I inserted a
breakpoint between those lines, examining PF$ with a Ctrl-RtMouse
showed the ~ character not present. I must admit it was a leap of
faith (in MS) to assume that this faithfully displayed the string.

Since posting, I have tried a lot more bits in the SHELL example above
(so the actual failing code is NLA), and did actually get the desired
result with:

CD$ = "CD\"
SHELL CD$
(probably redundant going to root of E:)

CD$ = "C:\"
SHELL CD$

CD$ = "CD " + "Progra~1\Whatever"
SHELL CD$
(note that it would NOT change direct to a folder in C:
in a single step ...)

SELECT CASE J$
CASE IS = "44"
PF$ = "copy 44\Whatever.ini c:\ini2ini.txt"
SHELL PF$
....
OPEN "c:\ini2ini.txt" FOR INPUT AS #1

Note that an OPEN containing the ~ character within a named string, or
even with a current path containing it and the ~ not in the OPEN
string per se, would still fail. The copy-then-parse approach did
work, however.

When I am doing quick'n'dirty mods in the IDE, I tend not to use error
trapping. Rather, I use breakpoints and examine variable values to
ensure things are happening the way I want. In this exercise the
parsing routine which examined the .ini file never found the target
until I employed the copy/parse approach. Clunky but it worked, and
all the data we needed to recover from the files was rapidly found.
Ron Avanzino
2011-11-23 17:33:49 UTC
Permalink
Post by who where
On Tue, 22 Nov 2011 17:42:28 +0000 (UTC), "Auric__"
Post by Auric__
Post by who where
I am modifying an old QB45 program to find some information embedded
within the folder "C:\Program Files\whatever" which of course in DOS
8.3-speak becomes "C:\Progra~1\whatever".
If I attempt to directly set up a string with the required path and
file name, the ~ character is omitted and the file open fails. The
same happens if I fabricate the string using CHR$(126). Even
executing a CD command to the required folder via SHELL has the same
limitation.
Is there a workaround for this?
Post your actual code. This should not be happening. (Doesn't happen to me
under WinXP using QBasic or QBX 7.1; don't have QB4.x installed to test on.)
What happens if you just do this?
CHDIR "\PROGRA~1"
SHELL "CD"
Part of the problem I am facing is that there appears to be no *easy*
way to ascertain what is the CURRENT PATH in the QB45 IDE, or if there
is I haven't discovered it.
The QB operation isn't on the C: drive, which may have complicated
CD$ = "something"
SHELL CD$
to try and get the current path to point to C:\Progra~1\whatever, as
direct statements like
PF$ = "C:\Progra~1\whatever"
OPEN PF$+"\folder1\file1" FOR INPUT AS #1
or
PF$ = "C:\Progra~1\whatever\folder1\file1"
OPEN PF$ FOR INPUT AS #1
didn't work while the current drive was E:. If I inserted a
breakpoint between those lines, examining PF$ with a Ctrl-RtMouse
showed the ~ character not present. I must admit it was a leap of
faith (in MS) to assume that this faithfully displayed the string.
Since posting, I have tried a lot more bits in the SHELL example above
(so the actual failing code is NLA), and did actually get the desired
CD$ = "CD\"
SHELL CD$
(probably redundant going to root of E:)
CD$ = "C:\"
SHELL CD$
CD$ = "CD " + "Progra~1\Whatever"
SHELL CD$
in a single step ...)
SELECT CASE J$
CASE IS = "44"
PF$ = "copy 44\Whatever.ini c:\ini2ini.txt"
SHELL PF$
....
OPEN "c:\ini2ini.txt" FOR INPUT AS #1
Note that an OPEN containing the ~ character within a named string, or
even with a current path containing it and the ~ not in the OPEN
string per se, would still fail. The copy-then-parse approach did
work, however.
When I am doing quick'n'dirty mods in the IDE, I tend not to use error
trapping. Rather, I use breakpoints and examine variable values to
ensure things are happening the way I want. In this exercise the
parsing routine which examined the .ini file never found the target
until I employed the copy/parse approach. Clunky but it worked, and
all the data we needed to recover from the files was rapidly found.
Please post your code as another person has suggested. I would not try to
mess with the 8.3 directory listings. I wrote this function several years
ago to determine the current directory. Let me know if it works for you.

' -------------------------------------------------------------------
' GetCurDr.Fcn
' 2004-08-06-1630

DECLARE FUNCTION GetCurDir$ (DRIVE$)

CLS
x$ = GetCurDir$("c:")
PRINT x$
END


FUNCTION GetCurDir$ (DRIVE$)

' GET CURRENT DIRECTORY

W$ = MID$(DRIVE$, 1, 1) + ":"' ADD COLON IF NECESSARY
DIRDAT$ = "C:\UTIL\DIR.DAT" ' A fixed location
SHELL "CD " + W$ + " > " + DIRDAT$
OPEN DIRDAT$ FOR INPUT AS #1: LINE INPUT #1, W$: CLOSE #1
IF RIGHT$(W$, 1) <> "\" THEN GetCurDir$ = W$ + "\" ELSE GetCurDir$ = W$

END FUNCTION
who where
2011-11-24 00:36:50 UTC
Permalink
On Wed, 23 Nov 2011 09:33:49 -0800, "Ron Avanzino"
Post by Ron Avanzino
Post by who where
On Tue, 22 Nov 2011 17:42:28 +0000 (UTC), "Auric__"
Post by Auric__
Post by who where
I am modifying an old QB45 program to find some information embedded
within the folder "C:\Program Files\whatever" which of course in DOS
8.3-speak becomes "C:\Progra~1\whatever".
If I attempt to directly set up a string with the required path and
file name, the ~ character is omitted and the file open fails. The
same happens if I fabricate the string using CHR$(126). Even
executing a CD command to the required folder via SHELL has the same
limitation.
Is there a workaround for this?
Post your actual code. This should not be happening. (Doesn't happen to me
under WinXP using QBasic or QBX 7.1; don't have QB4.x installed to test on.)
(snip)
Post by Ron Avanzino
Post by who where
Part of the problem I am facing is that there appears to be no *easy*
way to ascertain what is the CURRENT PATH in the QB45 IDE, or if there
is I haven't discovered it.
The QB operation isn't on the C: drive, which may have complicated
CD$ = "something"
SHELL CD$
to try and get the current path to point to C:\Progra~1\whatever, as
direct statements like
PF$ = "C:\Progra~1\whatever"
OPEN PF$+"\folder1\file1" FOR INPUT AS #1
or
PF$ = "C:\Progra~1\whatever\folder1\file1"
OPEN PF$ FOR INPUT AS #1
didn't work while the current drive was E:. If I inserted a
breakpoint between those lines, examining PF$ with a Ctrl-RtMouse
showed the ~ character not present. I must admit it was a leap of
faith (in MS) to assume that this faithfully displayed the string.
Since posting, I have tried a lot more bits in the SHELL example above
(so the actual failing code is NLA), and did actually get the desired
CD$ = "CD\"
SHELL CD$
(probably redundant going to root of E:)
CD$ = "C:\"
SHELL CD$
CD$ = "CD " + "Progra~1\Whatever"
SHELL CD$
in a single step ...)
SELECT CASE J$
CASE IS = "44"
PF$ = "copy 44\Whatever.ini c:\ini2ini.txt"
SHELL PF$
....
OPEN "c:\ini2ini.txt" FOR INPUT AS #1
Note that an OPEN containing the ~ character within a named string, or
even with a current path containing it and the ~ not in the OPEN
string per se, would still fail. The copy-then-parse approach did
work, however.
When I am doing quick'n'dirty mods in the IDE, I tend not to use error
trapping. Rather, I use breakpoints and examine variable values to
ensure things are happening the way I want. In this exercise the
parsing routine which examined the .ini file never found the target
until I employed the copy/parse approach. Clunky but it worked, and
all the data we needed to recover from the files was rapidly found.
Please post your code as another person has suggested.
Ron, you missed the bit above which stated:

"(so the actual failing code is NLA)"

which is why I didn't/can't. NLA = no longer available.
Post by Ron Avanzino
I would not try to
mess with the 8.3 directory listings. I wrote this function several years
ago to determine the current directory. Let me know if it works for you.
' -------------------------------------------------------------------
' GetCurDr.Fcn
' 2004-08-06-1630
DECLARE FUNCTION GetCurDir$ (DRIVE$)
CLS
x$ = GetCurDir$("c:")
PRINT x$
END
FUNCTION GetCurDir$ (DRIVE$)
' GET CURRENT DIRECTORY
W$ = MID$(DRIVE$, 1, 1) + ":"' ADD COLON IF NECESSARY
DIRDAT$ = "C:\UTIL\DIR.DAT" ' A fixed location
SHELL "CD " + W$ + " > " + DIRDAT$
OPEN DIRDAT$ FOR INPUT AS #1: LINE INPUT #1, W$: CLOSE #1
IF RIGHT$(W$, 1) <> "\" THEN GetCurDir$ = W$ + "\" ELSE GetCurDir$ = W$
END FUNCTION
I may "bookmark" that for another day. The task was to recover some
key strings from a huge number of files spread across an equally huge
number of subfolders, which I was able to complete as described above.
There was a level of urgency in the once-only task, and now it is
history.

Loading...