简体   繁体   中英

Using .xml Filename to create sub directories

I need to create sub directories in a user defined target folder. I need to do this based on date within the filename. The filename is formatted "Result9_9_2013 1-31-13 PM.xml". I need to create a folder for every Year, Month, and Day for every instance. I am new to C# and am having issues with how to create the directories using just the "9_9_2013" portion of the filename. How would I go about this? Thanks in advance.

Strip off the "Result" prefix from your file name

DateTime time = DateTime.ParseExact("9_9_2013 1-31-13 PM","d_M_yyyy h-mm-ss tt",     System.Globalization.CultureInfo.InvariantCulture)

Now you have date time and you can create you directory naming in format you wish with the reverse like this

String dirName = time.ToString("dd-MM-yyyy")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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