File and Folder Actions in Power Automate Desktop

File and Folder Actions in Power Automate Desktop

In the world of automation, managing files and folders is often a key task. Whether you're processing documents, organizing files, or moving data around, being able to manipulate files and folders is essential. Luckily, Power Automate Desktop (PAD) provides a rich set of File and Folder actions that help you automate tasks such as creating, reading, moving, and deleting files—all without needing to write a single line of code.

In this blog post, we'll explore the various File and Folder actions in Power Automate Desktop, and show you how to use them to streamline your workflows. We'll cover everything from basic file operations to more advanced tasks like file manipulation based on conditions.


What Are File and Folder Actions in Power Automate Desktop?

In Power Automate Desktop, File and Folder actions allow you to interact with the file system on your computer or network. These actions enable you to:

  • Create new files or folders.
  • Move, copy, or delete files and folders.
  • Read data from files, like text or Excel documents.
  • Rename files and folders.
  • Search for specific files or folders.

These actions are incredibly useful when automating repetitive tasks, such as organizing files, processing document data, or cleaning up directories.


Common File and Folder Actions in Power Automate Desktop

Let’s go over some of the most commonly used File and Folder actions in Power Automate Desktop, with examples to illustrate their use.


1. Create a New Folder

Sometimes you might want to create a new folder to organize files. The Create Folder action in PAD allows you to do this quickly.

Example: Creating a Folder for Each Month’s Reports

You might want to create a new folder every month for storing reports. Here’s how you can automate that:

  1. Action: Create Folder
    • Folder Path: C:\Reports\{CurrentMonth}
    • This will create a folder named with the current month (e.g., "January", "February", etc.) inside the C:\Reports\ directory.

Steps:

  1. Use the Get Current Date action to get the current month.
  2. Format the current date as “MMMM” (to get the full month name).
  3. Use Create Folder to create a folder with the month name.
plaintext
Action: Get Current Date Action: Format Date (to extract month name) Action: Create Folder (C:\Reports\January)

2. Create a New File

The Create File action allows you to create a new file in a specified location. You can even write content to the file at the same time.

Example: Creating a Text File with Some Content

Suppose you want to generate a new text file each day that logs the date and time.

Steps:

  1. Use the Create File action to create a text file with a name like Log_{CurrentDate}.txt.
  2. Use the Write to Text File action to write the current date and time into that file.
plaintext
Action: Get Current Date (Get the current date) Action: Create File (C:\Logs\Log_{CurrentDate}.txt) Action: Write to Text File ("Log created on: {CurrentDate}")

This will create a new text file with the current date, and log a message inside the file.


3. Read a Text File

The Read from Text File action allows you to extract the contents of a text file. You can then use the data in your automation process.

Example: Reading a Log File to Track Errors

Let’s say you have a log file that stores error messages, and you want to read through it to check if there were any failures.

Steps:

  1. Use the Read from Text File action to read the contents of the log file.
  2. Use a Text Actions step to check if the word "Error" is present in the file.
plaintext
Action: Read from Text File (C:\Logs\ErrorLog.txt) Action: Text Actions (Check if "Error" is found)

This allows you to read and process the contents of a file to track specific information, such as errors.


4. Move or Copy Files

The Move File and Copy File actions let you move or copy a file from one location to another. These actions are handy when organizing files based on conditions or after processing them.

Example: Moving Files Based on Type

Suppose you have files in a folder and you want to move all PDF files to a separate folder.

Steps:

  1. Use the Get Files in Folder action to get a list of files in a specific folder.
  2. Use the For Each loop to iterate over the list of files.
  3. Use a Condition action to check if the file extension is ".pdf".
  4. If the condition is true, use the Move File action to move the file to a new folder.
plaintext
Action: Get Files in Folder (C:\Downloads) Action: For Each (File in List) Action: Condition (If FileExtension = ".pdf") Action: Move File (C:\Downloads\File.pdf -> C:\PDFs)

This will move all PDF files from the Downloads folder to the PDFs folder.


5. Delete a File or Folder

The Delete File and Delete Folder actions allow you to remove files and folders from the system. These actions are useful for cleaning up old files or clearing temporary data.

Example: Deleting Old Files

Let’s say you want to delete files older than 30 days in a specific folder.

Steps:

  1. Use the Get Files in Folder action to get a list of files.
  2. Use the For Each loop to iterate through the list.
  3. Use the Get File Date action to retrieve the creation date of each file.
  4. Compare the file’s creation date with the current date using a Condition action.
  5. If the file is older than 30 days, use the Delete File action.
plaintext
Action: Get Files in Folder (C:\OldFiles) Action: For Each (File in List) Action: Get File Date (File) Action: Condition (If FileDate < 30 days ago) Action: Delete File (C:\OldFiles\OldFile.txt)

This will delete any file that is older than 30 days from the specified folder.


6. Get Files in Folder

The Get Files in Folder action allows you to list all files in a specific folder. This is useful when you need to process multiple files or check the contents of a directory.

Example: Listing All Files in a Folder

Suppose you want to log all files in a folder to a text file for auditing purposes.

Steps:

  1. Use the Get Files in Folder action to get a list of files in a specific folder.
  2. Use a For Each loop to iterate through each file.
  3. Use the Write to Text File action to log each file’s name to a log file.
plaintext
Action: Get Files in Folder (C:\Documents) Action: For Each (File in List) Action: Write to Text File (Log.txt) ("File: " + File.Name)

This will create a log file that lists all the files in the Documents folder.


Conclusion

Power Automate Desktop offers a wide range of File and Folder actions that enable you to automate tasks like file creation, moving, reading, and deletion. By mastering these actions, you can streamline many file-related tasks and improve your productivity.

In this post, we've covered some of the most commonly used file and folder actions:

  • Creating files and folders.
  • Reading data from files.
  • Moving and copying files.
  • Deleting unnecessary files or folders.
  • Listing files in a directory.

These actions are just the tip of the iceberg. With Power Automate Desktop, you can automate even more complex file operations, making your workflows more efficient and less error-prone.