Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing number of files per directory python

Tags:

python

I found several questions on this topic but none that addressed the problem I am seeing. I apologize in advance I'm new to python. What I am trying to do is count the number of files in every directory beneath somedir/ so I would get something like:

dir-a: 13
dir-b: 6
dir-c: 21

I thought the easiest way to prove I could do this would be:

from os import listdir
from os.path import isfile, isdir

def walk(p):
  for file in listdir(p):
    if isfile(file):
      print("File: " + file)
    elif isdir(file):
      print("Dir: " + file)
      walk(file)
    else:
      print("Unknown: " + file)

path = raw_input('Enter path to search')
walk(path)

But the first iteration is the only one that works as expected. I have tried adding the full path of the file with os.path.abspath and a couple other ways to ensure the file is the same in the first iteration as it is in recursive calls. I have checked the type with type(file) and it is 'str' and even if the path+filename is correct and exists the above program stills fails to produce the expected results. For example on a directory structure like:

dir-a/
     file-a.1
     file-a.2
     dir-b/
          file-b.1
          file-b.2
     file-a.3

I would expect:

File: file-a.1
File: file-a.2
Dir: dir-b
File: file-b.1
File: file-b.2
File: file-a.3

but I get:

File: file-a.1
File: file-a.2
Dir: dir-b
Unknown: file-b.1
Unknown: file-b.2
File: file-a.3

So basically all files are not getting identified as files or dirs on recursive calls. I looked through the docs on listdir, isfile, and isdir and it still doesn't make sense. I've tried with python 2.7.5 and 3.4.0, same behaviour. Any help is appreciated.

like image 396
achyrd Avatar asked Sep 29 '22 06:09

achyrd


1 Answers

You are correct about the absolute path thing. You can build the path yourself though by simply joining the contents of listdir on the variable passed to walk

from os import listdir
from os.path import isfile, isdir, join

def walk(p):
  for item in listdir(p):
    item = join(p, item)
    if isfile(item):
      print("File: " + item)
    elif isdir(item):
      print("Dir: " + item)
      walk(item)
    else:
      print("Unknown: " + item)

path = raw_input('Enter path to search')
walk(path)

Output (Note: errors out eventually cause I don't have root on this box so when it gets to /root it crashes, but that's easily catchable)

Enter path to search/
Dir: /tmp
Dir: /srv
Dir: /lib
Dir: /lib/systemd
Dir: /lib/systemd/system
File: /lib/systemd/system/dbus.socket
File: /lib/systemd/system/systemd-udev-settle.service
File: /lib/systemd/system/systemd-udev-trigger.service
File: /lib/systemd/system/dbus.service
File: /lib/systemd/system/[email protected]
File: /lib/systemd/system/systemd-udevd-control.socket
Dir: /lib/systemd/system/multi-user.target.wants
File: /lib/systemd/system/multi-user.target.wants/dbus.service
File: /lib/systemd/system/rsync.service
File: /lib/systemd/system/rsyslog.service
File: /lib/systemd/system/sudo.service
File: /lib/systemd/system/systemd-udevd-kernel.socket
File: /lib/systemd/system/systemd-udevd.service
File: /lib/systemd/system/ssh.service
File: /lib/systemd/system/udev.service
File: /lib/systemd/system/ssh.socket
Dir: /lib/systemd/system/sysinit.target.wants
File: /lib/systemd/system/sysinit.target.wants/systemd-udev-trigger.service
File: /lib/systemd/system/sysinit.target.wants/systemd-udevd.service
File: /lib/systemd/system/beanstalkd.service
File: /lib/systemd/system/beanstalkd.socket
Dir: /lib/systemd/system/dbus.target.wants
File: /lib/systemd/system/dbus.target.wants/dbus.socket
Dir: /lib/systemd/system/sockets.target.wants
File: /lib/systemd/system/sockets.target.wants/dbus.socket
File: /lib/systemd/system/sockets.target.wants/systemd-udevd-control.socket
File: /lib/systemd/system/sockets.target.wants/systemd-udevd-kernel.socket
File: /lib/systemd/system/dnsmasq.service
File: /lib/systemd/systemd-udevd
Dir: /lib/terminfo
Dir: /lib/terminfo/E
File: /lib/terminfo/E/Eterm-color
File: /lib/terminfo/E/Eterm
Dir: /lib/terminfo/m
File: /lib/terminfo/m/mach-gnu-color
File: /lib/terminfo/m/mach-bold
File: /lib/terminfo/m/mach
File: /lib/terminfo/m/mach-color
File: /lib/terminfo/m/mach-gnu
Dir: /lib/terminfo/s
File: /lib/terminfo/s/screen-256color-bce
File: /lib/terminfo/s/screen-bce
File: /lib/terminfo/s/screen
File: /lib/terminfo/s/screen-w
File: /lib/terminfo/s/screen-s
File: /lib/terminfo/s/screen-256color
File: /lib/terminfo/s/sun
Dir: /lib/terminfo/h
File: /lib/terminfo/h/hurd
Dir: /lib/terminfo/c
File: /lib/terminfo/c/cons25
File: /lib/terminfo/c/cygwin
File: /lib/terminfo/c/cons25-debian
Dir: /lib/terminfo/v
File: /lib/terminfo/v/vt220
File: /lib/terminfo/v/vt102
File: /lib/terminfo/v/vt52
File: /lib/terminfo/v/vt100
Dir: /lib/terminfo/x
File: /lib/terminfo/x/xterm-vt220
File: /lib/terminfo/x/xterm
File: /lib/terminfo/x/xterm-mono
File: /lib/terminfo/x/xterm-debian
File: /lib/terminfo/x/xterm-xfree86
File: /lib/terminfo/x/xterm-color
File: /lib/terminfo/x/xterm-256color
File: /lib/terminfo/x/xterm-r5
File: /lib/terminfo/x/xterm-r6
Dir: /lib/terminfo/a
File: /lib/terminfo/a/ansi
Dir: /lib/terminfo/d
File: /lib/terminfo/d/dumb
Dir: /lib/terminfo/w
File: /lib/terminfo/w/wsvt25m
File: /lib/terminfo/w/wsvt25
Dir: /lib/terminfo/r
File: /lib/terminfo/r/rxvt-basic
File: /lib/terminfo/r/rxvt-m
File: /lib/terminfo/r/rxvt-unicode
File: /lib/terminfo/r/rxvt
Dir: /lib/terminfo/l
File: /lib/terminfo/l/linux
Dir: /lib/terminfo/p
File: /lib/terminfo/p/pcansi
Dir: /lib/lsb
File: /lib/lsb/init-functions
Dir: /lib/lsb/init-functions.d
File: /lib/lsb/init-functions.d/50-ubuntu-logging
File: /lib/lsb/init-functions.d/20-left-info-blocks
Dir: /lib/modules-load.d
File: /lib/modules-load.d/fuse.conf
Dir: /lib/init
File: /lib/init/apparmor-profile-load
File: /lib/init/upstart-job
File: /lib/init/fstab
File: /lib/init/vars.sh
File: /lib/klibc-P2s_k-gf23VtrGgO2_4pGkQgwMY.so
Dir: /lib/security
File: /lib/security/pam_chroot.so
File: /lib/security/pam_mysql.so
Dir: /lib/ifupdown
File: /lib/ifupdown/settle-dad.sh
File: /lib/cpp
Dir: /lib/udev
File: /lib/udev/write_net_rules
File: /lib/udev/collect
File: /lib/udev/accelerometer
File: /lib/udev/hotplug.functions
Dir: /lib/udev/rules.d
File: /lib/udev/rules.d/75-tty-description.rules
File: /lib/udev/rules.d/73-idrac.rules
File: /lib/udev/rules.d/75-persistent-net-generator.rules
File: /lib/udev/rules.d/64-btrfs.rules
File: /lib/udev/rules.d/60-persistent-v4l.rules
File: /lib/udev/rules.d/60-persistent-serial.rules
File: /lib/udev/rules.d/60-persistent-storage-dm.rules
File: /lib/udev/rules.d/85-keyboard-configuration.rules
File: /lib/udev/rules.d/78-graphics-card.rules
File: /lib/udev/rules.d/60-keyboard.rules
File: /lib/udev/rules.d/75-net-description.rules
File: /lib/udev/rules.d/40-gnupg.rules
File: /lib/udev/rules.d/40-hyperv-hotadd.rules
File: /lib/udev/rules.d/60-persistent-alsa.rules
File: /lib/udev/rules.d/60-persistent-storage.rules
File: /lib/udev/rules.d/78-sound-card.rules
File: /lib/udev/rules.d/70-power-switch.rules
File: /lib/udev/rules.d/61-accelerometer.rules
File: /lib/udev/rules.d/55-dm.rules
File: /lib/udev/rules.d/50-udev-default.rules
File: /lib/udev/rules.d/60-persistent-storage-tape.rules
File: /lib/udev/rules.d/60-persistent-input.rules
File: /lib/udev/rules.d/60-cdrom_id.rules
File: /lib/udev/rules.d/80-drivers.rules
File: /lib/udev/rules.d/42-usb-hid-pm.rules
File: /lib/udev/rules.d/75-probe_mtd.rules
File: /lib/udev/rules.d/README
File: /lib/udev/rules.d/50-firmware.rules
File: /lib/udev/rules.d/95-udev-late.rules
File: /lib/udev/scsi_id
Dir: /lib/udev/hwdb.d
File: /lib/udev/hwdb.d/20-pci-classes.hwdb
File: /lib/udev/hwdb.d/20-acpi-vendor.hwdb
File: /lib/udev/hwdb.d/20-pci-vendor-model.hwdb
File: /lib/udev/hwdb.d/20-bluetooth-vendor-product.hwdb
File: /lib/udev/hwdb.d/20-usb-vendor-model.hwdb
File: /lib/udev/hwdb.d/20-OUI.hwdb
File: /lib/udev/hwdb.d/20-usb-classes.hwdb
File: /lib/udev/hwdb.d/60-keyboard.hwdb
File: /lib/udev/ata_id
File: /lib/udev/rule_generator.functions
File: /lib/udev/v4l_id
File: /lib/udev/hwdb.bin
File: /lib/udev/cdrom_id
File: /lib/udev/mtd_probe
File: /lib/udev/console-setup-tty
Dir: /lib/plymouth
Dir: /lib/plymouth/themes
Dir: /lib/plymouth/themes/details
File: /lib/plymouth/themes/details/details.plymouth
File: /lib/plymouth/ubuntu_logo.png
Dir: /lib/modprobe.d
Dir: /lib/resolvconf
File: /lib/resolvconf/list-records
Dir: /lib/x86_64-linux-gnu
File: /lib/x86_64-linux-gnu/libjson.so.0
File: /lib/x86_64-linux-gnu/libdevmapper.so.1.02.1
File: /lib/x86_64-linux-gnu/liblzma.so.5.0.0
File: /lib/x86_64-linux-gnu/libacl.so.1
File: /lib/x86_64-linux-gnu/libtinfo.so.5
File: /lib/x86_64-linux-gnu/libpamc.so.0.82.1
File: /lib/x86_64-linux-gnu/libncursesw.so.5
File: /lib/x86_64-linux-gnu/libexpat.so.1.6.0
File: /lib/x86_64-linux-gnu/libulockmgr.so.1.0.1
File: /lib/x86_64-linux-gnu/libutil.so.1
File: /lib/x86_64-linux-gnu/libkeyutils.so.1
File: /lib/x86_64-linux-gnu/libbsd.so.0.6.0
File: /lib/x86_64-linux-gnu/libbz2.so.1
File: /lib/x86_64-linux-gnu/libply-splash-graphics.so.2.1.0
File: /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4
File: /lib/x86_64-linux-gnu/libselinux.so.1
File: /lib/x86_64-linux-gnu/libsystemd-login.so.0.7.1
File: /lib/x86_64-linux-gnu/libnss_files-2.19.so
File: /lib/x86_64-linux-gnu/libnss_hesiod.so.2
File: /lib/x86_64-linux-gnu/libhistory.so.6
File: /lib/x86_64-linux-gnu/libBrokenLocale-2.19.so
File: /lib/x86_64-linux-gnu/liblzma.so.5
File: /lib/x86_64-linux-gnu/liblzo2.so.2
File: /lib/x86_64-linux-gnu/libpopt.so.0
File: /lib/x86_64-linux-gnu/libncurses.so.5
File: /lib/x86_64-linux-gnu/libc-2.19.so
File: /lib/x86_64-linux-gnu/libbz2.so.1.0
File: /lib/x86_64-linux-gnu/libply.so.2
File: /lib/x86_64-linux-gnu/libfuse.so.2
File: /lib/x86_64-linux-gnu/libply-boot-client.so.2.1.0
File: /lib/x86_64-linux-gnu/libdbus-1.so.3
File: /lib/x86_64-linux-gnu/libply-splash-graphics.so.2
File: /lib/x86_64-linux-gnu/libBrokenLocale.so.1
File: /lib/x86_64-linux-gnu/libuuid.so.1
File: /lib/x86_64-linux-gnu/libnss_nis.so.2
File: /lib/x86_64-linux-gnu/libcgmanager.so.0
File: /lib/x86_64-linux-gnu/libSegFault.so
File: /lib/x86_64-linux-gnu/libnss_dns.so.2
File: /lib/x86_64-linux-gnu/libcgmanager.so.0.0.0
File: /lib/x86_64-linux-gnu/libnih-dbus.so.1
File: /lib/x86_64-linux-gnu/libnewt.so.0.52.15
File: /lib/x86_64-linux-gnu/libncurses.so.5.9
File: /lib/x86_64-linux-gnu/libblkid.so.1.1.0
File: /lib/x86_64-linux-gnu/libpthread.so.0
File: /lib/x86_64-linux-gnu/libpam_misc.so.0.82.0
File: /lib/x86_64-linux-gnu/libglib-2.0.so.0
File: /lib/x86_64-linux-gnu/libcidn-2.19.so
File: /lib/x86_64-linux-gnu/libgcc_s.so.1
File: /lib/x86_64-linux-gnu/libnss_nisplus-2.19.so
File: /lib/x86_64-linux-gnu/libpopt.so.0.0.0
File: /lib/x86_64-linux-gnu/libwrap.so.0
File: /lib/x86_64-linux-gnu/libpam_misc.so.0
File: /lib/x86_64-linux-gnu/libss.so.2
File: /lib/x86_64-linux-gnu/libcap.so.2.24
File: /lib/x86_64-linux-gnu/libply-splash-core.so.2
File: /lib/x86_64-linux-gnu/libkeyutils.so.1.4
File: /lib/x86_64-linux-gnu/libudev.so.1.3.5
File: /lib/x86_64-linux-gnu/libslang.so.2
File: /lib/x86_64-linux-gnu/libe2p.so.2.3
File: /lib/x86_64-linux-gnu/libmount.so.1.1.0
File: /lib/x86_64-linux-gnu/ld-2.19.so
File: /lib/x86_64-linux-gnu/libjson-c.so.2
File: /lib/x86_64-linux-gnu/libply.so.2.1.0
File: /lib/x86_64-linux-gnu/libply-splash-core.so.2.1.0
File: /lib/x86_64-linux-gnu/libuuid.so.1.3.0
File: /lib/x86_64-linux-gnu/libcrypt.so.1
File: /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0
File: /lib/x86_64-linux-gnu/libpcre.so.3
File: /lib/x86_64-linux-gnu/librt-2.19.so
File: /lib/x86_64-linux-gnu/libutil-2.19.so
File: /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0
File: /lib/x86_64-linux-gnu/libusb-0.1.so.4
File: /lib/x86_64-linux-gnu/libncursesw.so.5.9
File: /lib/x86_64-linux-gnu/libaudit.so.1.0.0
File: /lib/x86_64-linux-gnu/libblkid.so.1
File: /lib/x86_64-linux-gnu/libcom_err.so.2
File: /lib/x86_64-linux-gnu/libmount.so.1
File: /lib/x86_64-linux-gnu/libbz2.so.1.0.4
File: /lib/x86_64-linux-gnu/libc.so.6
File: /lib/x86_64-linux-gnu/libnss_nis-2.19.so
File: /lib/x86_64-linux-gnu/libpamc.so.0
File: /lib/x86_64-linux-gnu/libm.so.6
File: /lib/x86_64-linux-gnu/libext2fs.so.2
File: /lib/x86_64-linux-gnu/libexpat.so.1
File: /lib/x86_64-linux-gnu/libpng12.so.0.50.0
File: /lib/x86_64-linux-gnu/libthread_db-1.0.so
File: /lib/x86_64-linux-gnu/libext2fs.so.2.4
File: /lib/x86_64-linux-gnu/libpam.so.0.83.1
File: /lib/x86_64-linux-gnu/libreadline.so.6.3
File: /lib/x86_64-linux-gnu/libanl.so.1
File: /lib/x86_64-linux-gnu/libe2p.so.2
File: /lib/x86_64-linux-gnu/libgpg-error.so.0
File: /lib/x86_64-linux-gnu/libresolv-2.19.so
File: /lib/x86_64-linux-gnu/libgcrypt.so.11
File: /lib/x86_64-linux-gnu/libnsl-2.19.so
File: /lib/x86_64-linux-gnu/liblzo2.so.2.0.0
File: /lib/x86_64-linux-gnu/libwrap.so.0.7.6
File: /lib/x86_64-linux-gnu/libdbus-1.so.3.7.6
File: /lib/x86_64-linux-gnu/libpng12.so.0
File: /lib/x86_64-linux-gnu/libmemusage.so
File: /lib/x86_64-linux-gnu/libacl.so.1.1.0
File: /lib/x86_64-linux-gnu/librt.so.1
File: /lib/x86_64-linux-gnu/libattr.so.1
File: /lib/x86_64-linux-gnu/libattr.so.1.1.0
File: /lib/x86_64-linux-gnu/libpcprofile.so
File: /lib/x86_64-linux-gnu/libudev.so.1
File: /lib/x86_64-linux-gnu/libnss_compat-2.19.so
File: /lib/x86_64-linux-gnu/libm-2.19.so
File: /lib/x86_64-linux-gnu/libnih.so.1.0.0
File: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
File: /lib/x86_64-linux-gnu/libply-boot-client.so.2
File: /lib/x86_64-linux-gnu/libulockmgr.so.1
File: /lib/x86_64-linux-gnu/libjson-c.so.2.0.0
Dir: /lib/x86_64-linux-gnu/security
File: /lib/x86_64-linux-gnu/security/pam_env.so
File: /lib/x86_64-linux-gnu/security/pam_stress.so
File: /lib/x86_64-linux-gnu/security/pam_succeed_if.so
File: /lib/x86_64-linux-gnu/security/pam_nologin.so
File: /lib/x86_64-linux-gnu/security/pam_localuser.so
File: /lib/x86_64-linux-gnu/security/pam_xauth.so
File: /lib/x86_64-linux-gnu/security/pam_tty_audit.so
File: /lib/x86_64-linux-gnu/security/pam_faildelay.so
File: /lib/x86_64-linux-gnu/security/pam_group.so
File: /lib/x86_64-linux-gnu/security/pam_shells.so
File: /lib/x86_64-linux-gnu/security/pam_warn.so
File: /lib/x86_64-linux-gnu/security/pam_selinux.so
File: /lib/x86_64-linux-gnu/security/pam_wheel.so
File: /lib/x86_64-linux-gnu/security/pam_issue.so
File: /lib/x86_64-linux-gnu/security/pam_umask.so
File: /lib/x86_64-linux-gnu/security/pam_debug.so
File: /lib/x86_64-linux-gnu/security/pam_limits.so
File: /lib/x86_64-linux-gnu/security/pam_mail.so
File: /lib/x86_64-linux-gnu/security/pam_securetty.so
File: /lib/x86_64-linux-gnu/security/pam_deny.so
File: /lib/x86_64-linux-gnu/security/pam_tally.so
File: /lib/x86_64-linux-gnu/security/pam_rhosts.so
File: /lib/x86_64-linux-gnu/security/pam_ftp.so
File: /lib/x86_64-linux-gnu/security/pam_keyinit.so
File: /lib/x86_64-linux-gnu/security/pam_loginuid.so
File: /lib/x86_64-linux-gnu/security/pam_lastlog.so
File: /lib/x86_64-linux-gnu/security/pam_userdb.so
File: /lib/x86_64-linux-gnu/security/pam_unix.so
File: /lib/x86_64-linux-gnu/security/pam_echo.so
File: /lib/x86_64-linux-gnu/security/pam_time.so
File: /lib/x86_64-linux-gnu/security/pam_rootok.so
File: /lib/x86_64-linux-gnu/security/pam_pwhistory.so
File: /lib/x86_64-linux-gnu/security/pam_listfile.so
File: /lib/x86_64-linux-gnu/security/pam_cap.so
File: /lib/x86_64-linux-gnu/security/pam_filter.so
File: /lib/x86_64-linux-gnu/security/pam_permit.so
File: /lib/x86_64-linux-gnu/security/pam_exec.so
File: /lib/x86_64-linux-gnu/security/pam_namespace.so
File: /lib/x86_64-linux-gnu/security/pam_mkhomedir.so
File: /lib/x86_64-linux-gnu/security/pam_tally2.so
File: /lib/x86_64-linux-gnu/security/pam_timestamp.so
File: /lib/x86_64-linux-gnu/security/pam_sepermit.so
File: /lib/x86_64-linux-gnu/security/pam_motd.so
File: /lib/x86_64-linux-gnu/security/pam_access.so
File: /lib/x86_64-linux-gnu/libnih-dbus.so.1.0.0
File: /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
File: /lib/x86_64-linux-gnu/libgcrypt.so.11.8.2
File: /lib/x86_64-linux-gnu/libfuse.so.2.9.2
File: /lib/x86_64-linux-gnu/libprocps.so.3.0.0
File: /lib/x86_64-linux-gnu/libsystemd-login.so.0
File: /lib/x86_64-linux-gnu/libcidn.so.1
File: /lib/x86_64-linux-gnu/libcrypt-2.19.so
File: /lib/x86_64-linux-gnu/libanl-2.19.so
File: /lib/x86_64-linux-gnu/libnih.so.1
File: /lib/x86_64-linux-gnu/libnsl.so.1
File: /lib/x86_64-linux-gnu/libhistory.so.6.3
File: /lib/x86_64-linux-gnu/libpthread-2.19.so
File: /lib/x86_64-linux-gnu/libpam.so.0
File: /lib/x86_64-linux-gnu/libtinfo.so.5.9
File: /lib/x86_64-linux-gnu/libcom_err.so.2.1
File: /lib/x86_64-linux-gnu/libnss_dns-2.19.so
File: /lib/x86_64-linux-gnu/libgpg-error.so.0.10.0
File: /lib/x86_64-linux-gnu/libkmod.so.2
File: /lib/x86_64-linux-gnu/libnss_nisplus.so.2
File: /lib/x86_64-linux-gnu/libaudit.so.1
File: /lib/x86_64-linux-gnu/libdl.so.2
File: /lib/x86_64-linux-gnu/libcap.so.2
File: /lib/x86_64-linux-gnu/libslang.so.2.2.4
Dir: /lib/x86_64-linux-gnu/plymouth
File: /lib/x86_64-linux-gnu/plymouth/details.so
File: /lib/x86_64-linux-gnu/plymouth/script.so
Dir: /lib/x86_64-linux-gnu/plymouth/renderers
File: /lib/x86_64-linux-gnu/plymouth/renderers/vga16fb.so
File: /lib/x86_64-linux-gnu/plymouth/renderers/frame-buffer.so
File: /lib/x86_64-linux-gnu/plymouth/renderers/drm.so
File: /lib/x86_64-linux-gnu/libdl-2.19.so
File: /lib/x86_64-linux-gnu/libnewt.so.0.52
File: /lib/x86_64-linux-gnu/libssl.so.1.0.0
File: /lib/x86_64-linux-gnu/libprocps.so.3
File: /lib/x86_64-linux-gnu/libkmod.so.2.2.5
File: /lib/x86_64-linux-gnu/libsepol.so.1
File: /lib/x86_64-linux-gnu/libreadline.so.6
File: /lib/x86_64-linux-gnu/libnss_files.so.2
File: /lib/x86_64-linux-gnu/libthread_db.so.1
File: /lib/x86_64-linux-gnu/libnss_compat.so.2
File: /lib/x86_64-linux-gnu/libz.so.1
File: /lib/x86_64-linux-gnu/libss.so.2.0
File: /lib/x86_64-linux-gnu/libusb-1.0.so.0
File: /lib/x86_64-linux-gnu/libnss_hesiod-2.19.so
File: /lib/x86_64-linux-gnu/libpcre.so.3.13.1
File: /lib/x86_64-linux-gnu/libz.so.1.2.8
File: /lib/x86_64-linux-gnu/libbsd.so.0
File: /lib/x86_64-linux-gnu/libresolv.so.2
Dir: /mnt
Dir: /root
Traceback (most recent call last):
  File "/home/ngenator/StackOverflow/27373035.py", line 16, in <module>
    walk(path)
  File "/home/ngenator/StackOverflow/27373035.py", line 11, in walk
    walk(item)
  File "/home/ngenator/StackOverflow/27373035.py", line 5, in walk
    for item in listdir(p):
OSError: [Errno 13] Permission denied: '/root'
like image 184
Ngenator Avatar answered Oct 04 '22 02:10

Ngenator