How to move a file?

I have two methods: search and sorting.
Search:
public void Search()
{
 title = title_tb.Text;
 OpenFileDialog ofd = new OpenFileDialog();
 ofd.DefaultExt = "fb2";
 ofd.Filter = "fb2 files (*.fb2)|*.fb2|All files (*.*)|*.*";
 Nullable<bool> result = ofd.ShowDialog();
 if (result.HasValue == true)
{
 // Open document 
 filename = ofd.FileName; 
 title_tb.Text = System.IO.Path.GetFileName(filename);
}
 }

I find a specific file format, in the future, you must move it to another folder.
Sorting:
private void SortClick_btn(object sender, RoutedEventArgs e)
{
 //for sorting pb2
 title = title_tb.Text;
 path = Link_tb.Text;
 subpath = author_tb.Text;
 seriespath = SeriesOfBooks_tb.Text;


 string mydir = $@"{path}\{subpath}\{seriespath}";
 if (!Directory.Exists(mydir)) Directory.CreateDirectory(mydir);

 if (!string.IsNullOrWhiteSpace(SeriesOfBooks_tb.Text))
 // **move to folder seriespath**

 }

If SeriesOfBooks_tb.Text is not empty, then the selected file is added to folder with the name that is written in SeriesOfBooks_tb.Text. How to do it?
April 3rd 20 at 18:32
2 answers
April 3rd 20 at 18:34
If I understand correctly, that the initial path in the title, and the ultimate in mydir, then:
File.Move(title, mydir);
I'd check for the existence of the file at the specified path, because if the file already exists you'll get an IOException. The result:
if (File.Exists(mydir)) 
File.Delete(mydir);
File.Move(title, mydir);
The initial path - filename, the idea.
I tried to do as you wrote, but there was a problem. The file moves, but it is unclear where (: - Freida.Pagac commented on April 3rd 20 at 18:37
Anyway, I solved the problem. Have done so:
string mydir = $@"{path}\{subpath}\{seriespath}";
 if (!Directory.Exists(mydir)) Directory.CreateDirectory(mydir); 

 if (!string.IsNullOrWhiteSpace(SeriesOfBooks_tb.Text))
 File.Move(filename, $@"{mydir}\{System.IO.Path.GetFileName(filename)}");
 else 
 File.Move(filename, $@"{path}\{subpath}\{System.IO.Path.GetFileName(filename)}");
- Freida.Pagac commented on April 3rd 20 at 18:40
April 3rd 20 at 18:36
or use the command-line move.
That is just to create a child process without creating a window. Startup options "move c:\test\file1.txt D:\folder2\file2.txt" to transfer the file file1.txt from the test directory of the C: drive in the directory folder2 the D: drive under the name file2.txt.
I think this is OK, because the task of moving the file will be placed on the program, which is provided with the operating system. And in your program you just use the algorithms of searching and sorting.

about something like that
void yourbestfunction()
{
 ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
 startInfo.WindowStyle = ProcessWindowStyle.Minimized;

Process.Start(startInfo);

 startInfo.Arguments = "move C:\test\file1.txt D:\folder2\file2.txt";

Process.Start(startInfo);
 }

Find more questions by tags WPFC#