现在我正在尝试截取屏幕截图并将其保存到本地计算机,然后再将其复制到网络驱动器:
Q:\1234567890123456789012345\123456789012\12345\Screenshots\sc.jpg
^ 了解有多少个角色在说话。我已将其设置为在“12345”之后创建一个屏幕截图文件夹当程序到达发生此错误的位置时:
我怎样才能避免这种情况?
还有:
DirectoryInfo scdestinfo = new DirectoryInfo(scdest);
DirectoryInfo scinfo = new DirectoryInfo(sccpath);
CopyAll(scinfo, scdestinfo);
这是我复制文件夹/文件的代码。
public void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
copyall = false;
try
{
//check if the target directory exists
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}//end if
//copy all the files into the new directory
foreach (FileInfo fi in source.GetFiles())
{
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
}//end foreach
//copy all the sub directories using recursion
foreach (DirectoryInfo diSourceDir in source.GetDirectories())
{
DirectoryInfo nextTargetDir = target.CreateSubdirectory(diSourceDir.Name);
CopyAll(diSourceDir, nextTargetDir);
}//end foreach
//success here
copyall = true;
}//end try
catch (IOException ie)
{
MessageBox.Show(ie.Message);
//handle it here
copyall = false;
}//end catch
}//end CopyAll
还有 copyall 函数。
请您参考如下方法:
这是一个 Windows limitation ,虽然有许多 API 函数的 Unicode 变体允许最大路径长度约为 32,767 个字符,但这再次受到您正在处理的特定文件系统的限制。通常,给定的路径组件限制为 255 个字符(查看 GetVolumeInformation 以了解给定卷的具体限制)。
要使用允许更长路径的 Unicode 变体(例如 CreateFileW),我相信您必须直接处理 Windows API 而不是使用 .Net 库函数。
