modes in xgiven bytes argumentthis function will return filenames as encoded byte stringsgiven normal str string argumentit instead returns filenames as unicode stringsdecoded per the filesystem' encoding schemec:\pp \system\filetoolspython import os os listdir(')[: ['bigext-tree py''bigpy-dir py''bigpy-path py''bigpy-tree py'os listdir( ')[: [ 'bigext-tree py' 'bigpy-dir py' 'bigpy-path py' 'bigpy-tree py'the byte string version can be used if undecodable file names may be present because os walk and glob glob both work by calling os listdir internallythey inherit this behavior by proxy the os walk tree walkerfor examplecalls os listdir at each directory levelpassing byte string arguments suppresses decoding and returns byte string resultsfor (dirsubsfilesin os walk(')print(dir\environment \filetools \processes for (dirsubsfilesin os walk( ')print(dirbb\\environmentb\\filetoolsb\\processesthe glob glob tool similarly calls os listdir internally before applying name patternsand so also returns undecoded byte string names for byte string argumentsglob glob(\*')[: [\\bigext-out txt'\\bigext-tree py'\\bigpy-dir py'glob glob( \*')[: [ \\bigext-out txt' \\bigext-tree py' \\bigpy-dir py'given normal string name (as command-line argumentfor example)you can force the issue by converting to byte strings with manual encoding to suppress decodingname os listdir(name encode())[: [ 'bigext-out txt' 'bigext-tree py' 'bigpy-dir py' 'bigpy-path py'the upshot is that if your directories may contain names which cannot be decoded according to the underlying platform' unicode encoding schemeyou may need to pass byte strings to these tools to avoid unicode encoding errors you'll get byte strings backwhich may be less readable if printedbut you'll avoid errors while traversing directories and files directory tools