C# 如何在C中将文件从当前文件夹复制到另一个文件夹
如何将test.pdf从当前文件夹复制到C:exfolder 我知道C中的siple复制方式,但我想要的代码适用于其中包含exe文件的任何文件夹。 我很困惑,因为我想使用当前文件夹路径visual studio 2008 erros 因为我用过:C# 如何在C中将文件从当前文件夹复制到另一个文件夹,c#,file,copy,C#,File,Copy,如何将test.pdf从当前文件夹复制到C:exfolder 我知道C中的siple复制方式,但我想要的代码适用于其中包含exe文件的任何文件夹。 我很困惑,因为我想使用当前文件夹路径visual studio 2008 erros 因为我用过: string fileName = "test_log.LDF"; string sourcePath = @ + Application.StartupPath; string targetPath =
string fileName = "test_log.LDF";
string sourcePath = @ + Application.StartupPath;
string targetPath = @"C:\honar2";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
System.IO.File.Copy(sourceFile, destFile, true);
您可以使用System.Environment.CurrentDirectory获取exe文件的目录,然后使用System.IO.file.Copy方法将该文件复制到任何目标。另外,要获取当前目录,您可能需要查看该目录
string fileName = "test.txt";
string sourcePath = @"C:\Users\Public\TestFolder";
string targetPath = @"C:\Users\Public\TestFolder\SubDir";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
有关更多信息,请遵循Plzsendtehcodez不是StackOverflow的有效问题。下次请尽量把你的问题弄清楚。