Saved Bookmarks
| 1. |
Solve : deleting multiple files with batch? |
|
Answer» Hey guyz, im trying to delete the copies of my songs in a directory. i got alot of files with the same file name and its annoying trying to delete one by one, eg. yea, thats ok with just 1 file, but im talking over 1000 with over 300 directories. Originally you wanted to save one file in a directory. Quote from: Khasiar on April 23, 2009, 11:07:39 PM Hey guyz, im trying to delete the copies of my songs in a directory. Could you EXPLAIN a little more of what you mean to accomplish as well as, like Dusty said, describing the directory tree that contains these files you want to delete?The following will do binary compare: ------------------------------------ 1. Traverse all the directory and save the listing to a temp file 2. SORT temp file by file size 3. for each files with the same size, do file compare fc.exe/b song1.mp3 song2.mp3 The following will do file name check: ----------------------------------- 1. Traverse all the directory and save the listing to a temp file 2. sort temp file by file name 3. for each files with the same name, delete duplicate(s) which one are you after?ok. same file names in the same directory? possible on windows file system?Quote from: gh0std0g74 on April 24, 2009, 05:48:15 AM ok. same file names in the same directory? possible on windows file system? Is your question rhetorical? That would cause an ERROR if some of the files have exact duplicates in the same directory when you try to use MOVE, or copy.i was actually trying to ask if OP's duplicate files are in different folders or not, because AFAIK(am not a windows expert) , wouldn't the OS give error you there are same file name ( case insensitive ).No idea at this point. First it sounded like 1 file of many in a directory, now it's 1000 files over 300 directories. In either case, it's impossible for two identical files with identical names to exist in the same directory.Sorry to confuse everyone, the main situation is that i have many files that are the same in different directories. eg c:\music\artist\123.mp3 c:\music\favs\123.mp3 c:\music\mymusic\123.mp3 c:\music\hismusic\123.mp3 problem is, ive copied most of them, and when i look in my media library i see doubles, triples and even up to 5 times the same song.... i know what was i thinking lol... but this was my first attempt of trying to arrange my files in a somewhat orderly manner by artist etc... and its a horrible mess... any help would be great... Khasiar if you have Perl and can use it. Uses MD5 to check for file duplicates. Code: [Select]use Digest::MD5; use File::Find; use File::Copy; my %seen; my $destination = "c:/tmp"; sub getmd5 { my $file = $_[0]; open(FH,"<",$file) or die "Cannot open file: $!\n"; binmode(FH); my $md5 = Digest::MD5->new; $md5->addfile(FH); return $md5->hexdigest; close(FH); } sub wanted { if ( -f $_ && /\....$/ ){ my $file = $File::Find::name; my $md5 = getmd5 $file; if ( defined($seen{$md5}) ){ # duplicates print "duplicate $file" . "=>" . $md5 ." \n"; unlink $file or die "Cannot remove $file:$!\n"; }else{ $seen{$md5} = $file; } } } my $dir = "c:/test"; # Traverse desired directory File::Find::find({wanted => \&wanted}, $dir); foreach my $v (values %seen){ print "\$v: $v\n"; move ("$v", "$destination" ) or warn "Cannot move file to destination:$!\n"; } alternatively, if you want to do in batch, you can use fc command, for loop, doing some if else check etc etc.. Ahhh ok. If you're running Windows, might be easier to use something like this: http://www.snapfiles.com/get/dupfilefinder.htmlThanks quaxo im pretty sure this is excatly what i wanted, using it now so ill let you know if it works laters .. cheers Khasiar |
|