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\xb fn.exe' 2 1267
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\xb fn.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:\\t emp'). 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
In <ma************ *************** ***********@pyt hon.org>, 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\xb fn.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcello Pietrobon |
last post by:
Hello,
I am using Pyton 2.3
I desire to walk a directory without recursion
this only partly works:
def walk_files() :
for root, dirs, files in os.walk(top, topdown=True):
for filename in files:
print( "file:" + os.path.join(root, filename) )
for dirname in dirs:
|
by: Frans Englich |
last post by:
Hello,
Have a look at this recursive function:
def walkDirectory( directory, element ):
element = element.newChild( None, "directory", None ) # automatically
appends to parent
element.setProp( "name", os.path.basename(directory))
|
by: rbt |
last post by:
I'm trying to write very small, modular code as functions to break up a
big monolithic script that does a file system search for particular
strings. The script works well, but it's not easy to maintain or add
features to.
I'd like to have a function that builds a list of files with os.walk()
and then have other functions accept that list as...
|
by: rbt |
last post by:
This function is intended to remove unwanted files and dirs from
os.walk(). It will return correctly *IF* I leave the 'for fs in
fs_objects' statement out (basically leave out the entire purpose of the
function).
It's odd, when the program goes into that statment... even when only a
'pass', and nothing else is present, nothing is returned....
|
by: Ministeyr |
last post by:
Hello,
os.walk doc: http://www.python.org/doc/2.4/lib/os-file-dir.html#l2h-1625
When walking top to bottom, it allows you to choose the directories you
want to visit dynamically by changing the second parameter of the tuple
(a list of directories). However, since it is a tuple, you cannot use
"filter" on it, since it would mean...
| |
by: delraydog |
last post by:
It's quite simple to walk to the DOM tree going forward however I can't
figure out a nice clean way to walk the DOM tree in reverse. Checking
previousSibling is not sufficient as the previousSibling could be a
node which has childNodes and therefore the 'true' previousSibling
would be the *deepest* lastChild of the previousSibling...
For...
|
by: Bruce |
last post by:
Hi all,
I have a question about traversing file systems, and could use some
help. Because of directories with many files in them, os.walk appears
to be rather slow. I`m thinking there is a potential for speed-up since
I don`t need os.walk to report filenames of all the files in every
directory it visits. Is there some clever way to use...
|
by: silverburgh.meryl |
last post by:
i am trying to use python to walk thru each subdirectory from a top
directory. Here is my script:
savedPagesDirectory = "/home/meryl/saved_pages/data"
dir=open(savedPagesDirectory, 'r')
for file in dir:
if (isdir(file)):
# get the full path of the file
|
by: Jeff McNeil |
last post by:
Your args are fine, that's just the way os.path.walk works. If you
just need the absolute pathname of a directory when given a relative
path, you can always use os.path.abspath, too.
A couple more examples that may help, using os.walk:
.... for j in i + i:
.... print os.path.join(i, j)
....
/var/log/apache2
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |