Author Topic: Copying all files and folders in a specified drive  (Read 4376 times)

0 Members and 4 Guests are viewing this topic.

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Copying all files and folders in a specified drive
« on: January 03, 2013, 08:36:48 pm »
HI,


wrote this code with an intention to copy files from a specified directory / file
 
Code: [Select]
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.

If you don't go into the tiger's cave, how will you get the cub?

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Copying all files and folders in a specified drive
« Reply #1 on: 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:\\*.*"

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Re: Copying all files and folders in a specified drive
« Reply #2 on: January 03, 2013, 10:14:48 pm »
great! that  works. thanx  :)

If you don't go into the tiger's cave, how will you get the cub?

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: Copying all files and folders in a specified drive
« Reply #3 on: January 03, 2013, 11:11:28 pm »
If you want to keep a folder structure you can use batch

Code: [Select]
@echo off
xcopy "C:\location\folder" "C:\destination\folder" /e
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Re: Copying all files and folders in a specified drive
« Reply #4 on: January 03, 2013, 11:22:12 pm »

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

Code: [Select]
@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
If you don't go into the tiger's cave, how will you get the cub?

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: Copying all files and folders in a specified drive
« Reply #5 on: 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.
>>>import this
-----------------------------