Check c drive folder

How can I check if the folder is inside c drive, if is not inside, create new folder.

Hi @C99

Try using those activities

Use If Activity with if conditions

Not System.io.file.exist("C:\FolderName")

Place the Create folder activity and pass the same path.

If there is no solder in a preferred location, the bot will create the folder, else it won’t.

HI @C99

You can try with is expression in the If Activity

not System.IO.File.Exists("Your folder")

image

Regards
Gokul

HI @C99

Try this expression directly in the if condition

Directory.Exists("C:\Users\UserName\Documents\")

If true → leave empty there
If False-> Create Folder
image

And that warning symbol is because you are using hardcorded path in the Field so you create a variable to store that path

Regards
Sudharsan

thankyou, it works

hi, can i ask how to name my new folder the same month as one of the directory name in c drive. For example, from c drive, i have to check that the there is a folder named “2022 Folder”, i have to get the year, then from there i name the new folder as “2022 sheet”, if is “2023 Folder”, i name my new folder as “2023 sheet”.

HI @C99

Just use like this in the Create folder activity

"C:\Users\UserName\Documents\"+DateTime.Now.ToString("yyyy")

DateTime.Now.ToString("yyyy")-> This will get the current year (2022)

DateTime.Now.AddYears(-1).ToString("yyyy") -> this will get the previous Year (2021)

DateTime.Now.AddYears(1).ToString("yyyy")-> this will get the Next Year (2023)

Regards
Gokul

What about i need to get the year from the existing folder, but not from getting current year.

Hi @C99

This is the Input folder

image

To get the Folder Name

Directory.GetDirectories("C:\Users\Dell\Documents\UiPath\Test\2022\")

Output

It will get only the folder name

Path.GetFileNameWithoutExtension(ArrString(0))

image

Check out this Tutorial for reference

Regards
Gokul

hi, how can i check the folder name itself or must check through directory, if there is a “-” inside folder name, it shows error

What is the error and share the screenshot @C99

Variable type is should be Array(String)

image

@C99

okay, thank you

Great, Let us know if you face any issue @C99

1 Like

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