|
-
Jan 4th, 2001, 07:31 PM
#1
Thread Starter
Addicted Member
can someone please tell me how to copy all contents of one directory to another, then delete the contents of the original directory? here's what i basically want in dos commands...
copy *.* c:\somedir
delete *.*
thanks
Pete
-
Jan 4th, 2001, 07:42 PM
#2
Use the FileSystemObject.
Code:
Dim FSO As Object
Private Sub Command1_Click()
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.MoveFolder "C:\somedir\", "C:\someotherdir\"
End Sub
-
Jan 4th, 2001, 07:48 PM
#3
You could also use the SHFileOperation API function to move a folder to another folder.
Code:
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Const FO_MOVE = &H1
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_SILENT = &H4
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SIMPLEPROGRESS = & H100
Private Const FOF_ALLOWUNDO = &H40
Private Declare Function SHFileOperation _
Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub Command1_Click()
Dim SHF As SHFILEOPSTRUCT
Dim lret As Long
SHF.wFunc = FO_MOVE
SHF.hWnd = Me.hWnd
SHF.pFrom = "C:\somedir\*.*"
SHF.pTo = "C:\someotherdir\"
SHF.fFlags = FOF_SILENT
lret = SHFileOperation(SHF)
'Returns 0 if successful
If lret <> 0 Then
MsgBox "Error"
End If
End Sub
-
Jan 4th, 2001, 07:50 PM
#4
_______
<?>
Code:
Private Sub Form_Load()
'Using FSO copy the contents of a floppy to a folder on a different drive
'copies files and folders seperately as they use different vehicles
'
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'make sure the directory exists and if not create it
If Dir("C:\AAA", vbDirectory) = "" Then
MkDir ("C:\AAA")
Else
End If
FSO.CopyFile "c:\AABBCC\*", "C:\AAA\", True
FSO.CopyFolder "c:\AABBCC\*", "C:\AAA\", True
'Using fso to delete a directory
FSO.DeleteFolder "c:\AABBCC"
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jan 5th, 2001, 10:58 AM
#5
Thread Starter
Addicted Member
Re: <?>
Originally posted by HeSaidJoe
Code:
Private Sub Form_Load()
'Using FSO copy the contents of a floppy to a folder on a different drive
'copies files and folders seperately as they use different vehicles
'
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'make sure the directory exists and if not create it
If Dir("C:\AAA", vbDirectory) = "" Then
MkDir ("C:\AAA")
Else
End If
FSO.CopyFile "c:\AABBCC\*", "C:\AAA\", True
FSO.CopyFolder "c:\AABBCC\*", "C:\AAA\", True
'Using fso to delete a directory
FSO.DeleteFolder "c:\AABBCC"
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed"
End Sub
great, thanks guys for the code, however i dont want to delete the directory im moving the files from, just the files inside the directory...how can i do this?
Pete
-
Jan 5th, 2001, 11:17 AM
#6
Thread Starter
Addicted Member
hehe it's too early in the morning, i forgot about the kill function for my post above but thanks guys for the posts, they helped tremendously
Pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|