By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

os.walk return hex excapes

P: n/a
Hi,
os.walk return hex excape sequence inside a files name, and when i try
to feed it back to os.remove i get

OSError: [Errno 22] Invalid argument:
'C:\\Temp\\?p?\xbfS\xbf\xac?G\xaba ACDSee \xbb?a??n a???\xac\xb5\xbfn.exe'

Nov 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Alex S wrote:
Hi,
os.walk return hex excape sequence inside a files name, and when i try
to feed it back to os.remove i get

OSError: [Errno 22] Invalid argument:
'C:\\Temp\\?p?\xbfS\xbf\xac?G\xaba ACDSee \xbb?a??n a???\xac\xb5\xbfn.exe'
It's not escape sequences that are the problem but question marks, I
suspect. Most likely this file name contains characters not in your
locale's language. To access this file name you need to use unicode,
just make sure the first parameter of os.walk is a unicode string, for
example: os.walk(u'c:\\temp'). The exact code how to make the first
parameter unicode depends on where it is coming from (network, config
file, registry, etc...) Reading unicode tutorial is highly recommended.

-- Leo

Nov 28 '06 #2

P: n/a
In <ma**************************************@python.o rg>, Alex S wrote:
os.walk return hex excape sequence inside a files name, and when i try
to feed it back to os.remove i get

OSError: [Errno 22] Invalid argument:
'C:\\Temp\\?p?\xbfS\xbf\xac?G\xaba ACDSee \xbb?a??n a???\xac\xb5\xbfn.exe'
There is no hex escape in that file name, just in the representation you
get in the error message. The `repr()` form of a string contains just
ASCII, everything outside printable ASCII characters is printed as hex
escape so you can see what the string actually contains without being
interpreted by the shell, IDE or wherever the string is displayed.

How does the real file name look like?

Ciao,
Marc 'BlackJack' Rintsch

Nov 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.