Try this :

 

To get the list of file in selected folder :

 

Option Compare Text

Sub GetFileListFromFolder()

 

    Dim strFolderPath   As String

    Dim objFso          As Object

    Dim objFolder       As Object

    Dim objFile         As Object

    Dim lngICounter     As Integer

    

    With Application.FileDialog(msoFileDialogFolderPicker)

    .Show

    .AllowMultiSelect = False

    strFolderPath = .SelectedItems(1)

    End With

    

    If strFolderPath = "" Then

        MsgBox "Cancelled by User", vbCritical

        Exit Sub

    End If

    

    Set objFso = CreateObject("Scripting.FileSystemobject")

    Set objFolder = objFso.getFolder(strFolderPath)

    lngICounter = 2

    

    For Each objFile In objFolder.Files

        Cells(lngICounter, 1).Value = objFile.Path

        lngICounter = lngICounter + 1

    Next

    

    MsgBox "Total File Found : " & lngICounter - 1, vbInformation

    

    strFolderPath = Empty

    Set objFso = Nothing

    Set objFolder = Nothing

    Set objFile = Nothing

    lngICounter = Empty

    

End Sub

 

To Delete the selected files :

 

Sub DeleteFiles()

  

    Dim objFso          As Object

    Dim rngCell         As Range

    Dim rngRange        As Range

    Dim objFile         As Object

    Set objFso = CreateObject("Scripting.FileSystemobject")

    Set rngRange = Sheet1.Range("B1:B" & Sheet1.UsedRange.Rows.Count)

    For Each rngCell In rngRange

        If rngCell.Value = "Yes" Then

            Set objFile = objFso.getFile(rngCell.Offset(, -1).Value)

            objFile.Delete

        End If

    Next

End Sub

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of Shinda Singh
Sent: Mar/Thu/2012 03:03
To: excel-macros@googlegroups.com
Subject: $$Excel-Macros$$ Need Urgent Help_Surendra

 

Hi Team,

 

I need a help from your side, i have a folder where more that 2000 xls and
word and PDF file save. i want to make a list of name in MS excel and then i
want to delete the unusable file from the list,

 

Please help me.

 

Thanks and Regards,

 

Surendra Singh

+91 95842 66415

 

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 
----------------------------------------------------------------------------
--------------------------
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

Attachment: DeleteFiles.xlsm
Description: application/vnd.ms-excel.sheet.macroenabled.12

Reply via email to