Delete all CSV files except for 1 specifid CSV file

I would like to use a simple script  to delete all *.csv files found in C:\Temp1\...  except for one file called Output.csv

It would be in Batch, .ps1 or vbs..

Thanks in advance.
100questionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
In test mode; remove the -WhatIf to run it for real:
Get-ChildItem C:\Temp1 -Filter *.csv | Where-Object {$_.BaseName -ne 'output'} | Remove-Item -Force -WhatIf

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oBdACommented:
For the fun of it, here's a cmd.exe version, for immediate execution in a command prompt.
As before in test mode; remove the uppercase ECHO to run it for real:
for %a in ("C:\Temp1\*.csv") do @(if /i not "%~na"=="Output" ECHO del "%~a")

Open in new window

For a batch script, double up on those percent signs of the loop variable:
for %%a in ("C:\Temp1\*.csv") do @(if /i not "%%~na"=="Output" ECHO del "%%~a")

Open in new window

0
Julian HansenCommented:
You can do it in one - but a potentially safer method would be to break your script into 3 parts
1. Rename the file to .preserve
2. Remove all .csv files
3. Rename the file back again

This has the added advantage that your delete does not have to be updated if names change or you want to expand to include additional names.
0
100questionsAuthor Commented:
Thanks very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.