python - Return files only from specific folder -


I wrote a function in Python, which would have to return the file from a specific folder and all subfolders. File name taken from function parameter:

  def ReturnFile (fileName) returns open ("C: \\ folder \\" + fileName, "r")  

But as the filename you can pass for example: ".. \\ Windows \\ passwords.txt " or some unicode symbols for dots .

How to fix it? Maybe some RegExp might be?

The function resolves a given path such as ".." after that you can check The resultant path is in the expected directory:

  def ReturnFile (fileName) norm = os.path.abspath ("C: \\ folder \\" + fileName) if  
no

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -