EvilZone

Programming and Scripting => Scripting Languages => : pyte January 03, 2013, 08:36:48 PM

: Copying all files and folders in a specified drive
: pyte January 03, 2013, 08:36:48 PM
HI,


wrote this code with an intention to copy files from a specified directory / file
 
:
import os
import shutil
sourcePath = r'G:/Air.doc'
destPath = r'C:\Users\Desktop\test'
shutil.copy(sourcePath, destPath)


this only copies a specified file(in my case Air.doc)


Now ild like to know how ild modify the same to copy everything from a specified drive over a network and also be able to attach the files to an email and send automatically at a scheduled time.

: Re: Copying all files and folders in a specified drive
: Kulverstukas January 03, 2013, 09:23:42 PM
Not sure about attaching to emails and whatnot, but to copy all files, do this:
instead of
sourcePath = r'G:/Air.doc'
put
sourcePath = r'G:/*.*'
or better yet, just
sourcePath = "G:\\*.*"
: Re: Copying all files and folders in a specified drive
: pyte January 03, 2013, 10:14:48 PM
great! that  works. thanx  :)

: Re: Copying all files and folders in a specified drive
: iTpHo3NiX January 03, 2013, 11:11:28 PM
If you want to keep a folder structure you can use batch

:
@echo off
xcopy "C:\location\folder" "C:\destination\folder" /e
: Re: Copying all files and folders in a specified drive
: pyte January 03, 2013, 11:22:12 PM

.
If you want to keep a folder structure you can use batch

:
@echo off
xcopy "C:\location\folder" "C:\destination\folder" /e
can i inc operate this to my python code?
i got no experience with batch though it looks quite clea
: Re: Copying all files and folders in a specified drive
: techb January 03, 2013, 11:39:00 PM
.can i inc operate this to my python code?
i got no experience with batch though it looks quite clea

Yes, you can use popen or system in the os module.

As for email, you will need to look up MIME types and how to creation emails in python. There are built-in libs, so go Google.