Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Delete files based on dup names

Reply
 
Old 07-16-2009   #1 (permalink)
newbie2


 
 

Delete files based on dup names

I have a set of xls and csv files, sometimes the names, except the extension,
are identicle. How do I delete excel files with duplicate names?

Example: I have three files in a folder.
File1.xls
File1.csv
File2.xls

I need to delete File1.xls and retain the other two.

My System SpecsSystem Spec
Old 07-16-2009   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Delete files based on dup names

You need to be more specific on how we choose which to keep. If there's dup
names, do we keep the newest file or if there's dup names, we *always*
delete the .xls file and keep the .csv, for example...

Marco

"newbie2" <newbie2@xxxxxx> wrote in message
news:261959AA-F913-4A36-9090-7DB265DE5288@xxxxxx
Quote:

> I have a set of xls and csv files, sometimes the names, except the
> extension,
> are identicle. How do I delete excel files with duplicate names?
>
> Example: I have three files in a folder.
> File1.xls
> File1.csv
> File2.xls
>
> I need to delete File1.xls and retain the other two.
My System SpecsSystem Spec
Old 07-16-2009   #3 (permalink)
newbie2


 
 

Re: Delete files based on dup names

Thanks for reply. I should make it more clear.

If a dup name is found, I'd always keep csv file, and delete xls file.
Timestamp on the file bears no significance.

"Marco Shaw [MVP]" wrote:
Quote:

> You need to be more specific on how we choose which to keep. If there's dup
> names, do we keep the newest file or if there's dup names, we *always*
> delete the .xls file and keep the .csv, for example...
>
> Marco
>
> "newbie2" <newbie2@xxxxxx> wrote in message
> news:261959AA-F913-4A36-9090-7DB265DE5288@xxxxxx
Quote:

> > I have a set of xls and csv files, sometimes the names, except the
> > extension,
> > are identicle. How do I delete excel files with duplicate names?
> >
> > Example: I have three files in a folder.
> > File1.xls
> > File1.csv
> > File2.xls
> >
> > I need to delete File1.xls and retain the other two.
>
>
My System SpecsSystem Spec
Old 07-16-2009   #4 (permalink)
Marco Shaw [MVP]


 
 

Re: Delete files based on dup names



"newbie2" <newbie2@xxxxxx> wrote in message
news:F470CA18-2901-431A-891C-AA11184E5743@xxxxxx
Quote:

> Thanks for reply. I should make it more clear.
>
> If a dup name is found, I'd always keep csv file, and delete xls file.
> Timestamp on the file bears no significance.
Does this need to be run recursively?

Try this:
PS>dir|group basename|foreach{if($_.count -gt 1){remove-item
($_.name+".xls") -whatif}}

Now, I think the basename property only exists if you're running PowerShell
v2...

If the above works for you, just remove "-whatif" to actually make it remove
the file(s).

Marco

My System SpecsSystem Spec
Old 07-17-2009   #5 (permalink)
Hans Dingemans


 
 

Re: Delete files based on dup names

>>> > Now, I think the basename property only exists if you're running
Quote:
Quote:
Quote:

>>> > PowerShell v2...

Nope, also available in V1.0 ( defined as:
[System.IO.Path]::GetFileNameWithoutExtension($this) )


"Marco Shaw [MVP]" <marco.shaw@xxxxxx_SPAMgmail.com> wrote in message
news:Oj1VgGoBKHA.3724@xxxxxx
Quote:

>
>
> "newbie2" <newbie2@xxxxxx> wrote in message
> news:F470CA18-2901-431A-891C-AA11184E5743@xxxxxx
Quote:

>> Thanks for reply. I should make it more clear.
>>
>> If a dup name is found, I'd always keep csv file, and delete xls file.
>> Timestamp on the file bears no significance.
>
> Does this need to be run recursively?
>
> Try this:
> PS>dir|group basename|foreach{if($_.count -gt 1){remove-item
> ($_.name+".xls") -whatif}}
>
> Now, I think the basename property only exists if you're running
> PowerShell v2...
>
> If the above works for you, just remove "-whatif" to actually make it
> remove the file(s).
>
> Marco
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can some help? cannot delete files as 'names too long for filesystem' General Discussion
Re: CAn some help? cannot delete files as 'names too long for filesystem' Vista General
unable to delete Names of files after deleted files. Vista mail
Delete files based on last accessed date? PowerShell
Delete based on date PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46