Solved

Need batch file to delete all files but jpg and flv extensions

Posted on 2009-04-02
3
329 Views
Last Modified: 2013-11-10
Hello all, need a batch file to loop through a folder and delete all file types but .flv and .jpg

Thank you
0
Comment
Question by:details212
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 24053017
This should work - change the folder name and remove the 'echo' from the last command line if it displays as you anticipate
setlocal enabledelayedexpansion
cd /d f:\test
for /f %%a in ('dir /a-d /b') do (
  set file=%%~fa
  set filename=%%a
  set fileext=%%~xa
  If not [!fileext!==[.flv (
    If not [!fileext!==[.jpg (
      echo erase !filename!
    )
  )
)

Open in new window

0
 
LVL 6

Expert Comment

by:IKZ
ID: 24053041
When you make your batch file- use the *.flv and *.jpg as your wild cards. Or set it up to move all *.flv and *.jpg files to a temporary directory- then delete all remaing files in the folder, then move all files back from the temp directory.  Let me know if you need more guidance.
0
 

Author Closing Comment

by:details212
ID: 31565926
Perfection, Thank you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question