当前位置:网站首页>Creating files, recursively creating directories

Creating files, recursively creating directories

2022-06-24 22:18:00 French red wine sweet

problem :

I was reading some file IO tutorials for C# and have managed to write out some files, but what if the path I'm given contains directories? I'm reading C# Some of the documents of IO Tutorial and try to write some files , But what if the path I give contains a directory ?

For example, I want to create the file called data/my_file except data folder doesn't exist. for example , I want to create a file named data/my_file The file of , but data Folder does not exist .

The line, Line ,

BinaryWriter outFile = new BinaryWriter(File.OpenWrite(path));

where path is the above string, crashes with the message that part of the path doesn't exist, which means C# isn't creating them as required. among path Is the above string , Crash and display a message that part of the path does not exist , It means C# They were not created as required .

I would like C# to handle all of the messy directory creation and checking for me instead of me having to parse the path and create all of the necessary directories. I hope C# Deal with all the messy directory creation and check me , Instead of having to resolve the path and create all the necessary directories .Is this possible? Is that possible? ?Otherwise, is there a snippet of code that I can just copy over into my project which will handle anything I might be overlooking (since I don't know much about file management). otherwise , Is there a piece of code that can be copied into my project , It can handle anything that I might overlook ( Because I know very little about document management ).


Solution :

Reference resources : https://stackoom.com/en/question/juQL
原网站

版权声明
本文为[French red wine sweet]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211312115998.html