0
\$\begingroup\$

i am experiencing some problem here , i have a path :

"/folder/folderagain/file.xml"

i tried to use Directory.CreateDirectory() to create all folder (in case one of them is missing) and then reuse the path to create a file in another place inside the script. But instead a folder named "file.xml" was created by Directory.CreateDirectory() and my script got blocked from creating the file .

I managed to solve this problem by creating 2 different path , one of them end with file.xml and the other does not. But is there any better way to do it ? can i tell Directory.CreateDirectory() to create only folder ??

look at screenshot below , there's System.UnautorizedAccessException error because my script trying to create file named "keymap.xml" but a folder with the exact name already exist so it thrown that error .

enter image description here

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Use Path.GetDirectoryName() to get everything except the last segment of the path, which is filename in your situation.

\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .