Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

handling "~" within a string - MS Basics

6 views
Skip to first unread message

who where

unread,
Nov 22, 2011, 2:44:15 AM11/22/11
to
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__

unread,
Nov 22, 2011, 12:42:28 PM11/22/11
to
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

unread,
Nov 23, 2011, 12:59:12 AM11/23/11
to
On Tue, 22 Nov 2011 17:42:28 +0000 (UTC), "Auric__"
<not.m...@email.address> wrote:

>who where wrote:
>
>> 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

unread,
Nov 23, 2011, 12:33:49 PM11/23/11
to
"who where" <no...@home.net> wrote in message
news:c91pc7pvkcc2go2s5...@4ax.com...
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

unread,
Nov 23, 2011, 7:36:50 PM11/23/11
to
On Wed, 23 Nov 2011 09:33:49 -0800, "Ron Avanzino"
<rava...@yahoo.com> wrote:

>"who where" <no...@home.net> wrote in message
>news:c91pc7pvkcc2go2s5...@4ax.com...
>> On Tue, 22 Nov 2011 17:42:28 +0000 (UTC), "Auric__"
>> <not.m...@email.address> wrote:
>>
>>>who where wrote:
>>>
>>>> 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)
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.

>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.

0 new messages