Hi All, Even though I am a old user in the mailing list, my skills in Python are not impressive. I have restarted doing python for some small task. I am trying to find the latest file in a dir, I have searched and found out I shoulld do in this way ---------------- #!/usr/bin/python
import os newest = max(os.listdir("/opt/AlfDB/."), key = os.path.getctime) print newest ----------------------- but when I run it I am getting error message such as ./FindingLatestFileInDir.py Traceback (most recent call last): File "./FindingLatestFileInDir.py", line 4, in <module> newest = max(os.listdir("/opt/AlfDB/."), key = os.path.getctime) File "/usr/lib64/python2.7/genericpath.py", line 64, in getctime return os.stat(filename).st_ctime OSError: [Errno 2] No such file or directory: 'alfresco20140104-0000.sql' ------------------------------------------------------ I get results if I do it without giving the dir location such as --- #!/usr/bin/python import os newest = max(os.listdir("."), key = os.path.getctime) print newest --------------------- This gives the result for the directory from where it runs, but when I change the dir location to "/opt/AlfDB" , It does not. I am not able to apprehend how it is not working Guidance and advice requested Thanks Joseph John
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor