earnestt1234 / seedir

A Python package for creating, editing, and reading folder tree diagrams
MIT License
122 stars 9 forks source link

Significant different outline with same command #24

Closed starrry123 closed 1 year ago

starrry123 commented 1 year ago

Hi, I'm trying to get a tree structure of a network folder. What I noticed is that when directory structures are really deep and complicated, each time you get different output.

Please see below photo(path is masked as it's company related information.) The 1st run I got 22580 lines, the 2nd run with exact same command I got 11680 lines, 3rd time I got 21268 lines, and the other time I got 71314 lines. It appears when you got less output lines, some folders were not scanned, and not showing sub-folders and files. image

Environment: Python: '3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]' IDE: IDLE

starrry123 commented 1 year ago

The problem might be from print function. When you have large amount of output string, print() probably will truncated resulted in partial output.

earnestt1234 commented 1 year ago

Interesting! If it is due to the printing, you could try to use s = sd.seedir(..., printout=False) to get the output as a string. You could run the command multiple times assigning to different variables, and see if you get the same answer.

But I still would think that any truncation due to printing would be the same if the inputs were the same. My initial guess was instead that the file system is listing the files in a different order each call. Generally, the order of files returned by os.listdir is arbitrary (and seedir uses this function). When using depthlimit=100, this could change which folders are included each call, and thus how long the total diagram is. I have definitely seen different operating systems return the "same" folder structure in different orders, though I would be a little surprised if the order was changing between individual calls.

To check this, you could try passing sort=True to your call - then each folder will be Python sorted and the order should be determined. If you still get different sized outputs, then something else may be going on.