Wednesday, March 28, 2012

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

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
Message posted via http://www.webservertalk.comYou could also loop through all the files, checkif they EndsWith(".csv") if
not, delete them.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"chris yoker via webservertalk.com" <forum@.nospam.webservertalk.com> wrote
in message news:86e839cf6238492484f4c941524b48a4@.Do
webservertalk.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
> --
> Message posted via http://www.webservertalk.com

0 comments:

Post a Comment