How to Get Files in a Folder in Power Automate Desktop

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
working with files and folders in power automate desktop is straight forward I have created a folder with six files in it and the mission now is to sort each file type and then create a new folder and cut them into there so that means that each text file will go into a directory called txt and so forth I also build in a trap that you'll see a lot in the real world that is the extension here is in capital letters and this one is non-capital letters but of course each text file must go into the same folder my name is Anna Jensen let's learn some Microsoft power automate desktop if you want these sample files you can go to the link in the description below mark them and then click download I downloaded mine to my desktop and we'll see him here that's the directory I want to grab the path of this folder so what I do here is that I press shift and then right click with my mouse envelope of this extended menu go find the copious path and we'll go to Power automate desktop and create the solution first we will set a variable for the folder path so choose a set variable and drag it in we will name our variable file path then in the value control V to paste it in so I'll delete the quotation marks and then I'll click save now we can use this variable name whenever we want to call the path this has the benefit that if these files get moved we can just change it here in the set variable now I want to get the files that is in this folder so I'll find a get files in folder and drag it in so here the folder that is the folder path that we just created up here called file path so I'll click this little X here and choose the file path we will not choose to include subfolders but we can do so if we want it developers produced that is called a files and that will be a list of files but then I can click save let's try to run the automation to see that it works that we can add the files to a list if you go over here on the right and click this the legs if you don't see the variables in files double click it now we have a list of files each item has its its place on the list we have three items and the first one is index 0 then one and two that is because this is zero indexed if I click the first one I can click more here you can see and let me just expand it we have some properties of this file for example we have the extension and that is called dot extension and here you can see the extension of this last this first one here that is called dot XL X and um this is the Excel file and if I just go back here you can see all six ones here I can again I can just do this to show all the elements now we will work with that extension to determine what type of file it is and then we won't do the Sorting so I'll click close here the first one we'll do is to iterate to each file so I'll find a for each a for each Loop iterates a collection from start to finish and the value to iterate that will be my list of files you'll find it up here so I click this x and double click the files I will then store the current item into a variable called q and item but since we each item is a file let's just rename it to file it doesn't mean anything but this is just a reference variable that says when we work with the first one we can call file that will give us the first one the second one we can reference to file again and grab that one so just for referencing it makes your flows a lot easier if you rename your variables to names that is describing for what they're doing so for now let's just try to write out the extension so find a display message and we drag that one in so in the fridge down in message to display click this little X here click the arrow to the left of the file and we will find the extension which is here and double click it now our expression is file.extension inside percentage sign let's see that it works so I'll run it here you'll see Dot xlsx dot xlsx in capital letters and so forth let us just stop it now we know that it works we need to do a little bit of text manipulation first we will remove the dart and the dot is always in its first place so we will just remove the first character for from this value so what I'll do here is that I'll find a get subtext here and drag it in in the start of the for each the original text well that is the file.extension so here again I'll just do the file I always prefer to find them here in the menus I could write them I could just write this but we will reduce the risk of Errors when we just choose them automatically I want to start at a position and in programming it's zero index so the first position that is precision zero then the second position is position one that means that we will start at position one and then length that will just be to the end of text and the variables produced that is a subtext but here I'll say extension value this is just the name of the variable and I click save now we can write this extension value out in our display message so simply just delete it click this little action and double click the extension value then I can click save so now we have removed the dot and we can see it when we run it here we have removed the DOT that's the first part of our mission let's stop it because we also want to make every extension to lower so we can compare them better because it has no difference for us whether or not it's capital or not but else there will be and we will click this little X here and then say change text case and drag it in right after this gets up text the text to convert well that will be the extension value so I'll find it up here I will convert them to lower case so pick that one here and the variables produced let's just save the value to the extension value again click this X choose the extension value and click save so now we have to remove the DOT and we have converted to lowercase XLS X LS X docx and so fourth there's no difference in the capital or non-capital now we can start comparing them and moving to new folders we will first count them because we also need to create a nice log and let me introduce you to a custom object a custom object can be seen as a dictionary where you add key value pairs in so I'll find a set variable we will initialize it in the beginning I'll drag in the set variable Lobby and then we'll give it a proper name I'll say five count like this and then we'll give it a value so the syntax is we want percentage signs in starting in the end then we want curly bracket in the start in the end and then we can add the key value pairs for example we can say test a in single quotation marks then a colon and we can say this one has a value of result a like this and so this is a key value pair the name is test a and the value is result a then it's comma separated so it looks like this we can add a space that doesn't matter it will be treated the same now let me just add one more item so I'll say test B in colon that equals two result B this is just to show you how this nice custom object works that will be useful to you let me have a display message it's just to write out something so if I want to say I want to look up test a or test B I can go into the X here I go into the file count that is this custom object up here and then after the T hard brackets then single quotation marks and inside that I can say test B so I'll look up a name and then I'll get a value back and click save now let me try to run it here you can see we look up the test B and then we get the value result B back that's how it works we will use it for the file counting that means that we will have each extension in this list that means that xlsx will be one item and then we will have the count of the files the deoxyx will be another item and then we'll have the count we will only add it once that means that we should check if this extension exists in this file count it will not for the first item so then we will just add it to it and we'll give it the value 1 because now we know we have one file type if it exists we will just add one trade it looks like this so and I really want you to do this because this is so nice to be able to do it will help you in a lot of your workflows I'll stop let's also delete this display message so I'll delete it again I go in here because this will be an empty list we will of course not have test a test B that was just to show you so I delete everything and to make an empty one we will have two curly brackets in the start and in the end like this I'll click save it looks like this so now we want to say does our file extension that is our file type does that exist in this file count if yes we will just add one to it if no we will create it so when we ask questions we'll use an if search for nif drag it down below the change text case and then you will ask and I'll go here so we want to ask is if does the file count contains click this x file count and then we want to say does that one contains and we'll say does it contains the extension value here and that means that it contains XLS X at dxcx so fourth and we will click save we will not use this ignore case we could have used it and then got rid of where we change the text case but since we're also going to use these extension in a lock we have created the solution with this one here so then I can click save so now we have an if and if this is true we do something we also want to add a brand to whenever this expression is not true anymore that means that the item is not created up here so I'll find an else and drag it in right now we have nothing in it but if it doesn't exist we want to create a value up here the key up here and give it the value 1. so let me find a set variable and drag it in inside the else so right here I will say um I want to set the file count go here I want to say give me the file count but the key I'll put in inside of hard brackets if I just wanted to do a test B test C I'll have it in single quotation marks but because our value is right here in the extension value I'll use that in here delete this text C and I'll just say extension value so because we are inside this percentage sign that means that any text here without single quotation marks will get treated treated as a variable so we're going into the file count we add this key the extension value now we just need to give it a value and since it doesn't exist before we're creating this we're down here in the else we will just give it the value one it's the first time we see this file type then I can click save so I can run and expect inspect we don't really do nothing and right now we could have deleted this display message because now I'm sitting here and clicking this one six times it's okay I'll just delete it afterwards that's not the really the big issue but now go over to your file account and click here so now you can see we have one xlsx One D of CX and one txt that is because we're only creating the item the first time we see it we don't do nothing if it's exist but now this part of the solution actually works slightly closed let's delete the display message down here and we solve for the then Branch we'll just do the same as here so we can either drag in another set variable or simply just copy this I recommend copying it because we are lazy as automation Developers so our control C go up to the else Ctrl V we need to modify this a bit so if I go in here I'll say it's still the file count extension value but now I want to add one because I know it's there oh check for that in DF so I'll add one to it and that means that I will wrap this expression remember the sentence sign so I copy this one here and put it in here to add one to it just move inside the present sign and say plus one this will add one to it now I can click save try to run the automation again now we have created a solution that creates a nice lock we still need to create folders and move the files but if you go over here that's it and this solution is so great because it works with any file type you can try other file types this will work so then I can click the sex so now we know we we need to create a folder if we haven't created one that means that the first time we see the file type we'll create a folder and again we're down here in the else so like this little X here and then find a create folder it is here put it in the else Branch it doesn't really matter if you put it on top or in the end of the else so we create a new folder into that it will be the file path that is the directory of our files the new folder name that will just be the extension value that could be xlsx deoxy X and so forth so refer to the extension value like this then we can click save so now we have created the folder and we know the folder exists if we up here because then otherwise we would have created previously so now we can start to move the files so we will go after the if down here and then we will find a move file yeah and drag that one in here so the files to move and now that's just time to do a referencing we are referring to the file up here so click the sex and this is the file that is because that is where we iterate each one of our files where do I want to move it well I want to move it into the file path by the path that one is up here so that is our main food but I also want to create a subfolder otherwise it will just move it to the same folder so I'll have it backwards last and then I will move it to the extension value like this so now um we have created a solution if the file exists well it will only exist if these folders were already present and then we would have to create a dynamic solution here I recommend using a date time but this is not the scope of this exercise if you want to know you're more than welcome to ask down here in the description I can link you to my solution then we can click save so now we are moving the files let's also create a log when we are done here I'll just write out this file count it's not the most fancy lock but again it's a lot and we can in later um lessons we can see how to create even more nice locks so here it will just be a display message but it could also be to a text document go down here and then just write out the file count like this then we click save so now again let me repeat what we actually have accomplished here because it's quite huge you iterating to each files then we'll count them we're also saying that we treat these ones here in non-capital and capital endings equal and then we will start creating a folder and moving them let's see how it goes and I can open this so you can see the solution and you can see the folders are getting created and the files are getting moved and this is our lock again we could format it but it is a lock it is a working lock I can click ok yeah the word file is in here the text file is here the Excel file is here I prepared the next lesson for you so go click it up here and become a complete power automate desktop developer
Info
Channel: Anders Jensen
Views: 24,047
Rating: undefined out of 5
Keywords: power automate desktop, power automate desktop tutorial, how to use power automate desktop, anders jensen, move file power automate desktop, power automate desktop move files, how to get files in power automate desktop, get files in folder power automate desktop, create a folder in power automate desktop, how to copy files in power automate desktop, power automate to copy files, office365, microsoft, power platform
Id: bXqSjLCSLEg
Channel Id: undefined
Length: 18min 17sec (1097 seconds)
Published: Wed Oct 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.