Hi Luke M
I am doing this but problem is all files are move to duplicate folder please help
Sub FileDetails()
Application.ScreenUpdating = False
'Sheets("Sheet1").Unprotect Password:="Swami"
Dim objfso As Object, myFolder As Object, myFile As Object
Dim strFldName As String
Dim i As Integer
Dim rng As Range
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
'\\ Get folder browser
On Error Resume Next
'strFldName = CreateObject("Shell.Application").BrowseForFolder(0, "Browse Folder", 0, "").Self.Path
Application.FileDialog(msoFileDialogFolderPicker).Show
strFldName = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
On Error GoTo 0
'\\ Don't process further
If strFldName = "" Then
MsgBox "No Folder selected!", vbExclamation
Exit Sub
End If
Set objfso = CreateObject("Scripting.FileSystemObject")
Set myFolder = objfso.GetFolder(strFldName) ' change the folder path
If myFolder.Files.Count > 0 Then
i = 2
For Each myFile In myFolder.Files
Range("A" & i).Value = myFile.Name
Range("B" & i).Value = myFile.DateLastAccessed
Range("C" & i).Value = myFile.DateLastModified
Range("D" & i).Value = myFile.Type
Range("E" & i).Value = myFile.Size
i = i + 1
Next
Else
MsgBox "No files in the specified Folder", vbOKOnly, "No files"
Application.ScreenUpdating = True
End If
Application.ScreenUpdating = False
Set rng = Sheet1.Range("E2:E" & Sheet1.Range("A65536").End(xlUp).Row).Rows
rng.Offset(0, 1).Formula = "=IF(E2=0,"" "",IF(COUNTIF(E:E,E2)>1,""Duplicate"",""Not Duplicate""))"
For i = 1 To 100
If Cells(i, "F").Value = "Duplicate" Then
FromPath = "C:\Users\swami\Desktop\PDF" '<< Change
ToPath = "C:\Users\swami\Desktop\PDF\" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Duplicate" & "\" '<< Change only the destination folder
FileExt = "*.*" '<< Change
'You can use *.* for all files or *.doc for word files
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CreateFolder (ToPath)
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
'Move file
End If
Next i
'Sheets("Sheet1").Protect Password:="Swami"
Application.ScreenUpdating = True
End Sub