Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

WPF, C #: Move files
 
Task:
Move files to a subdirectory
 

fileInfo.MoveTo(Folder_Path + "\\" + fileInfo.Name);

 
Namespace: Using System.IO
 
 
Example:
The photos shown here are automatically moved to a subdirectory with the same date.

 
 
With this C # code, all files of a directory are moved to a subdirectory with the same date as an ISO date in a WPF application.
If the subfolder does not exist, it is created at runtime.
Only files with extension jpg and photo and video formats will be edited.

//------< @Loop: Files >------
foreach (FileInfo fileInfo in folder.GetFiles())
{
//----< File >----
if (".jpg|.mp4|.mov|.jpeg|.mpeg|.png".Contains(fileInfo.Extension.ToLower()))
{
//----< IsPhoto >----
String sDate = fileInfo.LastWriteTime.ToString("yyyy-MM-dd");
Debug.WriteLine("#Debug: File: " + fileInfo.Name + " Date:" + sDate);
 
//--< check and create Directory >--
//*if subfolder does not exist then create one
String sPath_SubDirectory = folder.FullName + "\\" + sDate;
DirectoryInfo[] subFolders = folder.GetDirectories(sDate + "*", SearchOption.TopDirectoryOnly);
if (subFolders.Count()<=0)
{
DirectoryInfo subFolder= folder.CreateSubdirectory(sDate);
fileInfo.MoveTo(subFolder.FullName + "\\" + fileInfo.Name);
}
else
{
fileInfo.MoveTo(subFolders[0].FullName + "\\" + fileInfo.Name);
}
 
//--</ check and create Directory >--
//----</ IsPhoto >----
}
//----</ File >----
}
//------</ @Loop: Files >------

 
 
According to the MoveTo method
Mobile

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de