File path with multiple date conventions

for instance I am trying to find out if this path exists

“M:\Weekly Reports Open Reqs\2019\July 2019\Open Req Weekly 07.31.2019”
(ps I am not/can not rename it… its how my company wanted it… so I have no control over that!)

but this is going to a weekly/bi-weekly thing where I will need to create folders

“2019” - year folder soon enough I will need to create a new folder for 2020
“July 2019” - another folder, which tomorrow is august so i will have to create folder called “august 2019”
and
“Open Req Weekly 07.31.2019” just like that with the dots and everything

I have attached a xaml file that i have been working on and about ready to give up, I have no idea what i am doing wrong

open PO Folders Monday and Wednesday.xaml (8.8 KB)

For the first problem you can use Folder Exists activity, it returns a Boolean value.
Now for the rest, you need to make everything dynamical.

You will need to create a String with that full name. Now lets go over the parts.
Year = DateTime.Now.Year.ToString()
Month = DateTime.Now.ToString(“MMMM”)
WholeYear = DateTime.Now.ToString(“MM.dd.yyyy”)

Then just create string that you want and use Create Folder activity

are you sure its not path exists?

yes thats right
PATH EXISTS is the activity

in path exists mention like this
“M:\Weekly Reports Open Reqs\"+Now.ToString(“yyyy”)+"\"+Now.ToString(“MMMM yyyy”)+"\"+“Open Req Weekly"+" "+Now.ToString(“MM.dd.yyyy”)

hope this would help you
Cheers @rhyan.brandt

that it does!

One more question, so if this folder does not exists, how do i write it so that way it will create a new folder?

basically i am looking for it to look to see if it exists, if it does, then skip, if it doesnt, create it

1 Like

The steps involved will be @rhyan.brandt
–the output of path exists activity will be a boolean variable and lets name it bool_pathexists
–use a if condition and mention like this bool_pathexists = true
if true it will go to THEN part where we can proceed with activities we need if path exists or it will go to ELSE part where we can include a activity to create a new folder i.e., new directory and for that we got an activity called
CREATE DIRECTORY
where mention the path we need to create
“M:\Weekly Reports Open Reqs"+Now.ToString(“yyyy”)+""+Now.ToString(“MMMM yyyy”)+""+“Open Req Weekly"+" "+Now.ToString(“MM.dd.yyyy”)

hope this would help you
Cheers @rhyan.brandt

@rhyan.brandt - No need to have all of the multiple ifs and multiple create directory activities. The Create Directory activity already does all of this automatically. It will create a folder if it doesnt exist, and if it already exists it will simply do nothing. Here is an example of what you are trying to do all boiled down to 2 activities to create the folder at M:\Weekly Reports Open Reqs\2019\July 2019\Open Req Weekly 07.31.2019 where the dates are updated based on the current date at runtime :slight_smile:

  1. Assign a datetime variable (i’ll call FolderDate) = Now
  2. Create Directory. Path = "M:\Weekly Reports Open Reqs\" + FolderDate.ToString("yyyy\\MMMM yyyy") + "\Open Req Weekly " + FolderDate.ToString("MM.dd.yyyy")

@rhyan.brandt and @Palaniyappan no need to re-create the wheel. The create directory method already checks to see if the path exists and only creates the directory (and all subdirectories) if it doesn’t exist. Here is the documentation on it as well where it clearly states “Creates all directories and subdirectories in the specified path unless they already exist.”: https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory

yah thats correct Create directory will check once we have or not but when we have a prespective of validating whether a folder or file exists or not we need to have a path exists that would let us know while debugging, as create directory wont let us know whether it has created or its there already so didn’t react upon

Cheers @Dave @rhyan.brandt

this was it! this did it! Thank you!!!

1 Like

No worries
Cheers @rhyan.brandt

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.