I need to move all files from source folder to destination folder. How can I easily extract file name from file path name?
string newPath = "C:\\NewPath"; string[] filePaths = Directory.GetFiles(_configSection.ImportFilePath); foreach (string filePath in filePaths) { // extract file name and add new path File.Delete(filePath); }
split() method in Python is used to Split the path name into a pair head and tail. Here, tail is the last path name component and head is everything leading up to that. In the above example 'file. txt' component of path name is tail and '/home/User/Desktop/' is head.
Paths include the root, the filename, or both. That is, paths can be formed by adding either the root, filename, or both, to a directory.
Try the following:
string newPathForFile = Path.Combine(newPath, Path.GetFileName(filePath));
Path.GetFileName(filePath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With