I have a button that moves files from location 1 to location 2. If the folder doesn't exist in location 2, it creates it before moving the files. What i am trying to do is delete the empty folder from location 1 once the files have been moved to location 2. How would i do this?
Here is my current working code that moves the files perfectly but leaves the empty folder behind in location 1.
Private Sub Command63_Click()
Const Prep = "\\servername\dart$\Document-Library\Doc-Production"
Const Pub = "\\servername\DART$\Document-Library\Public"
Dim OldPath As String
Dim NewPath As String
Dim LoopFile As String
Dim FileExt() As String
'Dim Doc_Folder As String
Dim Folder As String
Dim fso As Object
Folder = Replace(Pub & Doc_Number, "/", "-")
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check whether folder exists
If fso.FolderExists(Folder) = False Then
' If not, create it
fso.CreateFolder Folder
End If
' Open it
Shell "explorer.exe " & Folder, vbNormalFocus
OldPath = Replace(Prep & Doc_Number & "", "/", "-")
NewPath = Replace(Pub & Doc_Number & "", "/", "-")
LoopFile = Dir(OldPath & "*.*")
Do While LoopFile <> ""
FileExt = Split(LoopFile, ".")
Select Case FileExt(UBound(FileExt))
Case "docx", "doc"
Name OldPath & LoopFile As NewPath & LoopFile
End Select
LoopFile = Dir
Loop
End Sub
Here is my current working code that moves the files perfectly but leaves the empty folder behind in location 1.
Private Sub Command63_Click()
Const Prep = "\\servername\dart$\Document-Library\Doc-Production"
Const Pub = "\\servername\DART$\Document-Library\Public"
Dim OldPath As String
Dim NewPath As String
Dim LoopFile As String
Dim FileExt() As String
'Dim Doc_Folder As String
Dim Folder As String
Dim fso As Object
Folder = Replace(Pub & Doc_Number, "/", "-")
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check whether folder exists
If fso.FolderExists(Folder) = False Then
' If not, create it
fso.CreateFolder Folder
End If
' Open it
Shell "explorer.exe " & Folder, vbNormalFocus
OldPath = Replace(Prep & Doc_Number & "", "/", "-")
NewPath = Replace(Pub & Doc_Number & "", "/", "-")
LoopFile = Dir(OldPath & "*.*")
Do While LoopFile <> ""
FileExt = Split(LoopFile, ".")
Select Case FileExt(UBound(FileExt))
Case "docx", "doc"
Name OldPath & LoopFile As NewPath & LoopFile
End Select
LoopFile = Dir
Loop
End Sub