Skip to content Skip to sidebar Skip to footer

File Arrangement Different In Ubuntu Server

I have a problem retrieving the last file from some files with these filenames: On Windows localhost: On Ubuntu server: Its all arranged by year and by quarter. I need the last f

Solution 1:

os.listdir() returns a list in arbitrary order, which doesn't guarantee that the last file is always going to be the same. If you want the list to be ordered on both platforms, you need to sort it yourself by calling sort() or sorted() on the list returned by os.listdir().

A short example using your code:

filenames = os.listdir(edgar_path)
filenames.sort()
last_file = filenames[-1]

Post a Comment for "File Arrangement Different In Ubuntu Server"