Solved

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

Posted on 2009-04-02
3
330 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

856 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