Python Forum
Failing to get Stat for a Directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Failing to get Stat for a Directory
#11
(Jul-20-2021, 09:40 PM)tester_V Wrote: Sorry for the confusion!
If a directory has a file or 2 or 100 files but each file has a size=0, the directory size is also=0.

That depends on the filesystem. You cannot take that as a rule. Try it on another filesystem (even on the same machine) and that expectation may be broken.

Here's a directory on my machine (appears to be an xfs filesystem) with nothing but 3 empty files. But the "size" of the directory is not zero.

Output:
$ ls -lns total 0 0 -rw-r--r-- 1 29324 101 0 Jul 20 14:56 a 0 -rw-r--r-- 1 29324 101 0 Jul 20 14:56 b 0 -rw-r--r-- 1 29324 101 0 Jul 20 14:56 c $ python3 -c 'from pathlib import Path; print(Path(".").stat().st_size)' 33
Quote:I'm not looking if a directory has file/files or not because if it has a file and filesize=0 it is an "Empty" directory.

It is an empty file. To call it an empty directory is against common usage. An empty directory has no members and rmdir() will succeed on it. Your directory does not match that description.

Quote:I'm looking if a directory size is =0. I thought I could do that with 'pathil.Path'.

You can do that with Path, but the meaning of such directories depends on knowing the specific filesystem you are dealing with. As such it is not recommended. It will fail when you do not expect. Don't do it that way.

I don't have access to a NTFS filesystem at the moment. Your code does exactly what I would expect on my filesystem.

Output:
Directory -> empty Size -> 6 Not Empty Dir ->6 Directory -> full Size -> 15 Not Empty Dir ->15 Directory -> half Size -> 15 Not Empty Dir ->15
Reply
#12
OK, now i understand what it is your trying to do.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failing to connect by 'net use' tester_V 1 163 Apr-20-2024, 06:31 AM
Last Post: tester_V
  Failing regex tester_V 3 1,177 Aug-16-2022, 03:53 PM
Last Post: deanhystad
  Unknown Error with Random Stat Assigner FC8 6 2,322 Dec-06-2021, 01:56 PM
Last Post: FC8
  Failing to connect to a host with WMI tester_V 6 4,381 Aug-10-2021, 06:25 PM
Last Post: tester_V
  Failing to Zip files tester_V 4 2,160 Dec-01-2020, 07:28 AM
Last Post: tester_V
  Python 3.8 on mac failing to start sgandon 0 2,907 Jan-14-2020, 10:58 AM
Last Post: sgandon
  trying to install oandapy and failing ErnestTBass 0 1,900 Feb-24-2019, 06:13 PM
Last Post: ErnestTBass
  Pyinstaller failing JP_ROMANO 2 4,066 Jan-16-2019, 06:07 PM
Last Post: JP_ROMANO
  Why is my for loop failing? microphone_head 4 2,985 Sep-11-2018, 01:21 PM
Last Post: microphone_head

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020