cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tommofin
Frequent Visitor

Python - Does not import os and import glob

Hey all,

 

Im trying to run a script that finds the most recently modified file in a folder and returns the file path. The python script works perfectly in Atom but for some reason, import os & glob are not recognised. 


Does anyone know of a way around this? Or point me in the right direction?

 

Junior engineer here looking to impress my boss by automating the payroll process 

Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions

When you use this:

https://docs.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/folder#getfiles

it outputs "The retrieved files as a list of file objects"

 

Lists are described here: https://docs.microsoft.com/en-us/power-automate/desktop-flows/variable-data-types#advanced-data-type...

To retrieve a specific item of a list, use the following notation: %VariableName[ItemNumber]%

 

Files object is described here:

https://docs.microsoft.com/en-us/power-automate/desktop-flows/datatype-properties#files

 

So file path of first file would be:

%VariableName[0].FullName%

View solution in original post

4 REPLIES 4
fraenK
Memorable Member
Memorable Member

Did you add the lib folder of your Python installation under "Module folder paths"?

 

But you don't need Python fir this, just use the get files in folder action and set the sorting to last modified:

https://docs.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/folder#getfiles

tommofin
Frequent Visitor

Thank you for the response. 

 

I did try this already. HCapture.PNG

 

owever, I need a file path (file path of the latest modified file in the folder) as an input argument to launch excel. I do not know how to pick the first item from the sorting list by last modified. Do you know of a way to do this?

When you use this:

https://docs.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/folder#getfiles

it outputs "The retrieved files as a list of file objects"

 

Lists are described here: https://docs.microsoft.com/en-us/power-automate/desktop-flows/variable-data-types#advanced-data-type...

To retrieve a specific item of a list, use the following notation: %VariableName[ItemNumber]%

 

Files object is described here:

https://docs.microsoft.com/en-us/power-automate/desktop-flows/datatype-properties#files

 

So file path of first file would be:

%VariableName[0].FullName%

tommofin
Frequent Visitor

fraenk you are a legend. Thank you 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Top Kudoed Authors
Users online (4,311)