Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delete duplicate files

97 views
Skip to first unread message

OldDog

unread,
Nov 30, 2008, 10:33:16 PM11/30/08
to
I have a directory with over 1000 mp3 files. Somehow I wound up with
two each of everything. Is there a way to go through the directory and
all its subs and delete any duplicate files? The files appear to be
identical in every way. So I guess I would like to;

check each file, and if another one exist with the same name, delete
it.

Thanks,

OldDog

Keith Hill [MVP]

unread,
Dec 1, 2008, 12:07:47 AM12/1/08
to
The trick is deciding which one to keep and which ones to delete.  However to find dupes in a directory structure try this:

PS> gci . *.txt -r  | ?{!$_.PSIsContainer} |
    %{$files=@{}}{if ($files[$_.name]) {$obj = new-object psobject;$obj |
        add-member NoteProperty Path $_.fullname;$obj |
        add-member NoteProperty Original $files[$_.name]; $obj}
        else {$files[$_.name]=$_.fullname}} | ft -groupby Original Path
 
 
 
If the output looks good and you are comfortable with what is showing up in the "Path" field on the output, then remove the "ft -groupby Original path" part and replace it with "remove-item -whatif".  After you have examined what will be deleted and are comfortable with that, then remove the -whatif and let 'er rip.
 
HTH
--
Keith
 

"OldDog" <mike...@comcast.net> wrote in message news:5a1aabcd-528d-4706...@k36g2000yqe.googlegroups.com...

IT Staff

unread,
Dec 1, 2008, 12:31:08 AM12/1/08
to
I am just curious,

Does the windows OS allows for duplicate filenames ? Or you are refering to
the contents ?

"OldDog" <mike...@comcast.net> wrote in message
news:5a1aabcd-528d-4706...@k36g2000yqe.googlegroups.com...

tojo2000

unread,
Dec 1, 2008, 4:58:35 AM12/1/08
to
On Nov 30, 9:31 pm, "IT Staff" <jkk...@hotmail.com> wrote:
> I am just curious,
>
> Does the windows OS allows for duplicate filenames ? Or you are refering to
> the contents ?
>
> "OldDog" <mikef2...@comcast.net> wrote in message

>
> news:5a1aabcd-528d-4706...@k36g2000yqe.googlegroups.com...
>
> >I have a directory with over 1000 mp3 files. Somehow I wound up with
> > two each of everything. Is there a way to go through the directory and
> > all its subs and delete any duplicate files? The files appear to be
> > identical in every way. So I guess I would like to;
>
> > check each file, and if another one exist with the same name, delete
> > it.
>
> > Thanks,
>
> > OldDog

You can't have duplicate filenames within the same directory, but
within subdirectories is fine.

OldDog

unread,
Dec 1, 2008, 9:34:12 PM12/1/08
to
> within subdirectories is fine.- Hide quoted text -
>
> - Show quoted text -

Thanks , that worked very well. And yes, they were all in the Music
directory, but in different sub directories.

adamjean

unread,
Sep 28, 2009, 5:15:26 AM9/28/09
to
There are many tools available on google to <a href="http://www.duplicate-finder-pro.com/delete-duplicate-files.htm">duplicate delete files</a> from the drives, i use duplicate finder 2009 to delete duplicate MP3 from my music library.

Find Here : http://www.duplicate-finder-pro.com/duplicate-mp3-finder.htm

OldDog wrote:

Delete duplicate files
02-Dec-08

Thanks,

OldDog

EggHeadCafe - Software Developer Portal of Choice
WPF DataGrid Custom Paging and Sorting
http://www.eggheadcafe.com/tutorials/aspnet/8a2ea78b-f1e3-45b4-93ef-32b2d802ae17/wpf-datagrid-custom-pagin.aspx

adamjean

unread,
Sep 28, 2009, 5:16:36 AM9/28/09
to
There are many tools available on google to <a href="http://www.duplicate-finder-pro.com/delete-duplicate-files.htm">duplicate delete files</a> from the drives, i use duplicate finder 2009 to delete duplicate MP3 from my music library.

Find Here : http://www.duplicate-finder-pro.com/duplicate-mp3-finder.htm

OldDog wrote:

Delete duplicate files
02-Dec-08

I have a directory with over 1000 mp3 files. Somehow I wound up with

Thanks,

OldDog

EggHeadCafe - Software Developer Portal of Choice

adamjean

unread,
Sep 28, 2009, 5:16:03 AM9/28/09
to
There are many tools available on google to <a href="http://www.duplicate-finder-pro.com/delete-duplicate-files.htm">duplicate delete files</a> from the drives, i use duplicate finder 2009 to delete duplicate MP3 from my music library.

Find Here : http://www.duplicate-finder-pro.com/duplicate-mp3-finder.htm

OldDog wrote:

Delete duplicate files
02-Dec-08

I have a directory with over 1000 mp3 files. Somehow I wound up with

Thanks,

OldDog

EggHeadCafe - Software Developer Portal of Choice

adamjean

unread,
Sep 28, 2009, 5:14:52 AM9/28/09
to
There are many tools available on google to <a href="http://www.duplicate-finder-pro.com/delete-duplicate-files.htm">duplicate delete files</a> from the drives, i use duplicate finder 2009 to delete duplicate MP3 from my music library.

Find Here : http://www.duplicate-finder-pro.com/duplicate-mp3-finder.htm

OldDog wrote:

Delete duplicate files
02-Dec-08

I have a directory with over 1000 mp3 files. Somehow I wound up with

Thanks,

OldDog

EggHeadCafe - Software Developer Portal of Choice

Shay Levy [MVP]

unread,
Sep 28, 2009, 7:59:07 AM9/28/09
to
Hi Adam,

You can group all files by name, filter groups with count greater than one
and delete all files of a group (execpt for one):


dir <root_path> -recurse -filter *.mp3 | group-object -property name | where
{$_.count -gt 1} | foreach {
$files = $_.group
$files[1..$files.length] | remove-item -whatIf -force
}


Remove -whatIf to actually delete the files. With powershell 2.0 you can
skip the first file of the group:


dir <root_path> -recurse -filter *.mp3 | group-object -property name | where
{$_.count -gt 1} | foreach {
$_.group | select-object -skip 1 | remove-item -whatIf -force
}


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar

AJ> There are many tools available on google to <a
AJ> href="http://www.duplicate-finder-pro.com/delete-duplicate-files.htm
AJ> ">duplicate delete files</a> from the drives, i use duplicate finder
AJ> 2009 to delete duplicate MP3 from my music library.
AJ>
AJ> Find Here :
AJ> http://www.duplicate-finder-pro.com/duplicate-mp3-finder.htm
AJ>
AJ> OldDog wrote:
AJ>
AJ> Delete duplicate files
AJ> 02-Dec-08
AJ> I have a directory with over 1000 mp3 files. Somehow I wound up with
AJ> two each of everything. Is there a way to go through the directory
AJ> and all its subs and delete any duplicate files? The files appear to
AJ> be identical in every way. So I guess I would like to;
AJ>
AJ> check each file, and if another one exist with the same name, delete
AJ> it.
AJ>
AJ> Thanks,
AJ>
AJ> OldDog
AJ>
AJ> EggHeadCafe - Software Developer Portal of Choice
AJ>
AJ> WPF DataGrid Custom Paging and Sorting
AJ>
AJ> http://www.eggheadcafe.com/tutorials/aspnet/8a2ea78b-f1e3-45b4-93ef-
AJ> 32b2d802ae17/wpf-datagrid-custom-pagin.aspx
AJ>


CodFather

unread,
Nov 13, 2009, 10:26:06 AM11/13/09
to
Hi Shay,

Sorry to bother you but I am up the creek and looking for a paddle.

Short Version) I need to copy or move all of the files that dont exist in
one folder and subdirectories to another folder and subdirectories while
maintaining directory structure and not disturbing any files in the first
folder and its subdirectories.


Long Version) I was using OneCare to back up my files and several months ago
I had trouble with the drive and ended up updating several components in my
system. I couldn't properly restore the backup because my drive assignments
had changed and the only workaround with onecare is to have the files
restored to a different location with a similar directory structure. I tried
Customer support but they were unable to help me on 3 occasions. I have
restored 3 seperate backups to a restore directory on my pc and have copied
files back into my Documents folder as I have needed them.

The end result is an awful mess.

Here is an example of the directory structure used by onecare for the restore.

Drive:\Documents and Settings\All
Users\Documents\Restore\11-13-2009\PCNAME\USERNAME\Email Files\Other Email
Files\00294823-00000001.eml

Within the Restore folder there are 3 folders which are named by the date of
the restore as in the example above. Some of the files in these restores
exist in my current documents folder and subdirecties and some do not exist.
I need to copy or move all of the files that dont exist in my documents and
subdirectories from the restore and subdirectories whithout disturbing any
files that exist in my current documents and subdirectories.

If I just drag the the My pictures folder from a restore into my documents
folder it will overwrite the folder and I will lose any new pictures that I
have taken. If I go into the My pictures folder from the restore and Select
all pictures and move them to the my new folder it is okay. I would then
have to go into each subdirectory and do the same thing hundreds of times.

There are no doubt other complexities that I havent even thought of. I cant
think of an easy way out if this. IT would be easy if I didnt care where the
files ended up. I could just create a set of folders PICS VIDS MP3 PDF and
do a search and then sort by file type and move them all into the
corresponding folder and then delete the duplicates. Then my work photos
would be mixed in with my personal photos and files from different projects
mixed in together....not good.

If you have any ideas I would really appreciate it.

Sean

Shay Levy [MVP]

unread,
Nov 22, 2009, 3:09:37 PM11/22/09
to
Hi CodFather,

Sorry for the LATE reply! It seems to me that what you need is a folder sync
application/script. Have you heard of Microsoft SyncToy?
Anyhow, try this script from Brandon http://bsonposh.com/archives/231


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar

C> Hi Shay,
C>
C> Sorry to bother you but I am up the creek and looking for a paddle.
C>
C> Short Version) I need to copy or move all of the files that dont
C> exist in one folder and subdirectories to another folder and
C> subdirectories while maintaining directory structure and not
C> disturbing any files in the first folder and its subdirectories.
C>
C> Long Version) I was using OneCare to back up my files and several
C> months ago I had trouble with the drive and ended up updating several
C> components in my system. I couldn't properly restore the backup
C> because my drive assignments had changed and the only workaround with
C> onecare is to have the files restored to a different location with a
C> similar directory structure. I tried Customer support but they were
C> unable to help me on 3 occasions. I have restored 3 seperate backups
C> to a restore directory on my pc and have copied files back into my
C> Documents folder as I have needed them.
C>
C> The end result is an awful mess.
C>
C> Here is an example of the directory structure used by onecare for the
C> restore.
C>
C> Drive:\Documents and Settings\All
C> Users\Documents\Restore\11-13-2009\PCNAME\USERNAME\Email Files\Other
C> Email Files\00294823-00000001.eml
C>
C> Within the Restore folder there are 3 folders which are named by the
C> date of the restore as in the example above. Some of the files in
C> these restores exist in my current documents folder and subdirecties
C> and some do not exist. I need to copy or move all of the files that
C> dont exist in my documents and subdirectories from the restore and
C> subdirectories whithout disturbing any files that exist in my current
C> documents and subdirectories.
C>
C> If I just drag the the My pictures folder from a restore into my
C> documents folder it will overwrite the folder and I will lose any new
C> pictures that I have taken. If I go into the My pictures folder from
C> the restore and Select all pictures and move them to the my new
C> folder it is okay. I would then have to go into each subdirectory
C> and do the same thing hundreds of times.
C>
C> There are no doubt other complexities that I havent even thought of.
C> I cant think of an easy way out if this. IT would be easy if I didnt
C> care where the files ended up. I could just create a set of folders
C> PICS VIDS MP3 PDF and do a search and then sort by file type and
C> move them all into the corresponding folder and then delete the
C> duplicates. Then my work photos would be mixed in with my personal
C> photos and files from different projects mixed in together....not
C> good.
C>
C> If you have any ideas I would really appreciate it.
C>
C> Sean
C>
C> "Shay Levy [MVP]" wrote:
C>

Martin Zugec

unread,
Nov 25, 2009, 3:08:46 PM11/25/09
to
Hi,

for such tasks, I still prefer to use robocopy instead of Posh itself :(

Martin

"CodFather" <CodF...@discussions.microsoft.com> wrote in message
news:E858D43B-9240-4A6B...@microsoft.com...

0 new messages