File input/output: Difference between revisions
Content added Content deleted
Line 897: | Line 897: | ||
</pre> |
</pre> |
||
=={{header|FutureBasic}}== |
|||
Modified May 2024 |
|||
Prompts the user for an input text file. |
|||
Rich Love |
|||
<syntaxhighlight lang="futurebasic"> |
<syntaxhighlight lang="futurebasic"> |
||
/* |
/* |
||
Rosetta Code File input/output example |
Rosetta Code File input/output example |
||
FutureBasic 7.0. |
FutureBasic 7.0.24 |
||
Rich Love |
Rich Love |
||
5/11/24 |
|||
Before running this, use TextEdit to create a file called input.txt on your desktop. |
|||
Format as plain text and create a few lines of text. |
|||
Then save. |
|||
*/ |
*/ |
||
Line 916: | Line 914: | ||
output file "FileInputOutput.app" |
output file "FileInputOutput.app" |
||
void Local fn doIt |
|||
CFURLRef ParentDirectory // Create a url for the desktop |
CFURLRef ParentDirectory // Create a url for the desktop |
||
ParentDirectory = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask ) |
ParentDirectory = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask ) |
||
CFURLRef inputURL // Create a url for input.txt on the desktop |
|||
inputURL = fn URLByAppendingPathComponent( ParentDirectory, @"input.txt" ) |
|||
CFURLRef outputURL // Create a url for output.txt on the desktop |
CFURLRef outputURL // Create a url for output.txt on the desktop |
||
outputURL = fn URLByAppendingPathComponent( ParentDirectory, @"output.txt" ) |
outputURL = fn URLByAppendingPathComponent( ParentDirectory, @"output.txt" ) |
||
⚫ | |||
CFURLRef inputURL = openpanel( 1, @"Open a text file",@"txt") |
|||
⚫ | |||
if inputURL = NULL then end |
|||
str255 dataLine |
str255 dataLine |
||
dataLine = "" |
|||
if fn FileManagerContentsAtURL(inputURL) <> NULL |
|||
⚫ | |||
⚫ | |||
While Not Eof( |
While Not Eof(1) |
||
Line Input #1, dataLine |
|||
Print #2, dataLine |
|||
Wend |
Wend |
||
⚫ | |||
Close #2 |
Close #2 |
||
⚫ | |||
alert 3,,@"File created on Desktop",@"output.txt",@"OK" |
|||
end |
end |
||
else |
|||
alert 3,,@"File Not Found on Desktop",@"input.txt",@"OK" |
|||
end |
|||
end if |
|||
end fn |
|||
void local fn DoAppEvent( ev as long ) |
|||
select (ev) |
|||
case _appDidFinishLaunching |
|||
fn doIt |
|||
end select |
|||
end fn |
|||
on AppEvent fn DoAppEvent |
|||
handleevents |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||