Results 1 to 2 of 2

Thread: Move Directory

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    I have a couple of questions. I have a form that I need to MOVE files from one directory to another. I know how to move single files, the code I have now is:

    Private Sub Command1_Click()
    Dim FileSystemObject As Object
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    FileSystemObject.MoveFile "o:\GIS\Unmappped\259G.dwg", "d:\NewWorkOrder\259G.dwg"
    End Sub

    However I will not know the names of the files to be moved, so I need to move the contents of the directory to the other diretory. I can't copy because the o:\ directory has to be emptied.

    Also I have the code in a Command button for this example but I need to know how to make this run "unseen"

    Thanks for any help,

    JO

  2. #2
    Guest
    Code:
    Private Sub Command1_Click()
          Dim FSO as Object
          Set FSO = CreateObject("Scripting.FileSystemObject")
          FSO.MoveFolder "o:\GIS\Unmappped\", _
          "d:\NewWorkOrder\" 
    End Sub
    Don't know how to make it hidden with FSO, but you can use API...

    Code:
    Public 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
      
    Public Const FO_MOVE = &H1
    Public Const FO_COPY = &H2
    Public Const FO_DELETE = &H3
    Public Const FO_RENAME = &H4
    
    Public Const FOF_SILENT = &H4
    Public Const FOF_RENAMEONCOLLISION = &H8
    Public Const FOF_NOCONFIRMATION = &H10
    Public Const FOF_SIMPLEPROGRESS = & H100 
    Public Const FOF_ALLOWUNDO = &H40
    
    
    Public 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_COPY
         SHF.hWnd = Me.hWnd
         SHF.pFrom = ""o:\GIS\Unmappped\*.*"
         SHF.pTo = "d:\NewWorkOrder\"
         SHF.fFlags = FOF_SILENT
    
         lret = SHFileOperation(SHF)
    
         'Returns 0 if successful
    
         If lret <> 0 Then
              MsgBox "Error"
         End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width