# Open the latest file

**URL:** <https://forum.inductiveautomation.com/t/open-the-latest-file/15464>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [September 25, 2017, 4:02pm UTC](https://forum.inductiveautomation.com/t/open-the-latest-file/15464 "2017-09-25T16:02:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [September 25, 2017, 4:02pm UTC](https://forum.inductiveautomation.com/t/open-the-latest-file/15464/1 "2017-09-25T16:02:18Z")

</div>

Now I use the script “system.file.openFile(‘pdf’,‘D:\reports\PT\_Report\PT\_Report\_2017-09-20\_17\_45\_33.pdf’)”,or "system.file.openFile(‘pdf’,'D:\reports\PT\_Report"but I can’t open a pdf file,after open a file dialog box, select the file, but can not open the PDF file,why?  
This pdf file takes time as the file name, the folder has a lot of such PDF files, I need to query the latest file and open it, how should I do ?

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [September 25, 2017, 4:32pm UTC](https://forum.inductiveautomation.com/t/open-the-latest-file/15464/2 "2017-09-25T16:32:03Z")

</div>

It would be easy to do this with some python code…

> <https://stackoverflow.com/questions/39327032/how-to-get-the-latest-file-in-a-folder>

something like the below example would work, then pass the latest file into the openFile()

```auto
import glob
import os

list_of_files = glob.glob('/path/to/folder/*') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
print latest_file

```

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [September 26, 2017, 1:20am UTC](https://forum.inductiveautomation.com/t/open-the-latest-file/15464/3 "2017-09-26T01:20:52Z")

</div>

Hi , now I can use this find a latest pdf file like this , then I use :  
os.popen(r’“D:\Program Files\Foxit Software\Foxit Reader\FoxitReader.exe” filename1’) , filename1 is the file path"D:\reports\PT\_Report\PT\_Report\_2017-09-26\_01\_01\_00.pdf" , I can’t open it , but use “os.popen(r’“D:\Program Files\Foxit Software\Foxit Reader\FoxitReader.exe” D:\reports\PT\_Report\PT\_Report\_2017-09-26\_01\_01\_00.pdf’)”  
I can open the file, why?

---

<div class="post-metadata">

**Author:** ![lautry](https://avatars.discourse-cdn.com/v4/letter/l/a8b319/32.png) [@lautry](https://forum.inductiveautomation.com/u/lautry)\
**Post date:** [September 26, 2017, 6:58pm UTC](https://forum.inductiveautomation.com/t/open-the-latest-file/15464/4 "2017-09-26T18:58:02Z")

</div>

> [@Updating Image component based off of newest image in a directory](http://forum.inductiveautomation.com/t/updating-image-component-based-off-of-newest-image-in-a-directory/14972):
>
> Hello all, I’m working with a Cognex camera currently, it isn’t an In-Sight series, so it doesn’t have the simple FTP push to server functionality. It uses VisionPro and Cognex Designer which do not allow this as easy. So, a work around I am trying to perform is to have a directory of images on the same system that Ignition is hosted on be the source location for an Image component. I would want it to be updated via the one that is most recently put into the source pathway. I found a post by …

I suggest checking here for any possible help you may find.
