I have a MS Access table that houses directory names in a table. Scott Reeves helped me with the code below to move files based on sql filter and move the files to a different directory. However, I need to be able to move the entire directory/sub directories based on DIR data in the table. So if the table has DIR1234, then I need to copy DIR name it’s searching in and move SUB DIR’s to the new destination. I tried to modify the code with fso.MoveFolder Source:=FromPath, Destination:=ToPath, but am only getting a subset of data in the immediate window and it’s not moving anything to my destination.
My directories look like Dir1>YYYYMMDD>ABC123>ABC1233>ABD1333 where the code would need to move DIR’s based on the predefined table data DIR’s ABC123/ABC1233 along with the root DIR
Anyone have an idea how I can achieve this?
Sub MoveFolder()
'Move DIR and all Sub Dir to destination based off of table DIR Name
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim mysource As String
Dim mydes As String
Dim mysql As String
mysql = "SELECT * from DIR_UPDATE"
mysource = "C:Test"
'Need to move DIR and Sub DIR's
mydes = "C:TestFromCode"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(mysource)
Set db = CurrentDb
Set rs = db.OpenRecordSet(mysql)
While Not rs.EOF
sourceFile = mysource & rs!Dir
destFile = mydes & rs!Dir
'Debug.Print rs!Dir
If Dir(sourceFile) <> "" Then 'If sourceFile exists, then Dir(sourceFile) will return it's name, otherwise empty string
FileCopy sourceFile, destFile
fso.MoveFolder Source:=mysource, Destination:=mydes
Else
Debug.Print mydes & rs!Dir
End If
rs.MoveNext
Wend
End Sub
question from:
https://stackoverflow.com/questions/65927807/move-directory-and-sub-directories-based-on-filtered-data 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…