How to create a folder

When I tried to download and save a file through Edge, it prompted that the path does not exist.

So I want to create a folder to save the file before downloading it, but I did not find any control to create a folder.

Therefore, I want to use Invoke Code to create a folder dynamically by passing variables through the code. However, I found that Invoke Code does not seem to have a place to pass in parameters.

So, I would like to know how to create a folder dynamically through variables using Invoke Code.

Regenerate response

Hi,

There is no need to pass a variable to Invoke code. You simply create the variable and assign a value (Directory Name) to that variable before calling invoke code.

P.S.: Invoke code can access variables defined in the workflow.

1 Like

As @Sandy_Mehta mentioned, invoke code can access all variables, so if you have the path in a variable called DownloadPath then you can use

System.IO.Directory.CreateDirectory(DownloadPath)

If you don’t have the folder but the filename, including the full path, then you could use

System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filePath))

Thanks for the reply, I understand that all variables can be accessed in the invoke code。

I completed the creation of the folder through python, and even got a return value to judge whether the folder exists。

import os

path = "C:/Users/TK/Desktop/NewFolder"

if not os.path.exists(path):
    os.mkdir(path)
    result = True
else:
    result = False

v_result = result

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