동일한 네트워크의 먼 디렉토리에서 파일을 복사해야합니다. 나는이 디렉토리에 액세스 할 수가 성공 :네트워크의 디렉토리 공유 C#
public void CopyDir(string sourceDir, string destDir)
{
DirectoryInfo dir = new DirectoryInfo(sourceDir);
if (dir.Exists)
{
string realDestDir;
if (dir.Root.Name != dir.Name)
{
realDestDir = System.IO.Path.Combine(destDir, dir.Name);
if (!Directory.Exists(realDestDir))
Directory.CreateDirectory(realDestDir);
}
else realDestDir = destDir;
foreach (string d in Directory.GetDirectories(sourceDir))
CopyDir(d, realDestDir);
foreach (string file in Directory.GetFiles(sourceDir))
{
string fileNameDest = System.IO.Path.Combine(realDestDir, System.IO.Path.GetFileName(file));
if (!File.Exists(fileNameDest))
File.Copy(file, fileNameDest, true);
}
}
}
그러나 오류가 Could not find a part of the path 'StlDirectory \ BM529234-CRL39-LF.stl'
나타납니다 :
string[] parts = Regex.Split(@directory_path, @"\\");
// l'emplacement de repertoire \\nom de la machine\nomde repertoire
string distant_directory = @"\\"+Environment.MachineName+ @"\" + parts[parts.Length - 2];
string local_directory = @"StlDirectory";
CopyDir(distant_directory, local_directory);
복사본의 기능은 다음과 같다.
- 왜이 오류가 표시됩니까?
- 어떻게 해결할 수 있습니까?
없는 존재하지 않는 생각? – KF2
무엇의 주소? –
귀하의 주소를 분할하는 동안 문제가 있다고 생각합니다.이 오류는 '경로의 일부를 찾을 수 없습니다'StlDirectory \ BM529234-CRL39-LF.stl'' 디렉토리 dosent가 있기 때문에 – KF2