Hello,
I'm writing an application in my pastime that moves files around to
achieve various ends -- the specifics aren't particularly important.
The shutil module was chosen as the means simply because that is what
google and chm searches returned most often.
My problem has to do with shutil.move actually putting the files where
I ask it to. Citing code wouldn't serve any purpose, because I am
using the function in the most straight forward manner, ex:
shutil.move( "C:\omg.txt " , "C:\folder\subd ir" )
In my script, rather than a file being moved to the desired location,
it is, rather, moved to the current working directory (in this case,
my desktop -- without any exceptions, mind you). As it happens, the
desired locations are system folders (running windows xp, the folders
are as follows: C:\WINDOWS, C:\WINDOWS\SYST EM, C:\WINDOWS\SYST EM32).
To see if this factor was causing the problem, I tried it using the
interpreter, and found it to be flawless.
My question boils down to this: What factors could possibly cause
shutil.move to fail to move a file to the desired location, choosing
instead to place it in the cwd (without raising any exceptions)?
Thank you for your time,
Daniel Bickett
P.S. I know I said I didn't need to post code, but I will anyway. You
never know :) http://rafb.net/paste/results/FcwlEw86.html 6 3607
I don't know if this is the problem or, not, but:
shutil.move( "C:\omg.txt " , "C:\folder\subd ir" )
Needs to have some special handling for the backslashes.
Either:
shutil.move( r"C:\omg.txt " , r"C:\folder\sub dir" )
or:
shutil.move( "C:\\omg.tx t" , "C:\\folder\\su bdir" )
-Don
Daniel Bickett wrote: Hello,
I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply because that is what google and chm searches returned most often.
My problem has to do with shutil.move actually putting the files where I ask it to. Citing code wouldn't serve any purpose, because I am using the function in the most straight forward manner, ex:
shutil.move( "C:\omg.txt " , "C:\folder\subd ir" )
In my script, rather than a file being moved to the desired location, it is, rather, moved to the current working directory (in this case, my desktop -- without any exceptions, mind you). As it happens, the desired locations are system folders (running windows xp, the folders are as follows: C:\WINDOWS, C:\WINDOWS\SYST EM, C:\WINDOWS\SYST EM32). To see if this factor was causing the problem, I tried it using the interpreter, and found it to be flawless.
My question boils down to this: What factors could possibly cause shutil.move to fail to move a file to the desired location, choosing instead to place it in the cwd (without raising any exceptions)?
Thank you for your time,
Daniel Bickett
P.S. I know I said I didn't need to post code, but I will anyway. You never know :)
http://rafb.net/paste/results/FcwlEw86.html
Don wrote: I don't know if this is the problem or, not, but: [snip]
As I said, that was simply an error when typing the example, and it is
not present in my code. See below.
Neil Benn wrote: Oh, I'm sorry, that was my mistake. The example contained that error, but my code does not.
[snip] To be fair though - I would have expected the method to throw an error rather than default to cwd.
Neil
Which is why I found this so strange, and also why I provided my code.
The paths are user-inputed, and only referenced as variables, so this
is clearly not a matter of escape sequences.
Daniel Bickett
Daniel Bickett wrote: As it happens, the desired locations are system folders (running windows xp, the folders are as follows: C:\WINDOWS, C:\WINDOWS\SYST EM, C:\WINDOWS\SYST EM32). To see if this factor was causing the problem, I tried it using the interpreter, and found it to be flawless.
I'm not entirely sure what that last sentence means. But does it mean
that shutil.move() works fine if you do it interactively but not in your
code? The simplest interpretation then would be that there is something
wrong in your code.
Why don't you post the debug output of that quoted section of code?
What version of Python are you using? Is it the standard Windows
distribution?
--
Michael Hoffman
Daniel Bickett wrote: In my script, rather than a file being moved to the desired location, it is, rather, moved to the current working directory (in this case, my desktop -- without any exceptions, mind you). As it happens, the
what is the output generated by the lines:
fdir, fname = randFileInfo.ne w()
debugMess( "Generated file information: %s, %s" % ( fdir, fname ) )
Istvan.
Daniel Bickett wrote: Hello,
I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply because that is what google and chm searches returned most often.
My problem has to do with shutil.move actually putting the files where I ask it to. Citing code wouldn't serve any purpose, because I am using the function in the most straight forward manner, ex:
shutil.move( "C:\omg.txt " , "C:\folder\subd ir" )
In my script, rather than a file being moved to the desired location, it is, rather, moved to the current working directory (in this case, my desktop -- without any exceptions, mind you). As it happens, the desired locations are system folders (running windows xp, the folders are as follows: C:\WINDOWS, C:\WINDOWS\SYST EM, C:\WINDOWS\SYST EM32). To see if this factor was causing the problem, I tried it using the interpreter, and found it to be flawless.
My question boils down to this: What factors could possibly cause shutil.move to fail to move a file to the desired location, choosing instead to place it in the cwd (without raising any exceptions)?
Thank you for your time,
Daniel Bickett
P.S. I know I said I didn't need to post code, but I will anyway. You never know :)
http://rafb.net/paste/results/FcwlEw86.html
AS several people have already suggested, you must have an error in the
calling code, which wasn't included in the pasted snippet.
Also, "data" appears to be a global variable, which leaves us lacking
some useful information.
Does the debugMess() call show the full destination path for the file?
regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Daniel Bickett wrote: Hello,
I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply because that is what google and chm searches returned most often.
My problem has to do with shutil.move actually putting the files where I ask it to. Citing code wouldn't serve any purpose, because I am using the function in the most straight forward manner, ex:
shutil.move( "C:\omg.txt " , "C:\folder\subd ir" )
In my script, rather than a file being moved to the desired location, it is, rather, moved to the current working directory (in this case, my desktop -- without any exceptions, mind you). As it happens, the desired locations are system folders (running windows xp, the folders are as follows: C:\WINDOWS, C:\WINDOWS\SYST EM, C:\WINDOWS\SYST EM32). To see if this factor was causing the problem, I tried it using the interpreter, and found it to be flawless.
My question boils down to this: What factors could possibly cause shutil.move to fail to move a file to the desired location, choosing instead to place it in the cwd (without raising any exceptions)?
Thank you for your time,
Daniel Bickett
P.S. I know I said I didn't need to post code, but I will anyway. You never know :)
http://rafb.net/paste/results/FcwlEw86.html
AS several people have already suggested, you must have an error in the
calling code, which wasn't included in the pasted snippet.
Also, "data" appears to be a global variable, which leaves us lacking
some useful information.
Does the debugMess() call show the full destination path for the file?
regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bmgz |
last post by:
I am have made a simple script that moves all desktop clutter (ie files that
are not *.lnk) to a specified folder
eg. c:\myhome\mydocs\desktopdebris\2003-12-16
----------------------------------------------------------------------------
-----------------
import re, os, time, shutil
os.chdir(os.environ+os.environ+"\\Desktop")
DESKTOP =
os.listdir(os.environ+os.environ+"\\Desktop")
|
by: Stéphane Ninin |
last post by:
Hello world,
I am fighting with what is probably a stupid problem.
In a wxpython GUI, here is a method which must read a file,
and if the file is not correctly formed rename it and create a new file:
(I have removed most of the logic of the code here, so I am not sure
it's going to be helpful)
|
by: Todd7 |
last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow
which displays it through adobe acrobat reader 7. Depending on the
buttons the user clicks, the program moves it to another subdirectory
with a new name. I am using python 2.4 with wxpython 2.6 on a windowsxp
machine.
I encounter a permission denied error when trying to move the file. It
appears to be caused due to the loading of the pdf file into the
IEHtmlWindow....
|
by: Russell Warren |
last post by:
I just did a comparison of the copying speed of shutil.copy against the
speed of a direct windows copy using os.system. I copied a file that
was 1083 KB.
I'm very interested to see that the shutil.copy copyfileobj
implementation of hacking through the file and writing a new one is
significantly faster... any clue as to why this is? I figure I'm
missing something here.
Does os.system launch a cmd shell every time?
|
by: Antoine De Groote |
last post by:
Google tells quite some things about it, but none of them are satisfactory.
I'm on Windows, and shutil operations (e.g. move, copy) throw
Permission denied all the time, for the source files. It seems that this
is the case for all my files. But what I don't understand is that
yesterday it still worked. I didn't change anything on my system though
(at least not that I am aware of). I restarted the computer several
times to see if that...
| |
by: David Nicolson |
last post by:
Hi,
I wasn't exactly sure where to send this, I don't know if it is a bug
in Python or not. This is rare, but it has occurred a few times and
seems to be reproducible for those who experience it.
Examine this code:
This is the output:
exceptions.UnicodeDecodeError
|
by: yinglcs |
last post by:
Hi,
Is there a c library which does shutil.copy2() in python? Basically
copy a file from 1 directory to another?
import shutil
import os
shutil.copy2(r"C:\test\test",r"C:\test1\test")
|
by: Roopesh |
last post by:
Hi,
I have a multithreaded application. There are two threads, T1 and T2.
Suppose that there are two folders A, B. Thread T1 fetches data from
network and creates files in folder A and after creating each file, it
moves the file to folder B, using shutil.move().
Thread T2, takes files from folder B and processes it.
Note: Only the thread T1 has access to the files in folder A.
|
by: klia |
last post by:
hello folks
i am trying to tweak the current codes so that later when i call it from the terminal i can provide sourcefile and the destination file rather being fixed in the code. because now i have to specify the sourcefile and the destinationfile in codes and not left to be specified from the terminal. i want to be able to do this.
python shutil_copy.py sourcefile, destinationfile
import shutil
shutil.copyfile(srcfile, dstfile)...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |