How can get a list of files in a specific directory ignoring the symbolic links using python? -


I need to process a file names by creating a list of file names. But entries for symbolic links in my resulting list Also how can I get a pure file name in a special directory using Python?

I have tried: os.walk, os.listdir, os.path.isfile

but in the list 'filename' Symbolic links to:

glob.glob adds a path to the list. I do not need it.

I need to use it in a code like this:

  files = os.listdir (for folder) files f: dosomething (like  

Any help? Or redirect me to the right answer Thank you

Edit: The tilde signal is finally

to get regular files in the directory:

Import from Import Import OS S_SIREG:

For file name in Oslistdir (folder): Path = os.path.join (folder, f Ile name) Try: get information about file = strings = os.lstat (path) # (Do not follow symlink) error except environment: Continue # File disappeared or allowed Arrow R other: if S_ISREG (st .st_mode): Is there a regular file? If_something (filename)

If you are still viewing the filename of 'filename ~' , then that means they actually There are no Simlinks in them just use their names:

  

or fnmatch :

  import fnmatch filenames = fnmatch.filter (os.listdir (folder), '* [! ~] ')  

Comments