How to Get File & Folder - Name | Path | Size | Creation time

Hello Everyone, Hope you are doing good

I would like to present this post who are looking for the File and Folder

Let Jump into the Tutorial

We are look into some Modern activities

  • Get Files in Folder

  • Get the specific folder

  • Get all the files in the subfolder

  • Get Directories

  • Get File and Folder Creation and Size

Folder Description - A folder is a storage area that helps keep your projects separate. They enable you to maintain fine-grained control over automations and their intrinsic entities, and personnel across the entire organization.

Get Folder Info Description - Retrieves the properties of a specified folder and saves the information for later use in the project. You can then select one of the folder properties as input for another activity

Get File Info Description - Retrieves the properties of a specified file and saves the information for later use in the project. When you then use the saved information in another activity, you select one of the file properties as input

Get Files in Folder

Step 1 : Use Assign activity.

LHS : Create an variable | ProjectPath | Variable Type -> String
RHS : Environment.CurrentDirectory+"\"

Step 2 : Use Assign activity.

LHS : Create an variable | GetFileinFolder | Variable Type -> Array(String)
RHS : Directory.GetFiles(ProjectPath+"2022\Linia 1","*.pdf")

Note : Based on the user needing you can update the extension in the expression

Step 3: Use For each activity

For Each : item
In : GetFileinFolder 

Output 

Use Log message | Assign activity to display the output

"Folder path - "+ item.ToString

"file Name with Extension - "+ Path.GetFileName(item.ToString)

"file Name without Extension - "+ Path.GetFileNameWithoutExtension(item.ToString)
Visual

image

image

image

Get the specific folder

Step 1 : Use Assign activity.

LHS : Create an variable | GetSpecficFolder | Variable Type -> String
RHS : Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\Downloads"

Note : It will get Download folder

Or

RHS : Environment.ExpandEnvironmentVariables("%USERPROFILE%\Desktop")

Note : It will get Desktop folder
Visual

image

image

Get all the files in the subfolder

Step 1 : Use Assign activity.

LHS : Create an variable | ProjectPath | Variable Type -> String
RHS : Environment.CurrentDirectory+"\"

Step 2 : Use Assign activity.

LHS : Create an variable | GetFileinSubFolder | Variable Type -> Array(String)
RHS : Directory.GetFiles(ProjectPath+"2022\","*.*",SearchOption.AllDirectories)

Note : Based on the user needing you must update the folder path

Step 3: Use For each activity

For Each : itemSub
In : GetFileinSubFolder 

Output 

Use Log message | Assign activity to display the output

"Folder path - "+ itemSub.ToString
Visual

image

image

Get Directories

Step 1 : Use Assign activity.

LHS : Create an variable | ProjectPath | Variable Type -> String
RHS : Environment.CurrentDirectory+"\"

Step 2 : Use Assign activity.

LHS : Create an variable | GetDirectories | Variable Type -> Array(String)
RHS : Directory.GetDirectories(ProjectPath+"2022\","*.*",SearchOption.AllDirectories)

Note : Based on the user needing you must update the folder path

Step 3: Use For each activity

For Each : itemSub
In : GetDirectories 

Output 

Use Log message | Assign activity to display the output

"Get all the Directories - "+itemDirectories.ToString
Visual

image

image

Get File and Folder Creation and Size

Get creation time for a file

New FileInfo("FilePath").CreationTime

Get creation time for a folder

New DirectoryInfo("FilePath").CreationTime 

Get size of a File in kb

New FileInfo("FilePath").SizeInKB

Get size of a Folder in kb

New DirectoryInfo("FilePath").SizeInKB 

Note : You can also try with For each File in folder and For each Folder in folder activities

For each File in folder Description - Executes an activity or a series of activities for each file in a specified folder. Use this activity when you are working with the files in a folder and you want to repeat one or more activities for each individual file.

For each Folder in folder Description - Executes an activity or a series of activities for each child folder in a specified folder. Use this activity when you are working with child folders in a parent folder and you want to repeat one or more activities for each individual child folder

Check out the Project File

Forum_GetFile-Folders.zip (361.2 KB)

Official Documentation for reference

Hope this will be helpful :slight_smile:

Questions

For questions on your retrieval case open a new topic and get individual support

Feedback

Click image button to share your thoughts

Regards
Gokul

15 Likes