QBasic - How do you create a file of any kind in QBasic? - dos

I'm trying to create a batch file, a text file, and a DLL file via QBasic?
Please help me... I'm making a fake DOS.

That's old :)
If i remind:
To Open files: (you can create, read and write)
Open (Path and file name) For (Mode) [Access (Type of access)] As #(File number)
Where:
(Path and file name) - The path and name of the destination file
(Mode) - You can set one of this values:
Input: Read Mode
Binary: Structured data
Output: Write Mode - If the file already exist - overwrites the file.
Append: The difference between this and Output is that if the file already exists, the content is appended to the end of the file
(Access type) - Kind of access.
Read: Read-Only access.
Write: Write-Only access.
Read Write: Available only in Append Mode
(File number) - Identifies the file, like a pointer to it.
To close a file, just use:
Close [#(FileNumber)][, #(FileNumber) ...]
Yes you can close more than one file at a time, and if you don't specify the file number, qbasic will close all your opened files.
Note that in Append and Output mode, you must first close the file before you open it for reading!
Ok, to read\write use the same you use on screen, but append the file destination:
Input (Char Length), #(File number), (Name of the Variable)
Line Input #(File number), (Name of the Variable)
Print #(File number), (Data) [or (Binary data)]
If you don't remember to give the carriage-return (commonly \n) use the ASCII char: Chr(10)
Example:
Open "c:\test.bat" for Output as #1
Print #1, "#echo off" + Chr$(10)
Print #1, "echo Hello World"
Close #1
End

Related

Neomutt Pipe Attachments to Shell Program from Menu

The header of the attachments menu in neomutt gives the options
q:Exit s:Save |:Pipe p:Print ?:Help
I assumed that the Pipe option would allow me to pipe a chosen attachment to the shell. In particular, maybe I want to open a file in a way that bypasses the mailcap defaults.
Suppose I wanted to open a file from the attachment menu with open. Is there a way to achieve this with Pipe and not by going to edit my mailcap?
Thanks
The only downfall of this is you need to specify all types, because wildcard can be only in subtype - */* or * doesn't work
Store original mailcap file location in a variable
Define macro in attach menu that changes mailcap file to a new one, run view-attach (which uses open to open a file with) and return to original mailcap_path configuration.
~/.muttrc
set my_origmailcap=$mailcap_path
macro attach <Space> "\
<enter-command>set mailcap_path=~/.mailcap2<enter>\
<view-attach>\
<enter-command>set mailcap_path=$my_origmailcap<enter>\
"
~/.mailcap2
audio/* ; open %s
image/* ; open %s
text/* ; open %s
video/* ; open %s

Validate text file using VB

Could you please advice me on getting the VB script for my below mentioned scenario!!!
Scenario:
VB script needs to open the text file and reads all the lines in the text file but main conditions are for example if the text file named read.000 so the VB script opens the file named read.000 then the validation of the text file should starts with reading the first line of the text file and that first line in the text file is same as the file name read.000 so VB script validation should exactly match first line of file with text file name(read.000). also, the file name can be any read.001 or read.002 whatever the file name it should be same inside the file which present in first line of the file.
if the condition satisfied then only it needs to go for second validation.
Once file name validation is satisfied then VB script needs to validate the text file structure for example, in the text file read.000 the second line starts "01 John lagoon Canada"
In the above example 01 -> represent serial number which should be only two characters if more than two characters then validation get fail
John -> represents first name which should be only 4 characters if its more than 4 then validation needs to get fail same applicable for lagoon.
Could you please advice me on the above request with VB script.
Well hope that i'm getting your problem right, i'll do something like this:
Dim fso, rfile, line
Set fso = CreateObject("Scripting.FileSystemObject")
Set rfile = fso.OpenTextFile(pathtoyourfile, 1)
Do While rfile.AtEndOfStream <> true
line = rfile.ReadLine
if line = fso.GetFileName(pathtoyourfile) then
do your next Validation or something else'must be speficied
else
do something or end 'must be speficied
End if
Loop
rfile.close

Save twitter search result to JSON file

I am using twitter ruby gem to fetch twitter search result. The example code from Github extracts the information from search result.I am wondering how to save the search result, which is JSON i think, to a separate JSON file.
Here is part of the example code:
results = #search.perform("$aaa", 1000)
aFile = File.new("data.txt", "w")
results.map do |status|
myStr="#{status.from_user}: #{status.text} #{status.created_at}"
aFile.write(myStr)
aFile.write("\n")
end
Is there any way to save all the search result to a separate JSON file instead of writing strings to a file?
Thanks in advance.
If you want to save to a file all you need to do is open the file, write it it, then close it:
File.open("myFileName.txt", "a") do |mFile|
mFile.syswrite("Your content here")
mFile.close
end
When you use open you will create the file if it doesn't exist.
One thing to be aware of is that there are different ways to open file, of which will determine where the program writes to. The "a" indicates that it will append everything you write to the file, to the end of the current content.
Here is some of the options:
r Read-only mode. The file pointer is placed at the beginning of the file. This is the default mode.
r+ Read-write mode. The file pointer will be at the beginning of the file.
w Write-only mode. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.
w+ Read-write mode. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.
a Write-only mode. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
a+ Read and write mode. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.
So in your case, you would want to pull out the data you want to save, then write it to a file as I have shown. You can also specify file paths by doing:
File.open("/the/path/to/yourfile/myFileName.txt", "a") do |mFile|
mFile.syswrite("Your content here")
mFile.close
end
Another thing to be aware of is that open does not create directories, so you will either need to create directories yourself, or you can do it with your program. Here is a link that is helpful for file input/output:
http://www.tutorialspoint.com/ruby/ruby_input_output.htm

can't locate my file in subfolder nor read it (applescript)

I want to read text in a list from a textfile "test.txt" that's located in a subfolder called "data". The text is formatted as plain text, every line ends with enter. After all I want to work around that my code could not be saved anymore because I stored too many data like set names to {"Adam", "Adele",... which pumped the sctp over 500kb, by reading huge lists from textfiles.
Which way I try, I end up getting the xyz.app-name in my set folder, I don't know how its better to use read or do it with POSIX, or I get permission trouble when I use container of to filter my filename, nor where to nest the code to open the file.
Can someone help me start?
EDIT
I tried a bit and got a solution that worked for me, reading my text in a list. See below.
Then I came to another problem: One list I could not save in MacOSRoman, so I had to use Unicode UTF-16. But I can't break myfile2 into a list anymore. Can someone help me out with this?
As a new user I could not upload my screenshot, so here is the code:
set List1 to (read file myFile1 using delimiters linefeed) as list
set List2 to (read file myFile2 using delimiters linefeed as Unicode text) as list
Try any of these:
set aData to read file "Mac OS X:Users:j0k:Desktop:text file.txt"
set bData to read POSIX file "/Users/j0k/Desktop/text file.txt"
set cData to read alias "Mac OS X:Users:j0k:Desktop:text file.txt"
set dData to do shell script "cat '/Users/j0k/Desktop/text file.txt'"
An easy way of getting the path to your file is to drag the file into the script editor.
EDIT:
tell application "Finder" to set myFolder to container of (path to me) as text
set myFile to myFolder & "Data:test.txt"
set aData to read file myFile

how to increment a counter written into a file in ruby

I am making a count of how many times a module fails into a file. so whenever it fails, i open the file, increment the number in the file and close it. How i can i do it with opening the file just once instead of opening it twice once for reading and another of writing.
Thanks
Assumes a file named counter.txt in the same dir as the script is invoked from. The file should have nothing other than the number in it.
File.open 'counter.txt' , 'r+' do |file|
num = file.gets.to_i
file.rewind
file.puts num.next
end
Basically, it opens the file 'counter.txt' for reading and writing starting at the beginning of the file It uses the block form of open in order to ensure the file is closed when it is done. It gets the number and then converts it to an integer to get the current count. It rewinds the file pointer so that it is at the beginning of the file again (because we want to write over the old number) Then prints out to the file the incremented number.

Resources