|
Post by DARKNIGHT on Dec 7, 2022 4:15:35 GMT -5
hey everyone,
I am trying, and have been trying to send output from a data file to a sub directory using a file path for another program I am working on I don't know what I am doing wrong, but I get immediate errors when I run the program. I am just noodling around with a test file, trying to get this to work. here are a couple of my failed attempts:
open " test file.file" \ SAMPLE DATA \TEST DATA for output as #1 print #1,"test data" close #1
and
open \ SAMPLE DATA \TEST DATA;" test file.file" for output as #1 print #1,"test data" close #1 path$="SAMPLE DATA\TEST DATA OPEN PATH$\ "test file for output as #1
like I have said before, I have been away from LB for many years and have taken it back up again.
so my memory on how to do some things is fuzzy, THANKS AHEAD OF TIME, Jim
|
|
|
Post by atomose on Dec 7, 2022 4:25:45 GMT -5
Hi,
have you test this yet?
test$ = "SAMPLE DATA\TEST\test file.file"
open test$ for output as #1 print #1,"test data" close #1
|
|
|
Post by Rod on Dec 7, 2022 4:38:21 GMT -5
From your code it seems you have two sub directories within the current working directory. When you create the file path this should be one continuous string. “datadir\testdata\test.dat” Notice there are no spaces and that the whole path and file name is surrounded by quotes. The leading \ is not required. If you are still having bother show us what your actual file paths are by using explorer and copy pasting the contents of the top bar. www.libertybasicuniversity.com/lb4help/Path_and_Filename.htm
|
|
|
Post by tsh73 on Dec 7, 2022 5:44:15 GMT -5
|
|
|
Post by DARKNIGHT on Dec 7, 2022 16:44:00 GMT -5
also, is there a way to use a string in the file path?
my current code creates a new directory and then opens a data file which is intended to send it's output to
the new folder. something like File$ = "f$\test file.file" ? I think this would just name the destination folder as "f$" tho.. Not sure how to get around this.
I love coding, but sometimes it can be a pain in the Asterisk!
here is my entire code thus far:
10 cls locate 5,4:input"Enter A Name For New Folder:";f$ :rem create a subdirectory named as f$ in the current directory if f$="" then confirm"ABORT? ";yn$ if yn$="no" then goto 10 if yn$="yes" then [go] gosub [write]
result = mkdir(f$) if result <> 0 then notice "THE CREATION OF THE FOLDER ";f$;" WAS ABORTED! "
[write] REM write some data in a data file and save to new directory
File$ = "SAMPLE DATA\TEST\test file.file"
open File$ for output as #1 print #1,"test data" close #1
|
|
|
Post by Walt Decker on Dec 7, 2022 18:47:40 GMT -5
Basic way (NOT TESTED): ' DefPath$ = DefaultDir$ NewPath$ = DefaultDir$ + "\TESTDIR"
OPEN DefPath$ + "\TEST1.TXT" FOR OUTPUT AS #1 PRINT #1, "PETER PIPER PICKED A PECK" PRINT #1, "OF PICKLED PEPPERS" CLOSE #1 RetVal = MKDIR(NewPath$)
OPEN DefPath$ + "\TEST1.TXT" FOR INPUT AS #1 OPEN NewPath$ + "\TEST2.TXT" FOR OUTPUT AS #2 LINE INPUT #1, A$ PRINT #2, A$ LINE INPUT #1, A$ PRINT #2, A$ CLOSE #1 CLOSE #2 '
If you want to copy the entire file, research LB statement INPUT$.
|
|
|
Post by DARKNIGHT on Dec 7, 2022 19:29:41 GMT -5
" BY GEORGE, I THINK HE'S GOT IT!" that works and is exactly what I wanted to do! thank you my friend, I have been struggling with this for years. and I also discovered it solves the problem of using a string to designate the
name of the new folder in the path by doing this:
input "NEW FOLDER NAME:";n$ DefPath$ = DefaultDir$ NewPath$ = DefaultDir$ + n$
thank you again! Jim
|
|
|
Post by Walt Decker on Dec 8, 2022 10:04:24 GMT -5
That will not work. It should be NewPath$ = DefaultDir$ + "\" + n$ Look up EOF, LOF, BINARY and INPUT$ in the help.
PS: Unless you are going blind, as am I, please stop using BOLD, HUGE text. It indicates that you are shouting.
|
|
|
Post by DARKNIGHT on Dec 8, 2022 14:07:18 GMT -5
thank you, I was going to ask the former poster how to send the file output to the Default folder named samples. not Samples\Samples\file output name I apologize for the text issue.
|
|
|
Post by Walt Decker on Dec 8, 2022 14:27:38 GMT -5
No problem. We all get carried away once in a while.
Just swap the paths: NewDir$ = "SAMPLES" File1$ = "TEST1.TXT" File2$ = "TEST2.TXT" DefPath$ = DefaultDir$ NewPath$ = DefPath$ + "\" + NewDir$
OPEN DefPath$ + "\" + File1$ FOR OUTPUT AS #1 '<----- PRINT SOME TEXT TO THE FILE -----> CLOSE #1
RetVal = MKDIR(NewPath$)
OPEN DefPath$ + "\" + File1$ FOR INPUT AS #1 OPEN NewPath$ + "\" + File2$ FOR OUTPUT AS #2 WHILE NOT (EOF(#1)) LINE INPUT #1, A$ PRINT #2, A$ WEND CLOSE #1 CLOSE #2
OPEN NewPath$ + "\" + File2$ FOR INPUT AS #1 OPEN DefPath$ + "\" + File1 FOR OUTPUT AS #2 FOR I = 1 TO 3 LINE INPUT #1, A$ PRINT #2, A$ NEXT I CLOSE #1 CLOSE #2
|
|
|
Post by DARKNIGHT on Dec 8, 2022 14:46:49 GMT -5
I tried your suggestion of changing the path to NewPath$ = DefaultDir$ + "\" + n$ that worked fine and is what I was looking for.
Thanks Jim
|
|