So i got working profiles that Copy new files in folder to local sever.
Code: Select all
import shutil
import os
# coding: utf8
IgnoreFileTypes = 'txt,nfo'
FileName = ''.join(eg.event.payload)
FileExtension = FileName[-3:]
isFolder = os.path.isdir(FileName)
DestFolder = u'\\\\SERVERD\\path in russian language\\'
shutil.copy(FileName,DestFolder)
print os.path.basename(FileName) + ' copied.'Its working with local files and folders.
But when i change the monitoring path to server folder - it gives me 4 new files every time bacause event DirectoryWatcher4.Updated triggers 4 times. Maybe its due to Windows making temp files or the file is opend on several PCs...
I tried to make "stop presessing event", disable macro and enable it after sriypt... its not working.
When i insert "wait" in macro or time.sleep(5) in script it gives me the loop with new files that i cant stop or gives me 12 files...
I opened python yesturday for the first time, so the help is appreciated. So the profile is (dont look at the disabled items):
Code: Select all
import shutil
import os
import datetime
import time
# coding: utf8
FileName = ''.join(eg.event.payload)
FileExtension = FileName[-4:]
isFolder = os.path.isdir(FileName)
DestFolder = u'D:\\backup folder\\'
shutil.copy(FileName,DestFolder)
print os.path.basename(FileName) + ' copied.'
FileName1 = os.path.basename(FileName)
Name = FileName1[0:-4]
now_time = datetime.datetime.now()
print(now_time.strftime("%Y-%m-%d-%I-%M-%S"))
date = now_time.strftime("%Y-%m-%d-%I-%M-%S")
os.rename(DestFolder+FileName1,DestFolder+Name+' '+date+FileExtension)It gives me often the IOError: [Errno 13] Permission denied or WindowsError: [Error 183] Cant create file but still makes 4 files
By the way can i make copy with rename at the same time?
And again: im very far avay from programming so dont say "try to use .... function" =) i need direct code lines.