简体   繁体   English

关于文件路径和打开这些文件的问题 C#

[英]Question about File Paths and opening those files C#

I have Three strings that are set to the current: year, month, day respectively using the "DateTimeNow".我有三个字符串设置为当前:年、月、日,分别使用“DateTimeNow”。 and I have set a path to a string of the root folder named "Custom_project" by grabbing the file path from a text file on the desktop.我通过从桌面上的文本文件中获取文件路径,设置了一个名为“Custom_project”的根文件夹字符串的路径。

They are named:它们被命名为:

public string CurrentYear;
public string CurrentMonth;
public string CurrentDay;
public string CustomOrderFilePathTopFolder = File.ReadAllText("C:/desktop/Custom_project.txt");
//CustomOrderFilePathTopFolder now ='s C:/desktop/Custom_project/

Okay so I am trying to check to see if a folder exists(Folder Named: "CurrentYear" or in this case "2020" inside of the: "Custom_project" folder) and if not then create the folder with the string, if it does exist then it will then proceed to my next step which is essentially opening the file: "CurrentYear" or "2020, then repeating the same thing but inside of that folder: Custom_project/2020, for month and repeat one last time for day.好的,所以我正在尝试检查是否存在文件夹(文件夹名称:“CurrentYear”或在本例中为“2020”在“Custom_project”文件夹中),如果不存在,则使用字符串创建文件夹,如果存在如果存在,那么它将继续执行我的下一步,这实际上是打开文件:“CurrentYear”或“2020”,然后在该文件夹内重复相同的内容:Custom_project/2020,一个月,最后一次重复一天。

So In the end I would have a file path that looks like so: "C:/desktop/Custom_project/2020/07/12".所以最后我会有一个看起来像这样的文件路径:“C:/desktop/Custom_project/2020/07/12”。

Now To My Question: "HOW DO I GO ABOUT CHECKING IF A FILE NAMED "2020" EXISTS INSIDE OF THE CUSTOMPATHFOLDER AND IF IT DOESN'T THEN CREATE THAT FOLDER现在到我的问题: “我如何检查 CUSTOMPATHFOLDER 中是否存在名为“2020”的文件以及是否不创建该文件夹

I just tried using This(Which doesn't seem to work):我刚刚尝试使用这个(这似乎不起作用):

        if (CustomOrderFilePathTopFolder == "")
        {
            MessageBox.Show("ERROR FILE PATH CANNOT BE EMPTY!");
        }
        else if (!Directory.Exists(CustomOrderFilePathTopFolder + CurrentYear))
        {
            Directory.CreateDirectory(CustomOrderFilePathTopFolder + CurrentYear);
        }

This Does nothing for me so I tried this:这对我没有任何作用,所以我尝试了这个:

        if (CustomOrderFilePathTopFolder == "")
        {
            MessageBox.Show("ERROR FILE PATH CANNOT BE EMPTY!");
        }
        else if (!Directory.Exists(CustomOrderFilePathTopFolder + "/" + CurrentYear))
        {
            Directory.CreateDirectory(CustomOrderFilePathTopFolder + "/" + CurrentYear);
        }

Doesn't Work Either So I am At a loss Please Let me know how I would go about this please and thank you a ton!!也不起作用所以我很茫然请让我知道我将如何处理这个问题,谢谢!

Try below steps尝试以下步骤

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM