1

I'm using a program that takes a picture every hour along with 3 other metadata files. All of these are stored in a folder. Through Terminal I made the program run ever 10 minutes. However I still want to keep the old structure of 1 picture (4 files) per hour. Thus creating 2 folders, one catch all and one that duplicates the pictures (from the catch all) with the hour timestamp into the old folder.

Right now I have this code, but I'm very lost and need some guidance.

import os
import subprocess 

class cd:
    def __init__(self, newPath):
       self.newPath = newPath

    def __enter__(self):
       self.savedPath = os.getcwd()
       os.chdir(self.newPath)

    def __exit__(self, etype, value, traceback):
       os.chdir(self.savedPath)


    with cd("/User/...."):

       subprocess.call("ls")

Thank you so much for any help,

Erik

Hauk1
  • 85
  • 4
  • If you use the built in [os.path](http://docs.python.org/2/library/os.path.html) module you'll make things a good bit easier. It makes exploring paths and files pretty easy and includes functions to check creation time. – oathead Dec 10 '12 at 03:12
  • Thanks I'll try that now. How would you duplicate the files? – Hauk1 Dec 10 '12 at 17:25
  • Look at [shutil](http://docs.python.org/2/library/shutil.html), you can probably use copyfile if it's just copying single files. If you want to copy the whole directory look at copy or copy2. copy2 preserves a lot of the file metadata. – oathead Dec 12 '12 at 14:16

0 Answers0