ravelogic Posted August 9, 2009 Report Share Posted August 9, 2009 Hey!I have about 16GB of files (over 11,000) in a folder and most of them are unneeded. The only ones I need have a certain sequence of characters in the file name. How do I delete all files that don't contain this sequence using a batch file? Although, if this can be done easier in the command line I'd like to know how as well.Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ravelogic Posted August 10, 2009 Author Report Share Posted August 10, 2009 After a couple more hours of searching the internet, I have found a batch file that does the trick::: DELE.bat:: Deletes Current Directory Entries Except for Specified Files:: Wildcards (* and ?) may be Used in File Names:: (Hidden, System, and Read-Only Files are Not Affected)::@ECHO OFFIF "%1" == "" GOTO ENDMD SAVE:MOVE-FILESXCOPY %1 SAVE > NULSHIFTIF "%1" == "" GOTO FILES-DELETEGOTO MOVE-FILES:FILES-DELETEECHO Y | DEL . > NULMOVE SAVE\*.* . > NULRD SAVEDR:ENDhttp://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv1.html#DELEThanks anyway. Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted August 10, 2009 Report Share Posted August 10, 2009 Thanks for the feedback! Do you know what the 'DR' command near the end of the script does? Quote Link to comment Share on other sites More sharing options...
ravelogic Posted August 10, 2009 Author Report Share Posted August 10, 2009 I think it's supposed to return the results but it doesn't do anything except give an error about it being an unknown command.Maybe it's just a typo and it should have been DIR? Quote Link to comment Share on other sites More sharing options...
PatrickMc Posted August 24, 2009 Report Share Posted August 24, 2009 Hey!I have about 16GB of files (over 11,000) in a folder and most of them are unneeded. The only ones I need have a certain sequence of characters in the file name. How do I delete all files that don't contain this sequence using a batch file? Although, if this can be done easier in the command line I'd like to know how as well.Thanks in advance.I will assume the following.1. The path to the folder is C:\folder. This folder contains the 16 GB files.2. The sequence of chars you are looking for is, to make it more general, "k0\naP l\nk<any number of unprintable characters>Q". (k0 followed by newline, then aP, a space, I, a new line, nk, any number of spaces/tabs etc.)3. Files are text files.Here is the script# script delete_no_sequence.txt# Collect the list of all files.var str list; lf -n "*" "C:\folder" > $list# Process one file at a time.while ($list <> "")do # Get the next file. var str file; lex "1" $list > $file # Read file into a string variable. var str content; cat $file > $content # Does the content contain our sequence ? if ( { sen -r "^k0\naP l\nk;Q^" $content } <= 0 ) # No, content does NOT contain the sequence of characters. Delete this file. system delete ("\""+$file+"\"") endifdoneScript is in biterscripting ( http://www.biterscripting.com ). We are using -r option to indicate regular expression with the sen command (string enumerator/counter). We are using ; (semicolon) to indicate any number of spaces/tabs/etc. . To try the script, save the script as C:\Scripts\delete_no_sequence.txt, start biterscripting, enter the following command.script -l delete_no_sequence.txtI have not been able to test. Test it first with test folder and test files.Patrick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.