Python Forum
How dont' show hidden system files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How dont' show hidden system files
#1
I'm using Windows now. I would like know how I can don't show hidden files in Windows. For example:
import os
print(os.listdir(r'C:/Users/mike/'))
But I need to get only my files. How can I hide AppData, Ntuser.dat etc... ?
Reply
#2
Go after the files you are interested in

import glob

def get_dir(dir):
    for file in glob.glob(dir):
        print(file)

get_dir('Z:/python/forum/inspect/*.py')
results:
Output:
Z:/python/forum/inspect\ListVariables.py Z:/python/forum/inspect\MyTestClass.py Z:/python/forum/inspect\review.py
Reply
#3
(Jan-11-2018, 12:44 PM)Larz60+ Wrote: Go after the files you are interested in

import glob

def get_dir(dir):
    for file in glob.glob(dir):
        print(file)

get_dir('Z:/python/forum/inspect/*.py')
results:
Output:
Z:/python/forum/inspect\ListVariables.py Z:/python/forum/inspect\MyTestClass.py Z:/python/forum/inspect\review.py

I need all files and folders except hidden
Reply
#4
import os

def get_dir(dir):
    return [file for file in os.listdir(dir) if not file.startswith('.')]

print(get_dir('Z:/python/forum/inspect/'))
Reply
#5
(Jan-11-2018, 12:55 PM)Larz60+ Wrote: import os
 
def get_dir(dir):
    return [file for file in os.listdir(dir) if not file.startswith('.')]
 
print(get_dir('Z:/python/forum/inspect/'))

It shows all files and folders and hidden too.
Reply
#6
check this on SO for extensive discussion on cross platform hidden file detection

https://stackoverflow.com/a/6365265/4046632
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy only hidden files and folders with rsync Cannondale 2 997 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  I dont know why my function won't work? MehHz2526 3 1,194 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 2,231 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  PIL Image im.show() no show! Pedroski55 2 955 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  why I dont get any output from this code William369 2 1,123 Jun-23-2022, 09:18 PM
Last Post: William369
  Can ZipFile be used to extract hidden files? AiedailEclipsed 0 1,614 Mar-22-2022, 05:21 PM
Last Post: AiedailEclipsed
  PIL Image im.show() no show! Pedroski55 6 4,879 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,604 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Run hidden exe samuelbachorik 0 2,702 Aug-02-2020, 03:10 PM
Last Post: samuelbachorik
  [split] import PIL dont work vedansh 1 2,076 Mar-29-2020, 10:00 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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