Nguyen Anh Dung
Board Regular
- Joined
- Feb 28, 2020
- Messages
- 180
- Office Version
- 2016
- Platform
- Windows
i have picture as below:
i have folder Image: include folder and image
i want move image group 1-> folder: 20200921_22_014_TPThuanAn_GS103997
i want move image group 2-> folder: 20200921_22_014_TPThuanAn_GS203997
i have code as below:
i have folder Image: include folder and image
i want move image group 1-> folder: 20200921_22_014_TPThuanAn_GS103997
i want move image group 2-> folder: 20200921_22_014_TPThuanAn_GS203997
i have code as below:
Code:
Public Sub Moveimage_360_1()
Dim sourceFolder As String, FileName As String
Dim destinationFolder As String, foundDestinationFolder As String
Dim destinationFolder1 As String
Dim missingFolders As String
Dim NewFileName As String
On Error Resume Next
'sourceFolder = "D:\Vidu\"
sourceFolder = Application.InputBox("Nhap duong dan: ")
If Right(sourceFolder, 1) <> "\" Then sourceFolder = sourceFolder & "\"
missingFolders = ""
FileName = Dir(sourceFolder & "*.JPG")
While FileName <> vbNullString
If Right(FileName, 4) = ".JPG" Then
destinationFolder = Left(FileName, Len(FileName) - 7)
foundDestinationFolder = Find_Subfolder(sourceFolder, destinationFolder)
End If
If foundDestinationFolder <> "" Then
NewFileName = Split(FileName, "_")(4)
Name sourceFolder & FileName As foundDestinationFolder & NewFileName
'Else
' missingFolders = missingFolders & vbCrLf & destinationFolder
End If
FileName = Dir
Wend
If missingFolders = "" Then
MsgBox "Ho" & ChrW(224) & "n Th" & ChrW(224) & "nh !!!"
Else
MsgBox "Folder Khong Ton Tai" & vbCrLf & _
missingFolders
End If
End Sub
Private Function Find_Subfolder(FolderPath As String, subfolderName As String) As String
Static fso As Object
Dim FSfolder As Object, FSsubfolder As Object
If fso Is Nothing Then Set fso = CreateObject("Scripting.FileSystemObject")
Set FSfolder = fso.GetFolder(FolderPath)
Find_Subfolder = ""
For Each FSsubfolder In FSfolder.SubFolders
If UCase(FSsubfolder.Name) = UCase(subfolderName) Then
Find_Subfolder = FSsubfolder.Path & "\"
Else
Find_Subfolder = Find_Subfolder(FSsubfolder.Path, subfolderName)
End If
If Find_Subfolder <> "" Then Exit For
Next
End Function