C# 将csv文件移动到今天日期位于不同路径的新文件夹
我有一个每天生成的CSV文件,我想用今天的日期将该CSV文件移动到不同的文件夹中 我的CSV文件finaltest12.CSV 这是我的代码:C# 将csv文件移动到今天日期位于不同路径的新文件夹,c#,C#,我有一个每天生成的CSV文件,我想用今天的日期将该CSV文件移动到不同的文件夹中 我的CSV文件finaltest12.CSV 这是我的代码: if (System.IO.File.Exists(@"F:/Explor/final test/finaltest12.csv")) { String Todaysdate=DateTime.Now.ToString("dd-MMM-yyyy"); if(!Directory.Exists("I:\\test\\final test\\
if (System.IO.File.Exists(@"F:/Explor/final test/finaltest12.csv"))
{
String Todaysdate=DateTime.Now.ToString("dd-MMM-yyyy");
if(!Directory.Exists("I:\\test\\final test\\snaps\\"+Todaysdate)
{
Directory.CreateDirectory("I:\\test\\final test\\snaps\\"+Todaysdate);
}
}
要移动文件,可以使用file.move(..)
要移动文件,可以使用file.move(..)
要移动文件,可以使用file.move(..)
要移动文件,可以使用file.move(..)
你需要下面的代码,它正在工作,试试这个
if (System.IO.File.Exists(@"D:/finaltest12.csv"))
{
string fileoldPath="D:\\finaltest12.csv";
string Todaysdate ="E:\\";
bool isExists = System.IO.Directory.Exists(Todaysdate);
if (!isExists)
System.IO.Directory.CreateDirectory(Todaysdate);
System.IO.File.Move(fileoldPath, Todaysdate+"\\finaltest12.csv");
}
你需要下面的代码,它正在工作,试试这个
if (System.IO.File.Exists(@"D:/finaltest12.csv"))
{
string fileoldPath="D:\\finaltest12.csv";
string Todaysdate ="E:\\";
bool isExists = System.IO.Directory.Exists(Todaysdate);
if (!isExists)
System.IO.Directory.CreateDirectory(Todaysdate);
System.IO.File.Move(fileoldPath, Todaysdate+"\\finaltest12.csv");
}
你需要下面的代码,它正在工作,试试这个
if (System.IO.File.Exists(@"D:/finaltest12.csv"))
{
string fileoldPath="D:\\finaltest12.csv";
string Todaysdate ="E:\\";
bool isExists = System.IO.Directory.Exists(Todaysdate);
if (!isExists)
System.IO.Directory.CreateDirectory(Todaysdate);
System.IO.File.Move(fileoldPath, Todaysdate+"\\finaltest12.csv");
}
你需要下面的代码,它正在工作,试试这个
if (System.IO.File.Exists(@"D:/finaltest12.csv"))
{
string fileoldPath="D:\\finaltest12.csv";
string Todaysdate ="E:\\";
bool isExists = System.IO.Directory.Exists(Todaysdate);
if (!isExists)
System.IO.Directory.CreateDirectory(Todaysdate);
System.IO.File.Move(fileoldPath, Todaysdate+"\\finaltest12.csv");
}
最好使用
System.IO.Path.combined
来处理文件夹路径。您的问题是什么?在第一个if中添加括号并添加一个文件。如果移动,它应该会工作。正如@VolodymyrMelnychuk已经说过的:使用Path.Combine来创建你的路径。使用反斜杠而不是斜杠。最好使用System.IO.Path.Combine
来处理文件夹路径。你的问题是什么?在第一个if中添加括号,并添加一个文件。移动,它应该会工作。正如@VolodymyrMelnychuk已经说过的:使用Path.Combine来创建你的路径。使用反斜杠而不是斜杠。最好使用System.IO.Path.Combine
来处理文件夹路径。你的问题是什么?在第一个if中添加括号,并添加一个文件。移动,它应该会工作。正如@VolodymyrMelnychuk已经说过的:使用Path.Combine来创建你的路径。使用反斜杠而不是斜杠。最好使用System.IO.Path.Combine
来处理文件夹路径。你的问题是什么?在第一个if中添加括号,并添加一个文件。移动,它应该会工作。正如@VolodymyrMelnychuk已经说过的:使用路径。组合来创建你的路径。使用反斜杠而不是斜杠。非常感谢wonko79。你很好!顺便提一下通常在c#中使用字符串代替字符串。非常感谢wonko79。你很好!顺便提一下通常在c#中使用字符串代替字符串。非常感谢wonko79。你很好!顺便提一下通常在c#中使用字符串代替字符串。非常感谢wonko79。你很好!顺便提一下通常在c#中,使用string代替string。