在WPF中嵌入CEF,打开一个要打开本地文件夹,上传该文件夹中的所有文件(比如百度网盘的上传文件夹),目前CEF只是上传了选择目录的根目录下的文件,但是里边的子目录及子目录中的文件并没有实现上传,DialogHandler里边的OnFileDialog,只能控制选择文件夹,但是之后的操作不能再控制,求救!!!
选择文件夹之后,遍历文件夹内容,如果又是文件夹,递归遍历,如果是文件,就可以进行操作了。这是一个复制的示例代码:
/// <summary>
/// 复制文件夹(及文件夹下所有子文件夹和文件)
/// </summary>
/// <param name="sourcePath">待复制的文件夹路径</param>
/// <param name="destinationPath">目标路径</param>
public void CopyDirectory(string sourcePath, string destinationPath)
{
try
{
DirectoryInfo info = new DirectoryInfo(sourcePath);
Directory.CreateDirectory(destinationPath);
foreach (FileSystemInfo fsi in info.GetFileSystemInfos())
{
String destName = Path.Combine(destinationPath, fsi.Name);
if (fsi is FileInfo)
{ //如果是文件,复制文件
try
{
FileInfo fi1 = new FileInfo(fsi.FullName);
if (checkExt(fi1.Extension))
{
Program.log("复制文件:" + fsi.FullName);
msg( fsi.FullName, "正在复制");
if (File.Exists(destName))
{
switch (Properties.Settings.Default.conflict)
{
case 0:
FileInfo fi2 = new FileInfo(destName);
if (fi1.LastWriteTime > fi2.LastWriteTime)
{
File.Copy(fsi.FullName, destName, true);
}
break;
case 1:
destName = (new Random()).Next(0, 9999999) + "-" + destName;
File.Copy(fsi.FullName, destName);
break;
case 2:
File.Copy(fsi.FullName, destName, true);
break;
default:
break;
}
}
else
{
File.Copy(fsi.FullName, destName);
}
}
}
catch (Exception ex)
{
Program.log("复制文件:" + destName + ":失败:" + ex.ToString(), 2);
}
}
else //如果是文件夹,新建文件夹,递归
{
try
{
Directory.CreateDirectory(destName);
CopyDirectory(fsi.FullName, destName);
}
catch (Exception ex)
{
Program.log("创建目录:" + destName + ":失败:" + ex.ToString(), 2);
}
}
}
}
catch (Exception ex)
{
Program.log("复制目录失败,设备可能被强行拔出:" + ex.ToString());
}
}