web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Unanswered

Folder cleaning

(0) ShareShare
ReportReport
Posted on by 14

I would like to create a flow that will clean my folders. in my <folder name> i have multiple subfolders and the go like:

customer1

customer2

Etc

each one these folders have 2 subfolder and at the deepest I have my files I want them to resurface to customer1 and the rest deleted for easier data transfer.

 

C:\Users\ADMIN\Desktop\<folder name>\customer1\edit for region\convert\finish

 

C:\Users\ADMIN\Desktop\<folder name>\customer1\edit for size\convert\finish

 

How can I make the files inside finish resurface and not clash with already same named files?

Every other file can be deleted for faster data transfer.

 

Thanks for any help!!!!🤗

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Get files and move files are your basic actions for what you want to do. Logically, you can select “look through sub folders” on the Get Files parameters. So, now you have %Files% and it has every subfolder and filename that exists from your main folder.  If duplicate file Ames are possible, I would rename each file as you move it using the subfolder it is under.  Here we go:

     

    get sub folders (main customer folder) to %Folders%
    for each %CurrentItem% in %Folders%
        Get files %CurrentItem% including subfolders to %Files%
        for each %CurrentItem2% in %Files%
             Rename file to %CurrentItem.Name%_%CurrentItem2.Name% and store result as %RenamedFile%
            Move %RenamedFile% to %DestinationFolder%

        End(for each on files)

    end(for each on subfolders)

  • qwe321 Profile Picture
    14 on at

    I am a noob so I have no idea what to do or what you said.

    Why are we putting '%'  and where?

    I watched couple of videos but this is the best I could do.

    hbghrthe.png
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    % signs indicate a variable, so when you use get folders, it shows in the parameters screen, save list to: Folders

     

    to call Folders, you use the syntax %Folders% which indicates to the system that you are calling a variable. Try again. You got “get files” and for each file, but before that, I would do “get folders” and for each folder. Make sure your get files and for each file is inside get folders and for each folder as indicated below. 

  • qwe321 Profile Picture
    14 on at

    I did this but I am not sure what is the problem😞😞 

    test.png
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    %DestinationFolder% is a variable. 

    so, at the beginning of your flow, use the set variable command to set %DestinationFolder% to the directory you want to move all the files to (example: C:/Documents)

  • qwe321 Profile Picture
    14 on at

    Ok I think i couldnt explain what I wanted to automate.

    I tried to do it with Recording but that was very time consuming.

    So here is a test video.

    https://www.loom.com/share/208755fa9b0e4241b6d7dbf4e467016f 

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Right, so you have to find some logic to rename the files so you are not overwriting them.  %Files% will have all files in the folder including subfolders.  Honestly, if you don't care about what the name of the file is, you could just get them all out with an index counter:

     

    Copy and paste the below into your subflow:

    SET SourceFolder TO $'''C:\\[ENTERMAININPUTFOLDERHERE]'''
    SET DestinationFolder TO $'''C:\\[ENTERMAINOUTPUTFOLDERHERE]'''
    Folder.GetFiles Folder: SourceFolder FileFilter: $'''*''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    File.RenameFiles.RenameAddSequentialSuffix Files: Files SequencePosition: File.AddTextPosition.BeforeName StartNumberingAt: 1 IncrementBy: 1 SequenceSeparator: File.Separator.Underscore UsePadding: True Padding: 3 IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
    File.Move Files: RenamedFiles Destination: DestinationFolder IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles

     

    It should look like this (with Set variable Input Folder and Set Variable Destination Folder as actions 1 & 2:

    MichaelAnnis_0-1668538265023.png

     

    This will rip every file out of your main folder, regardless of where it is, rename it with an index such as 001_Filename, 002_Filename, and so on, and then move it to your Destination Folder.  Nothing will be overwritten because they will all get names by the index.

     

    Good luck!

     

  • qwe321 Profile Picture
    14 on at

    Yes this puts "Everything" outside. I just need the files to go up couple of subfolders and delete rest.

    I looked it up a bit and figured I need some sort of loop for each folder. Because the action is the same.

    Should i post another discussion with that video link

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Look again at my first post, you can "Get Subfolders" to folders, and then use that list to loop (for each) through the list of %Folders% to perform what was created on the last post.  So, it would get files, rename files, and move the files to the top, and it would do that for each folder in %Folders%.

  • qwe321 Profile Picture
    14 on at

    I tried it still puts everything outside and doesn't delete anything. I am going to repost it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard