
-----------------------------------
gevorgkhc
Sun May 16, 2004 11:03 pm

[Tutorial] File Manipulation
-----------------------------------
File Copying
Use the FileCopy command for this. The syntax is:
FileCopy "source", "destination"
For example, if I wanted to copy yo.txt to blah.exe, I'll do:
Private Sub Command1_Click()
On Error Resume Next  'Error Handling
FileCopy "C:\yofolder\yo.txt", "C:\blahfolder\blah.exe"  'Command
End Sub

Yes, you can copy other file formats to another!

File Renaming
If we wanted to rename a file, we would use the Name command. The syntax is:
Name "oldname" As "newname"
For example, if I wanted to rename sup.txt to hello.html, I'll do:
Private Sub Command1_Click()
On Error Resume Next  'Error Handling
Name "c:\supfolder\sup.txt" As "c:\hellofolder\hello.html"  'command
End Sub

You can always rename or copy any formats to another!

Deleting Files
If we wanted to delete a file, we would use the Kill command. The syntax is:
Kill "file"
For example, if I wanted to delete alpha.exe, I'll do:
Kill "C:\Blah\alphafolder\alpha.exe"
I don't have to tell you about the formats again.....

Moving Files
To move a file or files, you first use the copy command and then the kill command. I hope I don't have to give a basic syntax of the two line. See "Copying File" and "Deleting File"
Ok this is an edit. If you want to check that the file was succefully copy is complete to prevent data loss, use the checking file section I just add to this tutorial as an edit and since I'm in a REAL hurry I can just give a quick example.

Checking Files
Private Sub Command1_Click()
On Error Resume Next
FileCopy "C:\oldyofolder\yo.exe", "c:\yofolder\yobolh.ran" 'Copy Command
Dim fexists As Variant 'Create fexists variable
fexists = Dir$("c:\yofolder\yobolh.ran") 'Gets the file name if it exists
If fexists = yobolh.ran Then 'checks if the filename is the file that you want and it exists
Kill "C:\oldyofolder\yo.exe" 'Delete the file
End Sub

You'll understand it.


I'll create a folder manipulation and further file manipulation in another tutorial at another time(part 2).

-----------------------------------
Tony
Mon May 17, 2004 11:01 am


-----------------------------------
When moving the file, it might be a good idea to check if the file was copied successfuly before deleting the original, to prevent accidental data lose.

Thx for the tutorial +25Bits

-----------------------------------
TheXploder
Thu Feb 17, 2005 10:26 pm


-----------------------------------
how would I create a Folder?

-----------------------------------
Tony
Fri Feb 18, 2005 10:16 am


-----------------------------------
you could use a shell command :D 

Shell("mkdir c:\folder")


-----------------------------------
Brightguy
Fri Feb 18, 2005 10:45 am

Re: [Tutorial] File Manipulation
-----------------------------------
But wouldn't you need a program named mkdir to run?
Heh, there is actually a mkdir statement:
MkDir "C:\Folder"
