Reputation: 919
I've got some strange behavior during execution in a ASP.NET application.
It doesn't matter if I set workingFolder (see code below) to System.IO.Path.GetTempPath
or any other public folder (current case).
I receive a ZIP file, unpack that file (using SharpZipLib) and try to digest the files in that folder, but the System.IO GetFiles
returns an empty list.
I've tried to use DirectoryInfo.GetFiles
and Directory.GetFiles
: both an empty list.
If I breakpoint on the Directory.Delete
and look at the folder I can see the files, they're not locked and I can do anything with the files - even if I set the "run from cursor" point at the beginning of the foreach
no luck - the GetFiles still return an empty list (although I can see the files in explorer).
private const string EXTENSION_LOG_FILE = ".txt";
private const string VALID_EXTENSION_MASK = "*." + EXTENSION_LOG_FILE;
var zipFolder = unpackZip(filePath, workingFolder);
foreach (var zipFileInfo in new DirectoryInfo(zipFolder).GetFiles(VALID_EXTENSION_MASK, SearchOption.TopDirectoryOnly))
{
// never get's here
value.AddRange(getLogItems(zipFileInfo.FullName));
File.Delete(zipFileInfo.FullName);
}
// this fails: folder is not empty
Directory.Delete(zipFolder);
and the unpackZip method:
private static string unpackZip(string zipFile, string workingFolder)
{
// doesn't matter what name I use, GUID or no GUID the GetFiles still returns an empty lists
var tempFolder = Path.Combine(workingFolder, Guid.NewGuid().ToString());
Directory.CreateDirectory(tempFolder);
using (var unzipStream = new ZipInputStream(File.OpenRead(zipFile)))
{
ZipEntry entry;
while ((entry = unzipStream.GetNextEntry()) != null)
{
var fileName = Path.GetFileName(entry.Name);
if (fileName == string.Empty) continue;
using (var streamWriter = File.Create(Path.Combine(tempFolder, Path.GetFileName(entry.Name))))
{
var size = 2048;
var data = new byte[2048];
while (size > 0)
{
size = unzipStream.Read(data, 0, data.Length);
streamWriter.Write(data, 0, size);
}
}
}
}
return tempFolder;
}
any suggestions?
Upvotes: 0
Views: 2555
Reputation: 5990
Problem which I guessed in
private const string VALID_EXTENSION_MASK = "*." + EXTENSION_LOG_FILE;
retruns *..txt
because EXTENSION_LOG_FILE = ".txt"
Upvotes: 1