Alyce
Aug 28, 2006
- "Reformatted, changed "as long" to "as boolean when required, corrected some misspellings"
__Copying,=Copying, moving, delecting and renamingfiles __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.files= [[user:alexbarfoot]] [[toc]]__Copying==Copying afile __Bellowfile== **Below the method by which a file can be copied using API calls isshown: [[code]]shown:** [[code format ]] calldll #kernel132, "CopyFileA",_ 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 aslong,_boolean,_ '1or0 re aslong 'notboolean'not 0 if copy was successful[[code]] 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:[[code]] The currentfilename$ is the string that contains the name of 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 below shows how to copy a file into a different folder with the same file name: [[code format="vbnet"]] let currentfilename$= "c:\text.txt" let copyfilename$= "c\folder\text.txt" let bFailIfExists= 0 calldll #kernel132, "CopyFileA",_ currentfilename$ as ptr,_ copyfilename$ as ptr,_ bFailIfExists aslong,_boolean,_ '1or0 re aslongboolean if re=0 then print, "copyfailed" [[code]] The codebellowbelow shows how to make a copy of a file into the same folder with a differentfile name:filename:[[code]][[code format="vbnet"]] let currentfilename$= "c:\text.txt" let copyfilename$= "c\copyoftext.txt" let bFailIfExists= 0 calldll #kernel132, "CopyFileA",_ currentfilename$ as ptr,_ copyfilename$ as ptr,_ bFailIfExists aslong,_boolean,_ re aslongboolean if re=0 then print, "copyfailed" [[code]] Remember to include thefile directoriescomplete path in the filename.__Moving==Moving afile __Therefile== **There are two ways to move afile,file; using the name command and using APIcalls. Bellowcalls.** Below the method by which a file can be moved using API calls is shown: [[code]] calldll #kernel132, "MoveFileA",_ 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 aslongboolean 'not 0 if move was successful[[code]][[code format="vbnet"]] 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 reIf the function succeeds, the return value is0 it meansnonzero. If the function fails, the return value is zero.Points to a null-terminated string thatmovingspecifies the new name of a filehas failed. Theor directory. The new name must not already exist. A new file may be on a different file system or drive. The codebellowbelow shows how to move a file and keep the same file name.[[code]][[code format="vbnet"]] let currentfilename$= "c:\text.txt" let movefilename$= "c\folder\text.txt" calldll #kernel132, "MoveFileA",_ currentfilename$ as ptr,_ movefilename$ as ptr,_ re aslongboolean if re=0 the print, "move failed" [[code]] The codebellowbelow shows how to move a file with a different file name:[[code]][[code format="vbnet"]] let currentfilename$= "c:\text.txt" let movefilename$= "c\folder\textmoved.txt" calldll #kernel132, "MoveFileA",_ currentfilename$ as ptr,_ movefilename$ as ptr,_ re aslongboolean if re=0 the print, "move failed" [[code]]BellowBelow the method by which a file can be moved using the name comand is shown: [[code]] name filename$ as movefilename$ [[code]]what you need to do isYou must set the filename$ string to the current name of the file you want to move. Remember to includefile directories.the full path. Then you need to set the movefilename$ to thedirectoriespath to which you want to moveit toit, plus the filename. movevilename$ can be any valid filename as long as it doesn't specify a filename. Athat already exists. A working example is shownbellow: [[code]]below: [[code format="vbnet"]] let currentfilename$= "c:\text.txt" let movefilename$= "c\folder\text.txt" name filename$ as movefilename$ [[code]]__Deleting==Deleting afile__file== Files can be deleted using the kill command. The kill comand does not place thefiilefile in the recycle bin. The codebellowbelow shows how the kill command works.[[code]][[code format="vbnet"]] filedialog "select file a file to delete" if filename$="" then wait kill filename$ [[code]] Use the code above wisely and don't just delete any odd file because it is hard to get then back.__Renaming==Renaming afile __Youfile== **You can use the name command to rename afile.file.** This command can also be used to move a file.Look a atSee the move section above to learn how that works. The codebellowbelow shows how to rename a file:[[code]][[code format="vbnet"]] filedialog "select file a file to rename" if filename$="" then wait prompt "enter a new file name"; newfilename$ name filename$ as newfilename$ print"file name"Filename has been changedfro";filename$;"to";newfilename$from";filename$;"to";newfilename$ [[code]] Remember to include file extensions such as .txt on the end of the new file name. Article by Alex Barfoot alexbarfoot at gmail.com [[user:alexbarfoot]] [[toc]]