1. finding file in program with created filename
I want to open a file using a filename that I create. When I run this
statement iget a value of -1 .
If I run the statement
Handler =
open("C:\\Downloads\\abgte2\\DATA\\SCR001.txt","r")
I get the file opened.
If I run the statement
Handler =
open("C:\\Downloads\\abgte2\\DATA\\filename"&".txt","r")
I get the file not found, -1.
I create the filename with this code
numfiles = numfiles + 1
anum = sprintf("%d", numfiles)
if numfiles < 10 then
filename = "SCR00" & numfiles
end if
I tried object filename,
and sequence filename.
When I compare the values of what the Dir command finds against what I
have created, the values are the same
Thanks for any advice
jvandal
2. Re: finding file in program with created filename
sixs wrote:
>
>
>I want to open a file using a filename that I create. When I run this
>statement iget a value of -1 .
>
>If I run the statement
> Handler =
>open("C:\\Downloads\\abgte2\\DATA\\SCR001.txt","r")
>I get the file opened.
>
>If I run the statement
>
> Handler =
>open("C:\\Downloads\\abgte2\\DATA\\filename"&".txt","r")
>I get the file not found, -1.
>
>
Well, it should look like this:
open("C:\\Downloads\\abgte2\\DATA\\"&filename&".txt","r")
3. Re: finding file in program with created filename
sixs wrote:
> If I run the statement
>
> Handler =
> open("C:\\Downloads\\abgte2\\DATA\\filename"&".txt","r")
> I get the file not found, -1.
If 'filename' is a variable then your code shoould look more like this:
open("C:\\Downloads\\abgte2\\DATA\\" & filename & ".txt","r")
Notice that 'filename' is located completely outside the double quotes.
Your original code is actually trying to open:
C:\Downloads\abgte2\DATA\filename.txt
...where the phrase "filename" is literally part of the name of the file
you are trying to open, and not the value of the variable by the same name.
HTH,
Carl
--
[ Carl R White == aka () = The Domain of Cyrek = ]
[ Cyrek the Illogical /\ www.cyreksoft.yorks.com ]
4. Re: finding file in program with created filename
I believe it should be
Handler = open("C:\\Downloads\\abgte2\\DATA\\" & filename & ".txt","r")
sixs wrote:
>
>
>I want to open a file using a filename that I create. When I run this
>statement iget a value of -1 .
>
>If I run the statement
> Handler =
>open("C:\\Downloads\\abgte2\\DATA\\SCR001.txt","r")
>I get the file opened.
>
>If I run the statement
>
> Handler =
>open("C:\\Downloads\\abgte2\\DATA\\filename"&".txt","r")
>I get the file not found, -1.
>
>I create the filename with this code
> numfiles = numfiles + 1
> anum = sprintf("%d", numfiles)
>
> if numfiles < 10 then
> filename = "SCR00" & numfiles
> end if
>I tried object filename,
> and sequence filename.
>When I compare the values of what the Dir command finds against what I
>have created, the values are the same
>Thanks for any advice
>jvandal
>
>
>
>TOPICA - Start your own email discussion group. FREE!
>
>
5. Re: finding file in program with created filename
<snip>
> if numfiles < 10 then
> filename = "SCR00" & numfiles end if
</snip>
Shouldn't that be 'filename = "SCR00" & sprint(numfiles)'?
--
Tommy Carlier
tommy online: http://users.pandora.be/tommycarlier
6. Re: finding file in program with created filename
On Mon, 12 Jan 2004 19:15:28 +0100, Tommy Carlier
<tommy.carlier at pandora.be> wrote:
><snip>
>> if numfiles < 10 then
>> filename = "SCR00" & numfiles end if
></snip>
>
>Shouldn't that be 'filename = "SCR00" & sprint(numfiles)'?
Good catch. I've already deleted the original posting but it also
looks like
filename=sprintf("SCR%03d",numfiles)
could replace an if <10 ... , elsif <100 ... , else ... end if set.
Regards,
Pete
7. Re: finding file in program with created filename
On Mon, 12 Jan 2004 12:57:07 -0800, Evan Marshall
<1evan at sbcglobal.net> wrote:
>sixs wrote:
<snip>
>> anum = sprintf("%d", numfiles)
>>
>> if numfiles < 10 then
>> filename = "SCR00" & numfiles
>> end if
Ah, so there wasn't an elsif <100. But anum can go, as said, replace
all four lines above with filename=sprintf("SCR%03d",numfiles), though
a purist might argue for a proper error message if numfiles>999.
Pete