Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
How to Copy Files from Basic Without Using SHELL Statement
Article ID: 77876 - View products that this article applies to.
This article was previously published under Q77876
Basic has no statement to copy files from one directory, drive, or filename to another. One method of copying files is by SHELLing to MS-DOS and using the COPY command. You can also open files for BINARY access and input the file one byte at a time and send it to another file. This is essentially the same as the MS-DOS COPY command.
Note that the NAME statement will rename a file (or a directory), or if given a different path for the second argument, will move a file to the new destination (deleting the file's copy in the old destination). An example is further below.
Other methods, such as MS-DOS interrupts, can be used to input larger file chunks at a time. However, trying to duplicate MS-DOS COPY with MS-DOS interrupts is more complicated than the program below.
The program below uses the INPUT statement to input the name of the file to copy and the name of the file to output. The "bigchunk" variable can be changed to fit your application, and can be up to 32K bytes in size.
File Copying Example
File Moving ExampleThe Basic NAME statement can move a file from one directory to another on the same disk. (Also, the NAME statement can rename a directory, but cannot move a directory.) The NAME statement will give the error "RENAME ACROSS DISKS" when attempting to move a file from one drive to another (such as from C:\ to D:\). For more information on NAME, see page 217 in the "Microsoft Basic 7.0 Language Reference" manual provided with Microsoft Basic PDS versions 7.0 and 7.1.
In the following example, the NAME statement moves MYNAME.DAT from C:\TEST to C:\NEWTEST:
Article ID: 77876 - Last Review: August 16, 2005 - Revision: 2.1