UiPath

How to get or change file names, create or open folders with UiPath

In UiPath Studio development, we often manipulate files and folders.

However, it can be difficult to know which activity to use for what you want to achieve.

This article explains how to get a list of files in a folder, rename or move files and open files, and create or open folders.

 

 Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch

This site was created by translating a blog created in Japanese into English using the DeepL translation.

Please forgive me if some of the English text is a little strange

Get the file name

Get the list of files in the specified folder.

System.IO.Directory.GetFiles(“<folder path>”) is used to get a list of files in a specific folder.

 

Sample Process
Get the list of files in the specified folder and output the full path, file name only, and file name without extension to the log.

・Code for the parts that are not fully displayed

The [Assign File List] activity will
arrFileFullPath = System.IO.Directory.GetFiles("C:\work\50_system\UiPath\ENG\FileList")

The [Assign FileName] activity will
strFile = System.IO.Path.GetFileName(strFilePath)

The [Assign FIleName No Extension] activity will
strFilewithout = System.IO.Path.GetFileNameWithoutExtension(strFilePath)

 

Each function has a

  • [System.IO.Directory.GetFiles] gets the full path to the files in the first argument, the target folder path.
  • [System.IO.Path.GetFileName] gets the file name with extension from the full path file name of the first argument.
  • [System.IO.Path.GetFileNameWithoutExtension] gets the file name without extension from the full path file name of the first argument

 

・Variables

・target folder

・Execution result

 

Retrieve only specific file names in a specified folder.

System.IO.Directory.GetFiles(“<FolderPath>”, “<search string>”) is used to get the specific file name in the list of files in a specific folder.

 

Sample Process
Acquire only file names that contain the specified string in the file list of the specified folder, and output the full path, file name only, and file name without extension to the log.

・Code for the parts that are not fully displayed

The [Assign FIleList] activity will
arrFileFullPath = System.IO.Directory.GetFiles("C:\work\50_system\UiPath\ENG\FileList","*.xlsx")

The [Assign FileName] activity will
strFile = System.IO.Path.GetFileName(strFilePath)

The [Assign FileName No extention] activity will
strFilewithout = System.IO.Path.GetFileNameWithoutExtension(strFilePath)

 

Each function has a

  • [System.IO.Directory.GetFiles] searches for files in the first argument’s target folder path with the second argument and gets the full path.
    * The second argument, *, represents an arbitrary string.
  • [System.IO.Path.GetFileName] gets the file name with extension from the full path file name of the first argument.
  • [System.IO.Path.GetFileNameWithoutExtension] gets the file name without extension from the full path file name of the first argument

 

・Variables

・target folder

・Execution result

 

File operation

Move files(Move File)

To move a file, use “Move File”.

“Move File” is located in System > File.

Move File  Setting item

Setting location Setting item Setting contents
Body
From The path of the file to be moved.
To The destination path where the file is to be moved.
Overwrite When checked, overwrites the files in the destination folder with the file that is to be copied.
Properties Common DisplayName The display name of the activity.
ContinueOnError Specifies if the automation should continue even when the activity throws an error.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
To Destination The destination path where the file is to be moved.
From Path The path of the file to be moved.
Options Overwrite When checked, overwrites the files in the destination folder with the file that is to be copied.

 

Sample Process
Move the file.

・Move File  Properties

・Folder before process execution

・Folder after executing the process

F-pen
F-pen
The files have been moved from the before folder to the after folder.

 

Rename the file(Move File)

To rename a file, use “Move File”.

“Move File” is located in [System > File].

 

Move File  Setting item

Setting location Setting item Setting contents
Body
From The path of the file to be moved.
To The destination path where the file is to be moved.
Overwrite When checked, overwrites the files in the destination folder with the file that is to be copied.
Properties Common DisplayName The display name of the activity.
ContinueOnError Specifies if the automation should continue even when the activity throws an error.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
To Destination The destination path where the file is to be moved.
From Path The path of the file to be moved.
Options Overwrite When checked, overwrites the files in the destination folder with the file that is to be copied.

 

 

Sample Process
Rename the file.

・Move File  Properties

 

・The target folder before the process is executed

・The target folder after the process is executed

rakko-kun
rakko-kun
After the process is executed, the file is renamed.

 

open a file(Start Process)

Use “Start Process” to open the specified file.

The “Start Process” is located in [System > Application].

 

Start Process  Setting item

設定場所 設定項目 設定内容
Body
FileName The full file path where you can find the executable file of the application to be opened.
Arguments The parameters that can be passed to the application at startup.
Properties Common DisplayName The display name of the activity.
ContinueOnError Specifies if the automation should continue even when the activity throws an error.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
Input FileName The full file path where you can find the executable file of the application to be opened.
WorkingDirectory Path of the current working directory.
Arguments The parameters that can be passed to the application at startup.

 

 

Sample Process
Open the specified file.

・Start Process  Properties

・Target file

・Execution result

F-pen
F-pen
After the process is executed, the specified file will be opened.

 

Folder Operations

Create a folder(Create Folder)

To create a new folder, use “Create Folder”.

“Create Folder” is located in [System > File].

 

Create Folder  Setting item

設定場所 設定項目 設定内容
Body
Folder name The full path of the directory to be created.
Properties Common DisplayName The display name of the activity.
ContinueOnError Specifies if the automation should continue even when the activity throws an error.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
In folder Path The full path of the directory to be created.

 

Sample Process
Create a new folder.

・Create Folder  Properties

・Target folder before process execution

・Target folder after executing the process

sea otter
sea otter
After running the process, you’ll see a new folder created.

 

Open the folder(Start Process)

Use “Start Process” to open the folder.

The “Start Process” can be found under [System > Application].

 

Start Process  Setting item

設定場所 設定項目 設定内容
Body
FileName The full file path where you can find the executable file of the application to be opened.
Arguments The parameters that can be passed to the application at startup.
Properties Common DisplayName The display name of the activity.
ContinueOnError Specifies if the automation should continue even when the activity throws an error.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
Input FileName The full file path where you can find the executable file of the application to be opened.
WorkingDirectory Path of the current working directory.
Arguments The parameters that can be passed to the application at startup.

 

 

Sample Process
Open the specified folder.

・Start Process  Properties

rakko-kun
rakko-kun
Specify [“C:\Windows\explorer.exe”] as the FileName to open the explorer.

 

・Execution result
The folder path specified in Arguments will be opened.

 

summary

  • System.IO.Directory.GetFiles(“<FolderPath>”) is used to get the list of files in the specified folder.
  • To move or rename a file, use “Move File”.
  • Use “Start Process” to open the specified file or folder.
  • To create a new folder, use “Create Folder”.

Back to Table of Contents

 

 Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch

 same category UiPath

 

The operator of this blog, F-penIT blog