한 폴더에서 다른 폴더로 폴더를 복사하려고합니다. File.Copy - 경로에 대한 액세스가 거부되었습니다.
public void sunfly_num()
{
if (sunfly378 == true)
{
try
{
if (Karaoke_download_res.locationtoinstall == "")
{
pathtoinstall elfenliedpath = new pathtoinstall();
elfenliedpath.ShowDialog();
if (File.Exists(locationtoinstall))
{
if(Directory.Exists(Karaoke_download_res.locationtoinstall + "SF378 August 2017"))
{
File.SetAttributes(locationtoinstall, FileAttributes.Normal);
File.Copy(Karaoke_download_res.mainpath + "SF378 August 2017//", Karaoke_download_res.locationtoinstall + "//SF378 August 2017//", true);
MessageBox.Show("Path Saved Karaoke Files Added To : " + Karaoke_download_res.locationtoinstall);
}
else
{
Directory.CreateDirectory(Karaoke_download_res.locationtoinstall + "SF378 August 2017");
File.SetAttributes(locationtoinstall, FileAttributes.Normal); // Makes every read-only file into a RW file (in order to prevent "access denied" error)
File.Copy(Karaoke_download_res.mainpath + "SF378 August 2017//", Karaoke_download_res.locationtoinstall + "//SF378 August 2017//", true);
MessageBox.Show("Path Saved Karaoke Files Added To : " + Karaoke_download_res.locationtoinstall);
}
}
}
else
{
if (Directory.Exists(Karaoke_download_res.locationtoinstall))
{
if (!Directory.Exists(pathString))
{
Directory.CreateDirectory(pathString);
}
foreach (var srcPath in Directory.GetFiles(Karaoke_download_res.mainpath + "//SF378 August 2017//"))
{
//Copy the file from sourcepath and place into mentioned target path,
//Overwrite the file if same file is exist in target path
File.Copy(srcPath, srcPath.Replace(Karaoke_download_res.mainpath + "SF378 August 2017//", Karaoke_download_res.locationtoinstall + "\\SF378 August 2017"), true);
}
MessageBox.Show("Path Saved Karaoke Files Added To : " + Karaoke_download_res.locationtoinstall);
// Directory.CreateDirectory(pathString);
}
else
{
if (!Directory.Exists(pathString))
{
Directory.CreateDirectory(pathString);
}
foreach (var srcPath in Directory.GetFiles(Karaoke_download_res.mainpath + "SF378 August 2017"))
{
//Copy the file from sourcepath and place into mentioned target path,
//Overwrite the file if same file is exist in target path
File.Copy(srcPath, srcPath.Replace(Karaoke_download_res.mainpath + "SF378 August 2017", Karaoke_download_res.locationtoinstall + "SF378 August 2017//"), true);
}
MessageBox.Show("Path Saved Karaoke Files Added To : " + Karaoke_download_res.locationtoinstall);
}
}
}
catch (Exception elf)
{
MessageBox.Show(elf.Message, "Path Location Error Code: 665");
}
}
}
내가 디버그 파일에서 실행
복사가 저를 준다 : 파일과 디렉토리가 존재하는 경우에, 나는 여기에 에 걸쳐 그렇지 않으면 파일을 복사 코드는 내가 가지고, 그것은 그들을 대체하는 것입니다 싶어 경로에,691 거부액세스라는 오류가
그리고 왜 내가이 오류를 내는지 모르겠습니다. 관리자로서의 실행을 확실히했습니다. 나도 해봤 어
File.SetAttributes(locationtoinstall, FileAttributes.Normal);
그리고 아직도 나에게 같은 오류를 준다.
'//'? 어쩌면 당신은'\\\'을 의미했을까요? – Gusman
오류의 경로가 의심스러워 보입니다. – mayu