c# ZipFile.CreateFromDirectory - the process cannot access the file “path_to_the_zip_file_created.zip” because it is being used by another process

前端 未结 5 1369
礼貌的吻别
礼貌的吻别 2020-12-03 04:22

Basic Code:

string startPath = @\"C:\\intel\\logs\";
string zipPath = @\"C:\\intel\\logs-\" + DateTime.Now.ToString(\"         


        
5条回答
  •  -上瘾入骨i
    2020-12-03 04:55

    The other answers, provide the correct reason, but I had a little problem in understanding them at the first sight. I cannot comment, so putting this as an Answer. Might be easy for someone who visits this later on.

    If the path of the Zip file that is being created, is the same as the path that is given to the ZipFile.CreateFromDirectory, the ZipFile creates the desired zip file and starts adding the files from the directory to it. And will Eventually, try to add the desired zip file in the zip as well, as it is in the same directory. This is just not possible and not required, because the desired zipfile is being used by CreateFromDirectory method.

提交回复
热议问题