Files and Folders in Power Automate for Desktop (Full Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this lesson we will learn to handle files let's get started so we download the course files click download the example files here that one will download our files when we click the three dots click download so if i just resize this i drag the files to my desktop you can place yours in whatever folder you want then i right click extract here so these are the files that we want to sort let's open it by double clicking it here are the files so we want each excel file to go into the excel folder each notepad file into the notepad each word into the word but there is a built-in trap here because we also have zipped files let me double click it you can see that we have notepad files inside the zip so what we will do is to first extract the zip files and then sort in the end we'll create a nice log you'll see how to do that let's get started first thing i'll do is to grab this path to the folder so i shift right click copy as path then i go to power automate for desktop and create a new flow i will call this file handling you can go use whatever you want then i click create let me maximize the canvas first thing we'll do is to create a variable for the folder path so i go over here to my input output variables click the plus sign click input here i have a variable name i will say folder path the default value i'll paste in that was my files folder i'll delete the quotation marks in the start and in the end and i will copy this folder path and paste it in as an external name then i click create so we'll split this exercise in different parts so it's easy to understand first we want to let me open up the folder again we want to unzip this so we can sort all these files and we don't know how many zip files we got in our folder so the first thing we'll do is to find a get files in folder and drag it in so the folder to login well we just created a variable for that so let's use it click the x here and use the folder path right here we only want to find the zip files so i'll say asterisk that's me that means every file and i want every file name ending with sip so i'll do this we can see that we produce a variable called files i will call this files zip because we will work with other files later in the exercise always name your variables and everything well so we can easily see what's going on i click save another thing that we can do to easily name and see what's going on in our workflow is to find a comment so if i search for comment that one is here in the flow control i can drag this in so i can give comments they will just be treated as comments the robot will do nothing with them but they can easily do for guidance for the future you or your colleagues so for example if i say unzip started then i can place all my unzip actions after this and let me copy it let me paste it in let me edit it and say end it so now i have a container i'll put all my unzip activities in here so far i could just get the files in folder we can try to run it there you go you can see that we if i open this we have a list of files there's only one item in and that's because we only have one zipped file and let me just because i will just maximize this just to have to have it more clean looked so now we can iterate to all our zip files i know there's only one but we could have five zip files in it it will work anyways to iterate to a list we'll find a for each and drag it in still inside the unzip started unsub ended value to iterate we want to iterate to our file zip that was the list with the zip files so if i click the x here file sip each item in the list will be stored into a current item that's the one we can process current item is fine this is just a name for reference but i will call it sip file like this i click save so for each zip file in the files sip list we want to do something i want to unzip so up in the actions i'll find a unzip here and drag it in so we need a path but that path is one of the items from the list we only have one this is this path here so i can just refer to the zip file remember that was the reference we gave each item when we're iterating through them one by one so if i go here just click the x click zip file so where do i want to unpack them to well i'm i want to unpack them to the folder path that's where all my other files are so i can just click dx fold the path we will do nothing else so i'll just click save here you can see the power of the folder path of course it's easier now when we just can click a variable but imagine that i want to move my files then i can just change it one place that is here instead of going into my robot change it every time i use that in the robot maybe i have several robots and i could forget something making my robot malfunction so this is a very powerful way to do and it's also an rpa best practice so now i have unzipped i will then delete the zip file because we will not use it anymore so i'll find a delete files here and i drag it in so i'll delete each zip file once i have unzipped it so click the x again choose the zip file then i click save so now we have our flow to unzip let's inspect the folder so we expect that this one will get unzipped the notepad documents will go into this folder and we will delete this zipped file let's run it so i run it it will be fairly quickly i go to my folder there you go we have now three zipped notepads and no saved file so we build the first part of the flow now the sorting can begin again we will use comments to better see what's going on so i'll find a comment drag it in after the unzip ended so this one is file sorting started then i click save i will copy this and paste it in just renaming the last one to end it so now i have a common container again where i can do my file solving we will have nothing going on here and we can even add longer comments if we want a better understanding for what's going on but that's fine for now so again i'll get all files now i have to unzip it so like i want to get all the files in here without exceptions last time we only got the zip files so if i go over here find it get files in folder drag it in between the two file sorting comments so the folder we want to look in that will be the folder path double click that we will take all files so i will just have this asterisk this one will enable us to take everything it will produce a variable and i will just say files i will call this files to sort and again i click save so now we get the files this one will give us a list just like before let me try to run the robot we will do no unzipping because we have no unzipped files anymore but it will of course work if we added saved files now we have the files to sort list so if i open this we can see that we now have a list of 14 actually 15 items because the first one is zero it's zero index and we can see we have all the nice files here those ones are the ones to get sorted again we will use it for each to iterate through each one of the files here and the files to sort so i'll find a fridge and drag it in so what value do i want to iterate through now well this is the files to sort and this is why we named it well so we can easily refer to it so if i click the x here and i find the files to sort i will rename the queue an item this was again just a reference for each one of the file names in the files to sort so i'll just say file then i click save so now we can do something we need to ask a question so let me open our folder again we need to ask first we will ask is the file that we are getting through one by one is that a notepad if yes move the file to the notepad folder so we'll find an if and again an if asks a question if it's true it will perform the actions inside it so if i drag an if in here we will have a condition so what is our condition well i want to ask if our file name up here if that ends with txt xlsx and docx then i can sort the files accordingly let me show you so if i find here i can do it in several ways one cool way to do it is to find my file here then click this arrow scroll a little bit up because here i can get get the extension as a text value so if i do this i select i now have only the extension and that is for example dot txt then i can just say is the extension equal to dot txt like this then we want to do something i'll click save so it will only work on the notepad files now but we will do the same things with each one of the other files types so now i'll have a move files here find the file here and drag it in so what file do i want to move well i want to move the file because we found out that the current file that one was in has had the extension txt then we can move it so if i click the x here then i'll take the file the destination folder well that was the folder path but we want to go inside the notepad so this will look like this so the destination folder well the first part is indeed the folder path and then we'll just do backslash then i'll say notepad like this so it will produce a variable called move files that's fine we will not use that one for now so i'll click save there you go now we can ask the same question for each one of the other two file types and what i'll do here is to find an else like this and pick the one that that's named else if so if i drag this one here because now we will ask a similar question we will just say if the file extension is equal to xlsx that is an excel file then we want to move it to the excel folder so click the x here click the file the arrow here scroll a little bit up take the extension that is the text value so again is the extension equal to dot xlsx that's the name for the excel files or the name that the excel files will end with and i can click save and again similarly we will just pick and move files and i can copy this one here so if i copy it go back here make sure you are on the end then you can control v it will get pasted in just before but here since this is excel files we will open the move files delete the notepad and have excel just as before then we can click save so finally we will have another else if so we only want to look at these three file types if we drag in the nils then everything else will go into like the last folder but this is fine we will just have an else if so here again we can ask is the file extension equal to you know the drill so the file let me find the file extension here here that one is that equal to dot d o c x then it's a word file so i click save here again we can just ctrl c go down here to the end paste it in change the excel to word here go in here have the word oh sorry the word folder then click save now let's try to run the automation to see that all these files will actually go into the right folders so i click run there you go we are now sorting the files let us go back to the folder open the word folder two word files open the notepad folder like 368 notepad files excel files in here but since we want to do it again so let me copy them back or just or cut them back or just unzip them again and delete this i'll just move the files to our main folder once more because we now also want to implement a log so what we will do here is to create three new lists in the beginning so this one will be the initialization that will be before the unzipped started so again i can add comments drag in the comment in the beginning like this here i'll say init started that will be my initialization starts i'll copy this again paste it in and open it say and save and here i'll have my tree lists so find a create new list like this and drag it in so i'll create a new list that says list and then let's call it notepad like this and then click save let me copy it two times so i'll say copy paste paste this one here will be called list excel so rename it here my file names will go for the logging part so i'll click save again here i'll say list word like this and then click save so this one will go up in my initialization so now each time i'll sort the files i will add an item to it over here i just have a breakpoint this is just when you run the automation this will stop here i will not have it so i'll untick it but it's nice when you want to see some features let your robot pause and inspect what's going on i'll untick it so inside each one of these i'll add an item to the lists up here so go over to your actions find and add item to list and drag it in beneath each one of the move files so what item do i want to add i want to add the file because that is the file name so click here into the list this is the notepad list so go find it here scroll a little bit down list notepad then click save i will do similarly for the excel ones so i'll add item that one will be the file again this one will be the list excel that one is here here then click save finally let's do the same thing for the word so i'll add the item to it be the file into the list list word like this then click save so now we will sort the file and add each one of these to a list those ones and let me just show you how it looks it's more easy when we do the robot and then we can see what's going on so we add steps to it so now we're iterating through each one of the 15 files we will finish now and if i go over here for example list notepad now you can see that we have a list of all the notepad files this will be perfect for our log but now again we need to go to the folder and copy the files or cut them back because we will use them once more but it's usually a good thing to run your robot over and over when you develop in that way you will cast the arrows as they appear but now we have added the items to the list we saw it works now we can create the log because we want to have multiple lines in our log we will use a set variable first so i'll scroll down let me just do a comment drag it in here say log started or create log started if you want to be more specific i'll copy it paste it in open it i'll say log ended then i can click save so now we will use the set variable because we wanted multiple lines i'll drag it in here and we will call this log because that's what it is like this so now we just have to say what do we want in our log well i first want total files sorted so i'll say total files sorted colon and then a space now we will just do some dynamic thing so i'll find each one of the list and do a count so what i want to do i first found the list notepad here but i will not use this list so i'll use this arrow list notepad take the count like this so it will look like this and then i will just have the three other ones i'll show you how you add numbers to to each other so if i click the x here i'll just find a list excel then count like this and i'll find a word so list word then that one here like this so in order to do variables and add them together for example we only need to have the percentage signs in the start and in the end so i'll delete each one of these make a space in between them and instead of the space we will have a plus or we'll still have space that one will be counted as nothing here so it will be we will say add all these three lists the count of those atoms together because that one will be our total files sorted what do you think about the quality of this lesson please post it in the comment below that will help me a lot thank you then i want i want to say total notepad files sorted and that one will just be this one up here here remember to add a percentage sign in the end let's say total excel files sorted like this copy this one here or find it in your variables manager but i'll copy it here paste it in remember to have percentage sign in the start and in the end finally total word files sorted i'll copy it from up here percentage sign in start and paste it in i'll also want each file name that i won't sort so i'll say something like this files sorted like this and then i'll just pick each one of the lists down here so i'll find if list of notepad again i'll find the list excel here and finally the list word like this so now i have a log so i'll click save then i will write this to a text file so i'll find a write text to file write text to file here drag it in beneath the set variable so the file path well that will be my folder path and then i want to go place it inside the log folder so what i'll do here is again you'll learn a lot about working with files and folders here i really hope you do it with me then i'll say log and now i can have the file name after another backslash i'll just call this doc txt what text do i need to write well i just created a variable for that that one was called log so you can find it by clicking the x here do like this we will do nothing else we'll just overwrite existing content fine then click save so now we have our files here let's try to run the robot once more here we are entering to each one of the files you can actually if we hurry up we can see the files getting sorted that's quite satisfying and we will be creating the log so if i move inside the log we can see we have a log text file here we have our log we have 15 files sorted 852 and each one of the file names that we sorted we have him here perfect but imagine that this robot runs it will overwrite this lock over and over so let's create a dynamic lock again let me cut out the files to the main deal you can do the same because we will build an additional step on our robot so the files out here let me close the lock what we will do to make a dynamic name we will use date because that one changes it will never be the same so up in the beginning in my init started i will have a get current date or caps lock doesn't matter get current date and time so i'll drag that in this one will just get the current date and time and store it into a current date time variable i click save now i will convert the current date time into a text so find a convert date time to text and drag it in so here i'll take my current date and time click the x here move a little bit up choose that variable in the standard formats again we can use a lot of pre-fixed dates but i want to create my own for the file name so pick custom here i can have some prefixes for example four wise that is years month that is two big amps days and i will show you how you can find these because then we'll say hours that will be hours in 24 hour format minutes and seconds this one will be a unique text because the time will take up over and over we will produce it in the formatted date time variable that will be the text we will use that one so i click save before i proceed with this robot let me show you where you can find it if you go to google and then you'll search for net custom date time format like this pick this one and in the documentation scroll a little bit down you can see the different abbreviations for example two ds as we used that will be the day of the month like this and two big m's that was the month and we will use this in our naming for our robot so let's scroll down first let's change our variable so in the end i will say robot rand successfully on colon and then we will use the formatted date time here like this and then we will click save we'll also use it in the file name so open up the right text to file here and just before the log find the variable again so formatted datetime here we are using it in our naming convention then i click save let's try to run the robot again we are running it let's see it's sorting it it's so satisfying so sword short sword and we will create a lock in a few seconds so here we can open up the lock now we have a new log it's the same as before just with the addition that we now have the time and it's dynamically named because when i run the robot again i can try it even without no files it will finish quickly but it will still create a lock that one will be this one so it is now empty fine we have created a new lock and these locks will just be going in here until we delete them or a robot delete them let me show you in addition to this because we used nivea but we could use a switch a switch is great if we have an if with a lot of else if in it let me show you so a switch it asks a question just like an if but we can just have multiple cases that is else if else if else if so i'll drag this zone in just above the if the value to check that one will be the file.extension so i'll find it here drop down file dot extension i'll select that one so here the switch will take a look at this so and then we can add cases for it we can say if the file extension is equal to text then we want to do something so if i go in here and i'll find a case drag it in so the first case will just be just like before is that equal to dot txt i'll click save so inside this i will have my two actions so if i go down here i copy it because i want to save this for later use i'll go up here click the end paste them in now i can disable some of this this one disabling this if will give us an arrow that is fine for now and the reason it will give us an arrow is that we have this else if at the end so i right click on this one disable actions fine now we have sorted the txt we will add another case for the xlsx so drag in another case here just below this txt so that one will be equal to dot xlsx like this i click save again i'll drag in the two actions here in the excel xl6 session so i'll copy it go up to the end paste them in now i can disable these three actions like this and we just need a case for the word documents so i drag in this case again i'll say equal to dot d-o-c-x like this and i'll copy in my word actions so i'll copy these ones here go up to the end paste them in now i can also disable these and since we are not having the end outside if we're not having if anymore i'll disable this one so now we have built a switch it's a bit more easy to look at and we have the different cases down here let me drag out the files again so we see that it works once more so i'll do this do this it's not mandatory that you use a switch instead of an if it will give a bit more a clean look and it's nice to know that the feature exists so now i run my robot again we'll do just it will be the same thing that happens before just by using the switch instead of the if so let us just finish this and let's inspect the lock so move move move move move here for some reason the word files didn't get sorted why is that well let's move up and find it well we accidentally disabled the actions up here so i will just mark them and then enable them this is a common mistake you'll make a lot of mistakes when building these robots even i do that's fine just know how to fix them and if i run this again we'll of course only have the two word files here those one will go into the word here so that one's there let's inspect the login here so the last log we only have two files it works we also saw it works in corner cases here we only sorted the notepad and the excel ones that's because we have disabled the word actions the next lesson is on the screen just click to go to it
Info
Channel: Anders Jensen
Views: 16,284
Rating: undefined out of 5
Keywords: power automate desktop, how to work with files and folders in power automate, power automate desktop tutorial, power automate folder, power automate files, anders jensen, power automate desktop move files, power automate desktop folder, microsoft, files and folder in power automate, file handling in power automate desktop, microsoft power automate desktop, sort files in power automate desktop, files and folders in power automate, power automate for desktop, files in power automate
Id: igl93T9Jrmc
Channel Id: undefined
Length: 30min 6sec (1806 seconds)
Published: Mon May 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.