Python Is there any way "os.listdir ()" returns gibberish for a bad folder name?

I have a simple script written in Python:

import os

def Path(SourcePath):
    for Folder in os.listdir(SourcePath):
        print "TESTING: %s" % Folder

Path("\\\\192.168.0.36\\PDFs")

When I run it, it recurses through the remote share on the local network and simply displays the names of the found folders. This section contains folders.

The problem is that if the folder name has a space at the end of the name, the above script contains a jibberish list.

For example, if the folder above contains the following folders:

  • "6008386 HH - Walkers Crisps"
  • "6008157 CPP - Chocolate Chocolate"
  • "6007458 SCA - Morrisons Bananas"

Please note that "6008157 CPP - Santas Chocolate" takes place at the end. This is the list from the above script:

  • "TEST: 6008386 HH - Walkers Crisps"
  • ": 6EBA72 ~ 1"
  • ": 6007458 SCA - Morrisons Bananas"

? , "os.listdir()".

, ?

+3
2

Windows 8.3 "", CIFS , Windows.

, "Santas Chocolate" . Windows , .

, GetLongPathName - , . , , - , , , .

+4

(g | j) ibberish, short (8.3) filename. Windows, GetLongPathName() .

+3

Source: https://habr.com/ru/post/1718261/


All Articles