Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to program a message that tells me if there is one or more cvs file present in the zip file and gives me the number of files contained in this zip. Thanks in advance

What I have tried:

var = comboBox1.SelectedItem.ToString();
fullpath = fbd.SelectedPath + "\\"+ var;

comboBox2.Items.Clear();
if (File.Exists(fullpath))
{
ZipArchive zip = ZipFile.OpenRead(fullpath);
MessageBox.Show(Directory.EnumerateFileSystemEntries(fullpath, "*.csv").ToList<string>().Count + " csv file(s) present"); // get error here
foreach (ZipArchiveEntry entry in zip.Entries)
{
comboBox2.Items.Add(entry.FullName); // fill comboBox2 with *.csv files from selected zip file
}
zip.Dispose();
}
else
{
MessageBox.Show("no csv file(s) present");
}
Posted
Comments
Garth J Lancaster 1-Mar-17 2:41am    
Why are you using Directory.Enumerate ? That is a 'local' directory in your machine - your question leads me to believe you wish to inspect the zip file .. in which case

int numAllFiles = 0;
int numCSVFiles = 0;
foreach (ZipArchiveEntry entry in zip.Entries)
{
if (entry.FullName.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
numCSVFiles += 1;
}
numAllFiles += 1;
}

// Test numCSVFiles == 0 etc
Member 12558924 1-Mar-17 3:48am    
Thanks first for your help. Please can you really tell me what i should use instead Directory.EnumerateFileSystemEntries so that it can count how much csv file are contained in zip file?
Garth J Lancaster 1-Mar-17 4:06am    
I gave you code
Member 12558924 1-Mar-17 4:37am    
yes l saw your code but what about the messagebox? i want to use it
Garth J Lancaster 1-Mar-17 4:52am    
we aren't a code-writing service - you have to be prepared to dig in and work yourself - you have messagebox code in your initial sample - adapt, research, but dont be a help vampire

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900