Retriving File Details and Moving Files to specifed Destination
In this it is providing Details for each file present in the specified Directory and move those files into Destination Path. If source Directory doesnot exist, it display message.
In this it is providing Details for each file present in the specified Directory and move those files into Destination Path. If source Directory doesnot exist, it display message.
string Path = @"D:\Swarna\personal";
string DestPath=@"D:\Swarna\Copy\";
StringBuilder Fileinfo = new StringBuilder();
if (Directory.Exists(Path))
{
FileInfo Fi = null;
string[] files = Directory.GetFiles(Path);
for (int i = 0; i <= files.Length - 1; i++)
{
Fi = new FileInfo(files[i].ToString());
Fileinfo.Append("Details for File : " + files[i].ToString());
Fileinfo.AppendLine("");
Fileinfo.Append("Filename : " + Fi.Name);
Fileinfo.Append("FileCreation Time : " + Fi.CreationTime);
Fileinfo.Append("FileLastAccessTime : " + Fi.LastAccessTime);
Fileinfo.Append("File Size :" + Fi.Length);
if(!Directory.Exists(DestPath))
{
Directory.CreateDirectory(DestPath);
}
Fi.MoveTo(DestPath+Fi.Name);
Fileinfo.AppendLine("");
Fileinfo.AppendLine("");
}
Response.Write(Fileinfo);
Response.End();
}
else
{
Response.Write("Directory Doesnot Exist");
Response.End();
}