Script to locate PDF's files from computer and delete them

SavindraSingh
SavindraSingh used Ask the Experts™
on
Team,

I am looking at a script which can auto locate PDF's files from computer and delete them .
PDF files are located on my documents, desktop and some time on C drive.  

Thank Nammi.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
for mydocs and desktop:

del %USERPROFILE%\"my documents"\*.pdf /s
del %USERPROFILE%\desktop\*.pdf /s

for C drive either delete all pdf's on the c drive with
del c:\*.pdf /s

or speficy the folders

Commented:
If you can use powershell you may try this inline

get-childitem DRIVE: -r | ? {$_.extension -eq ".pdf"} | foreach {remove-item -force $_.FullName}

Open in new window

Just change "DRIVE" to you drive letter.
This command will delete ALL pdfs on you drive to wich it will get access.

If you want to use cmd then this could work for you

for /f "tokens=*" %a in ('where /r DIRVE:\ *.pdf') Do del /q /f %a

Open in new window

You might want to run
C:\>dir *.pdf /s
first and see just what you'll be deleting... I came up with over 4GB of PDFs, with many of them being documentation in C:\Program Files\* and C:\Program Files (x86)\* folders.

Author

Commented:
Thanks for all, I like all the answers.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial