How to deal with the case where the specified file already exists.(Power Automate Desktop)

Japanese version.

When using an action to save some file,If the target file already exists, it is not convenient and may need to be dealt with.


Using the "If file exists" Parameter

In many cases, there is a parameter that specifies the behavior if the file already exists.
The options are almost always "overwrite", "nothing", or "append".

This method is easy to implement, but has the disadvantage that it does not notify the user that the file already exists.

If you want to be notified, use the "Check for Existence" in the next section in combination with the "Check for exists" section.

Check for exists

If you want to notify users in any way If you want to notify users of the existence of a file, use the If file exists Action to check for the existence of the file by setting a prior.

Select "Exists" for "If file" and specify the path to the file to be checked.

Notify with a message if the file exists.

Under the If file exists Actions block, place a message informing the user that the file already exists.

It is also useful to ask the user to specify a different file in the Display select file dialog Action.

Perform a specific action only if the file does not exist

Perform a specific action only if the file does not exist

Conversely, if you want to perform a specific action only if the file does not exist, you can select "Does not exist" for "If file" and place an action under it to avoid performing unnecessary actions.

Rename an existing file

Before executing the action to save a file, it is also useful to use "Rename file(s)" to leave an already existing file renamed.

Depending on the frequency of occurrence, it may be possible to rename the file without duplicating the file name by adding the result of Create random text or the execution date and time using Get current date and time and Convert datetime to text for the renamed name The file name is not changed.

Robin(for copy and paste). It can be copied and pasted into Power Automate Desktop.

IF (File.IfFile.DoesNotExist File: $'''C:\\Test\\Test.txt''') THEN
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyyMMddhhmmss''' Result=> FormattedDateTime
    Text.Random UseUpperCaseLetters: True UseLowerCaseLetters: True UseDigits: True UseSymbols: True MinimumLength: 4 MaximumLength: 4 RandomText=> RandomText
    File.RenameFiles.RenameAddText Files: $'''C:\\Test\\Test.txt''' TextToAdd: $'''_%FormattedDateTime%_%RandomText%''' TextPosition: File.AddTextPosition.AfterName IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles

For those who want to learn Power Automate Desktop effectively

The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.