Older Version
Newer Version
alexbarfoot
Aug 28, 2006
Copying, moving, delecting and renaming files
This article contains four sections. a section on copying files, a section on moving files, a section on deleting files and a section on renaming files. I am happy for anyone to edit this article and rewrite parts.
Copying a file
Bellow the method by which a file can be copied using API calls is shown:
Remember to include the file directories in the filename.
Moving a file
There are two ways to move a file, using the name command and using API calls.
Bellow the method by which a file can be moved using API calls is shown:
The code bellow shows how to move a file and keep the same file name.
The code bellow shows how to move a file with a different file name:
Bellow the method by which a file can be moved using the name comand is shown:
what you need to do is set the filename$ string to the file you want to move. Remember to include file directories. Then you need to set the movefilename$ to the directories you want to move it to plus the file name.
A working example is shown bellow:
Deleting a file
Files can be deleted using the kill command. The kill comand does not place the fiile in the recycle bin. The code bellow shows how the kill command works.
Use the code above wisely and don't just delete any odd file because it is hard to get then back.
Renaming a file
You can use the name command to rename a file. This command can also be used to move a file. Look a at the move section to learn how that works. The code bellow shows how to rename a file:
Article by Alex Barfoot
alexbarfoot at gmail.com
This article contains four sections. a section on copying files, a section on moving files, a section on deleting files and a section on renaming files. I am happy for anyone to edit this article and rewrite parts.
Copying a file
Bellow the method by which a file can be copied using API calls is shown:
calldll #kernel132, "CopyFileA",_The currentfilename$ is the string that contains the file you want to make a copy of. The copyfilename$ is the file name for the copy. The bFailIfExists tells the computer what to do if the file name for the copy is already used. If set to 0 the copy will overwrite the current file with the same name. If set to 1 the copy does not overwrite the file. The code bellow shows how to copy a file into a different folder with the same file name:
currentfilename$ as ptr,_ 'the string containing the file to be copied
copyfilename$ as ptr,_ 'the string containing the file name of the copied file
bFailIfExists as long,_ '1or0
re as long 'not 0 if copy was successful
let currentfilename$= "c:\text.txt"The code bellow shows how to make a copy of a file into the same folder with a different file name:
let copyfilename$= "c\folder\text.txt"
let bFailIfExists= 0
calldll #kernel132, "CopyFileA",_
currentfilename$ as ptr,_
copyfilename$ as ptr,_
bFailIfExists as long,_ '1or0
re as long
if re=0 then print, "copyfailed"
let currentfilename$= "c:\text.txt"
let copyfilename$= "c\copyoftext.txt"
let bFailIfExists= 0
calldll #kernel132, "CopyFileA",_
currentfilename$ as ptr,_
copyfilename$ as ptr,_
bFailIfExists as long,_
re as long
if re=0 then print, "copyfailed"
Remember to include the file directories in the filename.
Moving a file
There are two ways to move a file, using the name command and using API calls.
Bellow the method by which a file can be moved using API calls is shown:
calldll #kernel132, "MoveFileA",_The currentfilename$ is the string that contains the name of the file you want to move. The movefilename$ is the file name for new location of the file. re will be either 0 or more. when re is 0 it means that moving the file has failed.
currentfilename$ as ptr,_ 'the string containing the file to be copied
movefilename$ as ptr,_ 'the string containing the file name of the file in its new location
re as long 'not 0 if move was successful
The code bellow shows how to move a file and keep the same file name.
let currentfilename$= "c:\text.txt"
let movefilename$= "c\folder\text.txt"
calldll #kernel132, "MoveFileA",_
currentfilename$ as ptr,_
movefilename$ as ptr,_
re as long
if re=0 the print, "move failed"
The code bellow shows how to move a file with a different file name:
let currentfilename$= "c:\text.txt"
let movefilename$= "c\folder\textmoved.txt"
calldll #kernel132, "MoveFileA",_
currentfilename$ as ptr,_
movefilename$ as ptr,_
re as long
if re=0 the print, "move failed"
Bellow the method by which a file can be moved using the name comand is shown:
name filename$ as movefilename$
what you need to do is set the filename$ string to the file you want to move. Remember to include file directories. Then you need to set the movefilename$ to the directories you want to move it to plus the file name.
A working example is shown bellow:
let currentfilename$= "c:\text.txt"
let movefilename$= "c\folder\text.txt"
name filename$ as movefilename$
Deleting a file
Files can be deleted using the kill command. The kill comand does not place the fiile in the recycle bin. The code bellow shows how the kill command works.
filedialog "select file a file to delete"
if filename$="" then wait
kill filename$
Use the code above wisely and don't just delete any odd file because it is hard to get then back.
Renaming a file
You can use the name command to rename a file. This command can also be used to move a file. Look a at the move section to learn how that works. The code bellow shows how to rename a file:
filedialog "select file a file to rename"Remember to include file extensions such as .txt on the end of the new file name.
if filename$="" then wait
prompt "enter a new file name"; newfilename$
name filename$ as newfilename$
print "file name has been changed fro";filename$;"to";newfilename$
Article by Alex Barfoot
alexbarfoot at gmail.com