+ Reply to Thread
Results 1 to 15 of 15

Find and delete Corrupted files within a Directory

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Find and delete Corrupted files within a Directory

    Hi Guys,

    I have a directory (a single folder with no sub-directories within it) with 11,500 files in it, with file types: .pdf .xlsx .pptx .doc .docx .ods .xls
    All of the files looks like they are fine within explorer (they have date modified, and file size greater then 0KB, the icon corresponding to the correct file type), however when opening many of the files, a corrupted warning appears, and the files are full of gibberish.

    Does anyone know a way to file and delete the corrupted files, and spare the ones that still work?

    Maybe something in Excel VBA, could go through each file individually and check them?

    Thanks
    Thanks,

    JimmyWilliams

  2. #2
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    *Bumping Thread for responses*

  3. #3
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    *Bumping Thread for responses*

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Hi !

    Quote Originally Posted by JimmyWilliams View Post
    Does anyone know a way to file and delete the corrupted files, and spare the ones that still work?
    Hey VBA, can you rost my chicken ?!
    Hey VBA, can you open the CD tray to hold my coffee ?!
    Hey VBA, …

    As a reminder, VBA means Visual Basic for Application,
    Application belongs to the application hosting it like here Excel so it was designed for Excel and not for system stuff !

    So it's better to ask first on a system forum if anything exists in Windows to check if a file is corrupted
    then if you have a positive technical answer you may come back here to share it …
    … or obviously just operate manually when you meet such a file.

  5. #5
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Hi !

    Hi,

    Thanks for the reply.
    Fair enough, maybe asking excel to sort all corrupted files might be a bit much, however I know it's possible to open Word files with VBA (and excel files too), so I'd imagine there is a way to determine if there if an opened file has an error or not? I might be able to use that as a way to filter results. I'm just not too sure what the code would be for "checking for an error".
    something like this could work for .doc .docx, .xlsx and .xls files.

    Sorting them out manually I don't think is possible, too many files. Plus I'd like to have a tool that I can then use again in the future if the problem comes up again.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Yes, VBA is more obvious for only Office applications.

    Or exploring the old DOS way if a program returns an 'ErrorLevel' and in this case VBA is useless …

  7. #7
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    Hi,

    I am trying to sort out office files (Microsoft word, Excel ,power point, and PDF); so excel should work well. However, Marc L, Thank you for your opinion, even if it's not helpful.

    The code below almost works, except it stops if the excel file requires a password, or if the excel file asks to save when closed. Does anyone have any solutions to these to cases?

    Please Login or Register  to view this content.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Find and delete Corrupted files within a Directory

    Quote Originally Posted by Marc L View Post
    [INDENT]Hey VBA, can you rost my chicken ?!
    Hey VBA, can you open the CD tray to hold my coffee ?!
    Hey VBA, …
    Please provide responses when you can help answer the question, rather than offering sarcasm.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Find and delete Corrupted files within a Directory

    The code below almost works, except it stops if the excel file requires a password, or if the excel file asks to save when closed.
    Do you want to check only Excel files ??
    Can you attach samples of corrupted files ?
    - Battle without fear gives no glory - Just try

  10. #10
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    Hi,

    I've attached a file that is corrupted.
    I believe the code I have supplied can handle corrupted files (if they are excel), however it is tripping up on password protected files.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    Here is a copy of a file that is protected.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and delete Corrupted files within a Directory

    Just a note, Jimmy, regarding the "bumping" you did on posts #2 and #3. On some forums I think that may be a good idea. Here it is not, because all of our helpers have a convenient link at the top of the screen called "Unanswered Threads", this brings up a list of all posts with zero replies. As soon as you bump your own thread, you remove your thread from that list forever.

    Oops.
    So take on that. Patience wins the day.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  13. #13
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    Thanks for the heads up. I'll be more patient.

    However that being said.. this thread still needs some help relating to protected files.
    Last edited by JimmyWilliams; 03-13-2020 at 06:11 AM.

  14. #14
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    I have looked around the net, and still cannot find an answer,
    Someone looked into changing files into .zip files to try and separate corrupted and protected however that doesnt seem to work.

  15. #15
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Find and delete Corrupted files within a Directory

    *Bumping the thread*

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. delete all text files from directory
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-19-2016, 05:02 PM
  2. VBA code to find .asc files in a directory
    By dubbdan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2013, 05:41 PM
  3. Find *.xls files in a directory and run macro(including *.xls located in subfolders)
    By driftlogic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2012, 11:34 AM
  4. Macro to delete Highlighting in directory of excel files
    By tdm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2012, 02:47 AM
  5. Delete all files in directory, msgbox list files before delete.
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2010, 09:28 PM
  6. Find files in a directory using excel VBA
    By julioMendes1964 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2007, 11:21 AM
  7. What Are And Can I Delete .EMF Files in WINNT/Temp Directory ?
    By Donna in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2005, 09:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1