Forum

Upgrade VBA code to...
 
Notifications
Clear all

[Solved] Upgrade VBA code to remove all " - Copy." files to clean up the computer

4 Posts
2 Users
0 Reactions
248 Views
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

Hello, and thank you in advance!  I just got a new job (1 month now), and we migrated, so our emails and logins are all different (one company name to another).  And during the process, we got double emails on everything.  And all of our documents doubled.  So it is just a nightmare.  I am trying to clean up, and I would like to be able to offer this macro to the team as well so they can do easy clean-ups on their computer.  I want to be able to:

1.  BROWSE to select the folder

2.  Look at ALL folders, sub-folders and every additional folder in the hierarchy

3.  Have all files containing " - Copy." (regardless of what the file extension is) deleted

This is what i have so far.  It does work, however, I must do each folder separately, and the folder path is hard-coded, so it is not what I want/need.

Sub CleanDupesCopy()

'Delete all .xlsx files using the * wildcard character
Kill "C:UsersbarneshOneDrive - HIIDocumentsHIITrainingOnboarding* - Copy.*"

End Sub

 
Posted : 28/11/2024 3:14 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Sherry,

I'd try using the Command Prompt rather than VBA for this.

See if del "C:UsersbarneshOneDrive - HIIDocumentsHIITrainingOnboarding* - Copy.*" /s does the trick

If you open a Cmd Prompt and navigate to the Onboarding (or any other) folder you could just use

del "* - Copy.*" /s

Note that I haven't tested this but think it should work.  Please test it yourself before using.

You can always add a /p flag to the command to make it prompt for confirmation before doing any deletions.

Regards

Phil

 
Posted : 28/11/2024 11:55 pm
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Philip Treacy,

Thanks so much, that was a great solution.  I never thought of using the command prompt.  All my duplicates are gone (about 15K files or so!).  Problem solved.  It was easy and painless, thanks again!

 
Posted : 30/11/2024 11:40 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

no worries 🙂

 
Posted : 30/11/2024 8:38 pm
Share: