Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

delete specific jpg files from folders and subfolders using Excel VBA

Dear Experts:

I understand that it is possible to delete files from a folder using Excel VBA

I am running Excel 2010 on Windows 7

I would like to delete specific jpg files from a directory with many folders and subfolders. The directory's name is ...
... C\Graphics\...

The jpg files that are to be deleted are only those that have the following characters at the end:

_h.jpg or _n.jpg, i.e. for example 90-147-58-30_h.jpg or 94-111-24-39_n.jpg. All other jpg files that do not match these criteria are not to be touched.

Help is very much appreciated. Thank you very much in advance.

Kind regards, Andreas
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

So just to make sure if i understand this correctly you want to delete all the jpg files from folder and sub-folder which ends with h or n?

Is my understanding correct?

Saurabh..
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andreas Hermle

ASKER

Hi Saurabh,

yes you are right, that is exactly what I want.

Thank you. Regards, Andreas
Hi Olemo,

thank you very much for your professional help. I am sure that your DOS-command works just fine, but I am afraid to tell you that I use Windows 7 64 bit and I understand that DOS-command won't run on a Windows 7 64 bit system.

I got a workaround (http://windows.microsoft.com/en-us/windows7/install-and-use-windows-xp-mode-in-windows-7) but as a matter of fact I do not want to install anything (Windows XP Mode, and Windows Virtual PC).

Thank you again for your great help. Regards, Andreas
You were mislead by my usage of "DOS" - it's used sometimes for the good old-fashioned batch file stuff, as I used it here. I meant "cmd.exe batch". Start a command prompt, and try my code.
Doing that in VBA or VBS requires much more of code.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See what I mean? ;-)
Hi Qlemo, I am currently trying your DOS command.

Am I right, I press the Windows Key + R to bring up the Run Window. And then I enter cmd.exe to launch the command prompt. The window in the command prompt says: C:\Users\Andreas>

I then enter your command prompt right after the 'greater than' sign, am I right?

Regards, andreas and thank you very much for your help.
Hi ProfJimJam,

great coding, I am really impressed, works just fine. Thank you very much for it.

I will try Qlemo's command prompt and then award the points.

Again, thank you very much for your swift and professional support. Regards, Andreas
Exactly. Make sure to change the path (two times) to a test folder, the command will really delete files!
Qlemo, thank you very much for your help. Will make the testing this evening, hence it'll be tonight when I award points.

ProfJimJam, again thank you very much for your superb code.

Regards, Andreas
Dear Qlemo,

works really great, thank you very much for your professional support. I really appreciate it.

Dear Qlemo and ProfJimJam,

Since I was initially asking for a VBA solution, I will award more points to ProfJimJam.

You both deserve 500 points, but regrettably this is not possible. Again, thank you very much for your superb, swift and professional help. This forum has saved me days and months of tedious and exhausting work.

Have a nice day, regards, Andreas
Avatar of Professor J
Professor J

Thank you Andreas for your nice feedback
Wish you a nice day too
Regards