CodeItBetter Programming Another VB Programming Blog

How to Move File from one directory to another (in three ways)

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'File/Folder Handling - How to Move File from one directory to another (in three ways)
'Using Name:

Public Sub MoveFileUsingName(ByVal sOldFileName As String, ByVal sNewFileName As String)
'The Name statement renames a file and moves it to a different directory or folder,
'if necessary. Name can move a file across drives, but it can only rename an existing
'directory or folder when both newpathname and oldpathname are located on the same
'drive. Name cannot create a new file, directory, or folder.
    Name sOldFileName As sNewFileName
End Sub
 
'Using FSO:

Public Sub MoveFileUsingFSO(ByVal sOldFileName As String, ByVal sNewFileName As String)
    Dim FSO As Scripting.FileSystemObject
    Set FSO = New Scripting.FileSystemObject
    FSO.MoveFile sOldFileName, sNewFileName
    Set FSO = Nothing
End Sub
 
'Using API

Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, _
    ByVal lpNewFileName As String) As Long
 
Public Sub MoveFileUsingAPI(ByVal sOldFileName As String, ByVal sNewFileName As String)
    Call MoveFile(sOldFileName, sNewFileName)
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.