Solved

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

Posted on 2009-04-02
3
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

695 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