Python Get File Properties from SharePoint Using Office365 Rest Package Part 6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what up guys what up what up guys in today's video this is part of the multi-part series video that i've been working on on the office 365 api and this is going to be part six so in this video we're gonna walk through the process and we're going to create a function to give us back file properties so for example some of the properties that we're going to have that we're going to pull back is going to be file name file size when the file was created uh the file id um what else think there's like one more but either way i'm gonna be pulling some of those file properties and you're gonna receive back a list of all the different files that belong to a folder so it's gonna be pretty much properties of all the files based on a sharepoint folder but before we get started guys hit that like button give me a follow again guys that like button go ahead and hit it hit it now all right guys let's get started okay guys so again those who are new go revisit part one if you have to but we're adding to our source code that we have we have a file called office 365 api so we're going to be adding to this file right that's ultimately what we're doing here we're adding to it so what i'm going to do i want to go ahead and come down and just add it towards the end we're going to create a function we're going to call this function get file properties from folder right because so and i'll explain to you on why we're doing it this way if you receive back a a file object there's properties associated already but if we're receiving it back on receiving a specific file object you could specify you want properties from from that file object but let's say you want to just retrieve back a list of whatever exists um in a folder maybe for free for instance the what you want to know is which files are part of that folder well this function that we're creating is going to give it back a list and you could just do a count and that could kind of tell you right away all right there's four four files in there um [Music] you know or you want to be able to determine which one is the newest file or you want to be able to determine um just the date like when were these files even created when they're updated you want to get some of that metadata right for each file this will provide that information for you even versions the which version of the file uh belong to you know um it's part of that file maybe it's already in version five version one whatever it is so let's kind of walk through and i'll kind of show you uh let me zoom in it's actually kind of small i don't need this let me minimize this down alright cool i think that's good enough all right so now what we're going to do let's create we're going to call this object files list and what we're gonna do here we're gonna call our git files function that we have so this function that we have here get file list which if i go up on top we have this up to something that we created from towards like part one i believe and what this is doing is give us giving us back a list of all the files right you know it's not specifying specific properties but just giving it back in the form of objects so pretty much we're getting back a list of every file object that's it right now from from this file object since we're arguing back a list of files and you know in a object uh not in a string format but in object format we're going to be able to extract key properties that we want and we're going to ultimately compile a dictionary of these properties so that's kind of what we're doing here so i'm going to create a proper tease let's call it list it's going to be empty because i'm going to add on to it and let's go ahead and do a for loop so we're gonna do four file in files list and then let's create a file dictionary oops and inside this dictionary we're going to go ahead and add some key properties that we're going to want to capture so for example the first one is going to be file id and this would be file uh unique id okay so every file has some kind of unique id relate related to it so that's the so this has given us the unique id if there's a need beyond that to use it in other ways then you know one again you could pull this list get the id and then do some other process if needed but nevertheless it's included in this we're going to capture that information so the next thing will be file name now this this is very key this is something that all means everybody would want right if you want to get a list of all the files in a folder file name is key we want that the next thing would be a major version a major version so anytime you create a new file and by default it's version one if you're making updates changes things of that nature that's where you'll see the version ultimately change uh depending on what kind of changes and all of that that's happening but nevertheless if your organization is managing versions to that level then yeah it makes sense to to retrieve that information so that would be included as well the other one will be minor versions again same thing if your organization is managing those kind of changes this will be included so you're you know what it is another one that i think would be somewhat um valuable is a file size like how big the file is you know so uh this could come in handy from a sense of if you're i don't know let's say there's some a good example to be you're trying to determine the size of a folder and you want to find out which file has the biggest size like and you know which one without having to go in manually one by one and look at all the folders uh the next one is going to be time time create it again same thing this one's always good to capture if you want to know how old a file is especially if you're doing some sort of um some sort of way to identify like all right i want to capture the new file the old files or maybe i only want to capture files that are 30 days older they could kind of build some logic to identify which one are 30 days within the 30-day range and then those you could like capture and do something with then of course last um modified and again this shows when the file with last modified i mean pretty straightforward so for now those are the the uh property that we're gonna capture um and then what we're gonna end up doing we're going to go ahead and call our property oops uh properties list and then we're going to append this dictionary okay and then what we're going to do is we're going to go ahead and clear out the dictionary so when we iterate over again it's a clean um empty object and then we'll just add on to it again oops and that is it man after that we're gonna then return uh the property list and that's it so ultimately we're going to get back by calling this function we're going to end up getting back a list a list that contains all the files that we have and of course these properties which is the id name version size create time pretty much we're going to be returning back um so i think this is it man this is all we need so now let me go ahead and create a file and let me call this file it's called the file properties from folder okay so now they just go ahead and let's bring in we're gonna have to bring in the office 365 api file and then we're going to import in sharepoint because sharepoint again is our class that we have over here yep now remember when we call this we already have all of these variables that are being assigned again if you're not familiar with how we did this go and reference part one we kind of walked through the process but we're assuming that you already watched that part so we're not going to go in detail let's go ahead and import system and then i'm going to do folder name but you know what before i do that this just go ahead and call this so argument oops arts one is going to be sharepoint folder name all right so that's ultimate we're gonna our argument gonna be the sharepoint name so in this case it will be system rs one right so not zero the reason why not to zero because in python when you call python and then you gotta specify your file that you're gonna execute that file is argument zero anything after that is argument one two and three so just fy um i'm gonna create a function so i've been told in the comments that these examples that i'm providing it's it's an overkill and honestly um i agree i totally agree right i'm not going to disagree it is an overkill but i do it because i know in certain cases these examples for some people they could literally take as is and and implement it in their um in their process or they can literally take the script and just have some sort of scheduler running that would just run it and then it would do what they want to do right and they don't even have to do anything to it so that's kind of the reason why i do it that way again is it i totally agree i'm not saying that it's not because it is but again i know that's the case and i'm i'm fine with it right um so all right i'm gonna create this function yeah i don't know why i'm calling this point it's not gonna be called get latest file so this function i'm gonna create we're going to call it uh get um properties by folder right that's what we're going to call it get properties by folder and then we're going to end up calling sharepoint git property file properties by folder and then we're going to end up specifying the the folder whatever this argument is that's what we're going to specify over here and then what i'm going to do i'm going to do a for loop because remember we're getting back a list this is what we're getting back so let's iterate over i'm going to call this file and file properties and then i can just for now let's just go ahead and and print file that's all we're going to do right so to finish it off um if name equals main then we could run this get property by folder then of course this would be our folder name argument so let's go ahead and let's go ahead and run it so i'm going to call python oops so python or you know what before i run it though let's go ahead and go to uh sharepoint i'm going to sales so as you could tell i have five files in here right csv json another csv excel and excel different types too right they've been modified different times and so on um like for example the excel i'm going to click on let's click on this excel i don't know what it is but let's click on it let's say i'm going to make some kind of change i don't know i'm going to change this to 0.9 cool it should have saved automatically and then now i can kind of come back hit refresh and um did it change and which file did i modify whether this one or the other one it says modified june 10s click it again oh it didn't change my bad there we go they did change 0.09 so i'm not sure what happened here but it did change so let me close out of it let me close out of it let me hit refresh there we go scene got modified it took a while but it's been modified it looks good right a few seconds ago so we should see that reflected when we pull our data but so we should get back five um a list of five but let's test out a few things right before we run it i want to iterate over each one right which is number one but also what i want to do here in the very beginning i'm going to do a print and i'm going to say um file count and this would be links file properties so again it should give us back five because that's what we know what it is right it's five um [Music] what else oops and then this will give us back the rows of each one so let's let's take a look at it right so it's python file property then again my first argument here is going to be the directory pass the folder pass so if i go back to my sharepoint it's going to be data 2022 sales so i'm going to type in data 2022 sales hit enter let's see what we get cool so we got something back let's expand this out boom right there file count equals five perfect because we know we have five and it did give us back a file count s5 so again this will be one of those good um function to call especially trying to keep count of how many files you have in a folder and boom right away right you get that uh i mean it will give you back the list but i got a links back of the the amount of files that are in there and then of course we could look at each one here's the one file we have a file id here's the grid we have the file name which is the 50 context csv and then we have the version version one minor version zero file size um 6 64 67 which is pretty much 6k there's a file size then of course we have the timestamps so let's look at the one that we modified which would have been this guy right here right this one was the one that we modified so we look at the created time created time would have been uh june 11th 2022 the time modified is what we just did right now which is um september 4th uh time frame so here's the thing it's really not september 4th but this is utc time so also keep that in mind this time that you see here is utc time so you're trying to convert it to your uh whether it be central eastern pacific you're gonna have to do the mass on it to convert it to um your local time but this is all utc time this one doesn't have a version and if you look at the major version changes in major version three and then of course minor version zero the file size 21k then of course you have your grid so again this will give you back just by specifying the folder the pass you can get back properties uh a list of all the files and properties and then from there you could do whatever you need to do with it right um but nevertheless though this you know will give you that information um which is pretty straightforward nothing complex you know right pretty straightforward so again guys this was a this actually came in as a request somebody requested about hey can you make a video showing how we could get some of the properties um and there may be may i may make another video where we add up more properties but for now i wanted to just add some of the least basic core properties uh to this function and then you know that seemed beneficial so again guys if there's uh i i mean i am putting some things to work well we i will be creating a discord server soon i will we're going to be building a small team um of people kind of helping out uh when it comes to some of the requests that i'm getting so you're gonna start seeing uh potentially you may see other people working more behind the scenes i guess maybe you may not see them in the videos and maybe i shouldn't say you're gonna see them but um there are some things that are in the works and in order to kind of to speed up expedite the process of making more videos um doing more testing and trying to solve some of these problems i'm starting to get more and more requests you know i'm going to be assembling a team behind the scenes that's going to help out to do some of the testing and things of that nature so we could push out more and more content uh solving the problems that we're getting right these are all questions that we're getting from viewers so that's the plan that's what we're trying to do that's what i'm gonna be working on i know it's not gonna be easy test and i know it's gonna take time you know but i think it's gonna be all worth it again guys give me a follow hit that um like button and appreciate it guys and y'all take care peace
Info
Channel: I am Lu
Views: 5,635
Rating: undefined out of 5
Keywords:
Id: GJKHKlm6pug
Channel Id: undefined
Length: 19min 45sec (1185 seconds)
Published: Wed Sep 07 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.