【发布时间】:2015-12-09 16:17:45
【问题描述】:
因为我没有找到一种方法来创建可以在 Windows CE 7 (.NET Framework 3.5) 中复制我的目录的批处理脚本,所以我尝试通过创建 C# 应用程序来解决这个问题。
我使用了 VS2008 并将我的“目标框架”设置为 .NET Framework 3.5。我已经从这台 PC 上为 CE 编写了其他应用程序,所以我认为问题出在我的代码上。
我发现一个应用程序已经有了我要找的东西,这是经过一些修改后的样子:
using System;
using System.IO;
class DirectoryCopyExample
{
static void Main()
{
DirectoryCopy(@"\Hard Disk2\BootFastBlink", @"\Hard Disk\TwinCAT\3.1", true);
}
private static void DirectoryCopy(
string sourceDirName, string destDirName, bool copySubDirs)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
// If the source directory does not exist, throw an exception.
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory does not exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the file contents of the directory to copy.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
// Create the path to the new copy of the file.
string temppath = Path.Combine(destDirName, file.Name);
// Copy the file.
file.CopyTo(temppath, false);
}
// If copySubDirs is true, copy the subdirectories.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
// Create the subdirectory.
string temppath = Path.Combine(destDirName, subdir.Name);
// Copy the subdirectories.
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}
当我在 CE 中运行 .exe 文件时,出现错误:
"copyFolderCE.exe DirectoryNotFoundException at System.IO.Directory.InternalGetFileDirectoryNames(String fullPath, Boolean file) at System.IO.DirectoryInfo.GetDirectories".....
我认为问题可能是 CE 无法使用这些功能,或者我输入的目录名称有误。
谁能告诉我我做错了什么? 我需要 SDK 吗?
提前致谢。
TLDR:我不想在 Windows CE 7 上将文件从 U 盘复制到硬盘。
【问题讨论】:
-
首先,换行: DirectoryInfo[] dirs = dir.GetDirectories();尝试/捕获以获取更多详细信息。我猜它不喜欢你的源目录:\Hard Disk2\BootFastBlink
标签: c# .net embedded windows-ce