Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove one directory from full directory path

Tags:

c#

I have a directory path of C:\Subdir1\Subdir2\Subdir3\filename.xml.

I need to first check if the file, filename.xml exists in the root of "Subdir2" (one level back) before looking in "Subdir3". How can I easly parse this with Path.GetPathRoot(filename)?

I.E.

First see if this is true:

C:\Subdir1\Subdir2\filename.xml

If not true, then default to C:\Subdir1\SubDir2\Subdir3\filename.xml for the file.

like image 673
user500741 Avatar asked May 23 '11 13:05

user500741


People also ask

How do I rm an entire directory?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do I delete a full directory in Linux?

How to Remove a Directory in Linux. To permanently remove a directory in Linux, use either rmdir or rm command: For empty directories, use rmdir [dirname] or rm -d [dirname] For non-empty directories, use rm -r [dirname]

How do you remove a directory which is not empty?

To remove a directory that is not empty, use the rm command with the -r option for recursive deletion. Be very careful with this command, because using the rm -r command will delete not only everything in the named directory, but also everything in its subdirectories.


2 Answers

Directory.GetParent(dir).FullName
like image 58
artplastika Avatar answered Sep 24 '22 14:09

artplastika


Try this one Directory.GetParent and System.IO.File.Exists

like image 38
Pankaj Avatar answered Sep 24 '22 14:09

Pankaj