@lakshman - I don’t think that is what the OP wants. If a user were to accidentally create a new folder in there, then it would just give that folder name. OP wants to read the directory names, convert it to a date in MM.yyyy format, then get the next month.
@Apple1 You are on the right track! Now that you have an array (of string) of all the directory names, you should convert it into an array of datetime variables instead. This will allow you to use various datetime methods and properties which will help you achieve your goal. I have attached a workflow showing how to do it and described it below as well. Please let me know if you have questions.
Directory.GetDirectories returns the full path rather than just the name of the directory (e.g. C:\temp\01.2020 instead of only 01.2020). To remedy this, we will use linq to pull out only the directory name property instead. Directory.GetDirectories(YourPath).Select(function(x) new DirectoryInfo(x).Name).ToArray()
NOTE: We could build this next piece into our above linq, but i prefer to use built-in activities where possible instead.
Next, we use a for each loop to convert each item in the string array to a datetime variable. We can do this using the ‘add to collection’ activity (after initializing a list of datetime), and converting the string to datetime like so: Datetime.ParseExact(item,"MM.yyyy",System.Globalization.CultureInfo.InvariantCulture)
Next, we will use the .Max() function on our list of datetimes to find the latest date, add 1 month with the .AddMonth() method, and convert it back into a string with the .ToString() method and formatting it the way we like in MM.yyyy format. NameListDates.max().AddMonths(1).tostring("MM.yyyy")
And finally, we use the ‘create directory’ activity to actually create the directory. Use the path.combine() method to combine the original path of the directory (I called it YourPath) and the newly found date (I called it NewDateFolder). Path.Combine(YourPath,NewDateFolder)
delete.xaml (7.1 KB)