I am using the python shutil module to copy files and directories on a linux redhat machine.
I wrote the following method, which takes two parameters: src (the path to the file or dir that is being collected) and destination (the desired new path into which the compiled log / dir file is inserted).
def copy(src, destination): if(os.path.exists(src)): if(os.path.isdir(src)): if(os.path.exists(destination)): shutil.copytree(src, destination+getTimeStamp()) else: shutil.copytree(src, destination) else: shutil.copy(src, destination) else: print src+" not found"
I use this method just fine, but I recently encountered an error while running this code:
copy("/home/midgar/logs/logger.xml", currentPath+"/testrun/logs/logger.xml")
Error: IOError: [Errno 2] There is no such file or directory: 'collectLogs / testrun / logs / logger.xml'
I would understand what this error means if the file or directory it is looking for is src, but this is the destination that causes the error. I found out that this line of code that throws an error refers to the line: "shutil.copy (src, destination)" in my copy method.
So far, my copy method has simply overwritten existing files, and if there is an existing directory, it creates a new one with a timestamp. In this case, the target file does not exist yet. So what could be the problem? Why am I getting this error using the DESTINATION path (when I usually expect to see such an error using the SRC path).
Perhaps this is because it is a .xml file?
python linux xml file shutil
OMGitzMidgar Jul 29 '15 at 6:55 2015-07-29 06:55
source share