Active Forums => QB64 Discussion => Topic started by: Mad Axeman on May 12, 2020, 04:31:08 pm
Title: File manipulation commands
Post by: Mad Axeman on May 12, 2020, 04:31:08 pm
I've just been looking through the keyword list and surprised that there doesn't seem to be some basic file handling commands available. I want to copy some files from one directory to another. I know I can do a simple shell command but that would only work on Windows machines. Wouldn't it be so much nicer if there was a 'copy' keyword to copy a file from one directory to another or a 'move' keyword to move a file?? Just a thought for the next version - unless those keywords are there already and I just can't find them :-)
Title: Re: File manipulation commands
Post by: Pete on May 12, 2020, 05:19:18 pm
1) Open your original file for BINARY as file number #1. 2) Set len(a$) = LOF(1) 3) GET #1,,a$ ' Gets the entire file. 4) Copy it to a new file, by opening a new file for BINARY as #2 5) PUT #2,,a$ 6) Close both files.
Pete
Title: Re: File manipulation commands
Post by: Mad Axeman on May 13, 2020, 02:00:50 am
Hi Pete
I realise you could create a little function to copy files, either the way you say or using shell, but don't you think QB64 should have some basic file handling commands? We've already got the directory commands from quickbasic so it would be nice to have matching file commands. Just 'copy frompath$ topath' and 'move frompath$ topath$' would be lovely :-)
Title: Re: File manipulation commands
Post by: Pete on May 13, 2020, 02:44:57 am
QB64 also preserved the QBasic NAME AS command. NAME AS allows users to change the name of a file, or move it to another drive/directory with the same or different name.
My hunch is that since there are several simple ways to do these tasks, and very limited development of the language going forward, that although I agree these commands would be nice additions to the language, they are probably not a priority. Now that stated, if you get your wish, thank Murphy and his law.
Pete
Title: Re: File manipulation commands
Post by: Petr on May 13, 2020, 02:29:17 pm
You can also in this easy way do a program to move files.
Title: Re: File manipulation commands
Post by: Mad Axeman on May 13, 2020, 02:40:55 pm
I had forgotten about 'NAME'. Pity you can't use it to make a copy of the file in a different directory while keeping the original. Looks like I'll have to resort to open, get, put, close etc. I need to copy large files from a USB stick onto the hard drive.
Title: Re: File manipulation commands
Post by: Petr on May 13, 2020, 02:53:14 pm
You can use my COPY SUB. Just add corect paths there. If you need first create files list to copy, it is possible using
1) DIR to file (system command) 2) Windows libraries (thanks to Eoredson) 3) SteveMcNeill´s perfect library (direntry.h)
Title: Re: File manipulation commands
Post by: Mad Axeman on May 13, 2020, 03:08:18 pm
I'll be using a simplified version of your post. I know the files will exist and what the file names are so all I'll need is something like below but I'll simplify that even more for what I will be doing.