Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: deleting multiple files with batch  (Read 3557 times)

0 Members and 1 Guest are viewing this topic.

Khasiar

    Topic Starter


    Intermediate

    deleting multiple files with batch
    « on: April 23, 2009, 11:07:39 PM »
    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.

    1.mp3 1mb
    1.mp3 1mb

    like to delete all but one..

    thanks

    quaxo



      Guru
    • Thanked: 127
      • Yes
    • Computer: Specs
    • Experience: Guru
    • OS: Windows 11
    Re: deleting multiple files with batch
    « Reply #1 on: April 23, 2009, 11:12:28 PM »
    I'd move the one you want out of the directory, then empty the directory (del *.*). After that, you can move the one back.

    Khasiar

      Topic Starter


      Intermediate

      Re: deleting multiple files with batch
      « Reply #2 on: April 23, 2009, 11:16:04 PM »
      yea, thats ok with just 1 file, but im talking over 1000 with over 300 directories. you can see my problem

      Dusty



        Egghead

      • I could if she would, but she won't so I don't.
      • Thanked: 75
      • Experience: Beginner
      • OS: Windows XP
      Re: deleting multiple files with batch
      « Reply #3 on: April 24, 2009, 02:23:01 AM »
      Need to get some idea of your directory tree.
      One good deed is worth more than a year of good intentions.

      quaxo



        Guru
      • Thanked: 127
        • Yes
      • Computer: Specs
      • Experience: Guru
      • OS: Windows 11
      Re: deleting multiple files with batch
      « Reply #4 on: April 24, 2009, 03:09:49 AM »
      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.

      Hey guyz, im trying to delete the copies of my songs in a directory.

      like to delete all but one..

      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?

      Reno



        Hopeful
      • Thanked: 32
        Re: deleting multiple files with batch
        « Reply #5 on: April 24, 2009, 03:28:33 AM »
        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?

        gh0std0g74



          Apprentice

          Thanked: 37
          Re: deleting multiple files with batch
          « Reply #6 on: April 24, 2009, 05:48:15 AM »
          ok. same file names in the same directory? possible on windows file system?

          Dias de verano

          • Guest
          Re: deleting multiple files with batch
          « Reply #7 on: April 24, 2009, 05:54:44 AM »
          ok. same file names in the same directory? possible on windows file system?

          Is your question rhetorical?

          macdad-



            Expert

            Thanked: 40
            Re: deleting multiple files with batch
            « Reply #8 on: April 24, 2009, 06:15:08 AM »
            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.
            If you dont know DOS, you dont know Windows...

            Thats why Bill Gates created the Windows NT Family.

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: deleting multiple files with batch
              « Reply #9 on: April 24, 2009, 06:25:27 AM »
              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 ).

              quaxo



                Guru
              • Thanked: 127
                • Yes
              • Computer: Specs
              • Experience: Guru
              • OS: Windows 11
              Re: deleting multiple files with batch
              « Reply #10 on: April 24, 2009, 10:04:51 AM »
              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.

              Khasiar

                Topic Starter


                Intermediate

                Re: deleting multiple files with batch
                « Reply #11 on: April 26, 2009, 03:44:28 AM »
                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 ;)

                gh0std0g74



                  Apprentice

                  Thanked: 37
                  Re: deleting multiple files with batch
                  « Reply #12 on: April 26, 2009, 04:30:24 AM »
                  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..

                  quaxo



                    Guru
                  • Thanked: 127
                    • Yes
                  • Computer: Specs
                  • Experience: Guru
                  • OS: Windows 11
                  Re: deleting multiple files with batch
                  « Reply #13 on: April 26, 2009, 04:52:58 AM »
                  Ahhh ok.

                  If you're running Windows, might be easier to use something like this:
                  http://www.snapfiles.com/get/dupfilefinder.html

                  Khasiar

                    Topic Starter


                    Intermediate

                    Re: deleting multiple files with batch
                    « Reply #14 on: April 29, 2009, 03:40:50 PM »
                    Thanks quaxo im pretty sure this is excatly what i wanted, using it now so ill let you know if it works laters ..


                    cheers

                    Khasiar