I am quite an amateur programmer and this is my first question on Stack Overflow, I hope I am doing everything right :). But maybe someone here can think of what the problem could be.
My program is supposed to move various files from one disk to another on the server. With a large zip file (always about 10-20GB in size) I always have the problem that the following exception is thrown:
System.IO.IOException: The process cannot access the file because it is being used by another process.
at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at System.IO.FileInfo.MoveTo(String destFileName, Boolean overwrite)
at MPOS_Archiver.Program.Main(String[] args) in C:\Users\ivan.gazic\Desktop\MPOS_Archiver\MPOS_Archiver\Program.cs:line 106
Importend to know. I am not creating the files in my Code they are just there on the disk (there is a share folder on the disk where my colleagues are leaving the files) I just want to move them. This is the only part of my code where the zip files are mentiond. So I guess I am not opening a FileStream and there for I don't need to close one. In a similar question on Stack Overflow its always about opening and closing the file streams but I don't see that applying in this case
My program is also running on a test server where the files are much smaller. This problem does not occur there! The code with which I realize the file shift:
files = Directory.GetFiles(Path.Combine(sourcePath, bkz)).ToArray();
if (files.Length > 0)
{
foreach (string file in files)
{
FileInfo dbZIPfile = new FileInfo(file);
try
{
dbZIPfile.MoveTo(Path.Combine(targetPath, bkz, dbZIPfile.Name), true);
}
catch (IOException ex)
{
Console.WriteLine("There was an error moving the DB ZIP: " + ex);
}
Console.WriteLine("File " + dbZIPfile.Name + " moved to " + Path.Combine(targetPath, bkz));
}
}
else
{
Console.WriteLine("No DB .ZIP in market" + bkz);
}