System.IO: best approach for clearing a DIR of all files except .CSV

  • Thread starter chris yoker via DotNetMonster.com
  • Start date
C

chris yoker via DotNetMonster.com

hiya,
I have a DIR that should only accept .CSV files..I haven't found a way to
do this prorgramatically.

ATM, I:
1) obtain an array of all the files that contain a .CSV extension.
2) move these files to another dir.

I check to see if there are any NON-CSV files in the dir by the following:

<code>
If arrAllFiles.Length = arrCsvFiles.Length Then
'do nothing, as this DIR only contained CSV files.
Else
'delete ALL the files in this dir, as the CSV files have already been
moved.
'The remaining files are therefore, NON-CSV
End If
<\code>

Is this a good approach?Or maybe there is a slicker way to achieve what I
am trying to do / maybe there are some utilities out there that already do
all the system.IO stuff?

All thoughts appreciated.

many thanks
yogi
 
K

Karl Seguin

You could also loop through all the files, checkif they EndsWith(".csv") if
not, delete them.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top