Page 1 of 1
Copy files after download

Posted:
Sat Jul 24, 2004 7:39 am
by kuyawsadabaw
I think cam2pc should have an option to duplicate files that were just downloaded (including directory structure) to another location for backup purposes. That's something I'd really like to have.
I think it would be pretty simple to implement, right?
---------------------------------------
Try out
PixVillage for sharing pictures
http://www.PixVillage.com

Posted:
Mon Aug 02, 2004 8:28 am
by kuyawsadabaw
I just realized that I can do this through batch files or windows scripting files.
nabocorp,
instead of implementing this in cam2pc itself, can you just add an option to run a file (.bat, .exe, .wsf) after transferring of photos is finished? I think this option will fit well with those checkboxed items in the "And then..." section of the main UI of the Image Downloader.

Posted:
Mon Aug 02, 2004 8:30 am
by nabocorp
Hello,
what arguments do you pass to your script? The images? The folders?
Thanks,
nabocorp

Posted:
Mon Aug 02, 2004 8:35 am
by kuyawsadabaw
i don't think arguments would be necessary to pass, but it's up to you.
In my case, I already know where the directory where the files are downloaded..so if the image downloader could just have the option to run a file (let's say) "C:\backup.wsf", that would be great.
I don't mean this to run for each photo as it downloads, but after all the photos have been downloaded...just to be clear.
If you think other users might find arguments useful, I think passing the path of the new download directory would be sufficient.
Just to give you an idea of what "C:\backup.wsf" does
it recursively looks through "C:\DigitalCameras" and looks through its sub folders.... for each file in those directories.. it looks in "D:\Backup" if a copy exists...if yes, then it compares the size. if the copy is larger in filesize, then it's not overwritten, else it is overwritten... if it doesn't exist..it's copied.

Posted:
Mon Aug 02, 2004 10:37 am
by NACarter
I think this is a great idea. I too manually copy the files after downloading the images. I reckon passing the path name of the newly-created directory to the script would be sufficient.
kuyawsadabaw, would it be possible for you to publish your code? I guess it would be simple enough to do, but why re-invent the wheel? I think I would prefer to not overwrite images, but create a new directory with a different name, e.g. foldername(2). Or else I would test on last modification date rather than file size. Anyway, that's up to you!
Nick

Posted:
Mon Aug 02, 2004 6:40 pm
by kuyawsadabaw
I really hope this option would get into the next release, from a programming point of view, I don't think it's hard to implement.
Here's the code for task.wsf
- Code: Select all
<job id="Job1">
<script language="VBScript">
Sub Recurse(dir)
Dim fso, curdir, file, subdir, jerdenfile, newfile, path, newpath, regex
Set fso = CreateObject("Scripting.FileSystemObject")
Set curdir = fso.GetFolder(dir)
For Each subdir in curdir.SubFolders
newpath = Replace(subdir.Path, "C:\DigitalCameras", "C:\Backup")
If Not fso.FolderExists(newpath) Then
fso.CreateFolder newpath
End If
Recurse(subdir)
Next
For Each file in curdir.Files
Set regex = New RegExp
regex.Pattern = "jpg|jpeg"
regex.IgnoreCase = True
If regex.Test(file) Then
jerdenfile = Replace(dir & "\" & file.name, "C:\DigitalCameras", "C:\Backup")
If fso.FileExists(jerdenfile) Then
Set newfile = fso.GetFile(jerdenfile)
If (newfile.size < file.size) Then
'WScript.Echo "Smaller...Copy" & vbCrLf & dir & "\" & file.name & vbCrLf & jerdenfile
fso.CopyFile dir & "\" & file.name, jerdenfile
Else
'WScript.Echo "Equal or Bigger...Don't Copy" & vbCrLf & dir & "\" & file.name & vbCrLf & jerdenfile
End If
Else
'WScript.Echo "Does Not Exist..." & vbCrLf & dir & "\" & file.name & vbCrLf & jerdenfile
path = Replace(jerdenfile, file.name, "")
If Not fso.FolderExists(path) Then
'WScript.Echo path
fso.CreateFolder path
End If
fso.CopyFile dir & "\" & file.name, jerdenfile
End If
Else
'WScript.Echo "File is not JPEG" & vbCrLf & dir & "\" & file.name & vbCrLf & jerdenfile
End If
Next
End Sub
Recurse("C:\DigitalCameras")
</script>
</job>
this is in VBScript. MSDN has the documentation. In your case you want
- Code: Select all
newfile.DateLastModified & file.DateLastModified
for comparison. Other Properties & Methods can be found here:
http://msdn.microsoft.com/library/defau ... dified.asp

Posted:
Mon Aug 02, 2004 8:02 pm
by NACarter
Thanks, that's great. As a programmer/engineer myself that's no problem (already familiar with coding VB, VBscript, javascript, Fortran, C, Python etc.). I hope this facility appears in a forthcoming version of Cam2PC. I think it's already one of the best camera download programs, and this would make it even better!
Thanks again.
Nick

Posted:
Wed Aug 04, 2004 10:56 am
by kuyawsadabaw
nabocorp, any chance for this to happen?

Posted:
Wed Aug 04, 2004 1:37 pm
by nabocorp
Hello,
yes this will come in next release. You will have the choice to run a program and pass it as arguments:
- all the filenames of the transfered files
- OR all the paths were files were transfered to
Regards,
nabocorp

Posted:
Thu Aug 05, 2004 3:06 am
by kuyawsadabaw
that's great news! Thanks again. :)
You will have the choice to run a program.
This won't be limited to just programs, right? Are Batch files and Scripting files allowed? :wink:
(Perhaps a silly silly question)

Posted:
Thu Aug 05, 2004 3:01 pm
by nabocorp
Let's say anything that is runable...
New Code

Posted:
Tue Sep 14, 2004 2:59 pm
by NACarter
Here's my code for copying images (and sound files), based heavily on kuyawsadabaw's code:
- Code: Select all
<job id="Job1">
<?job debug="true"?>
<script language="VBScript">
Sub Recurse(dir)
Dim fso, curdir, file, subdir, existingfile, newfile, newfile2, path, newpath, regex,src,dest
src="f:\photos" ' this line MUST be in lower case!
dest="f:\EditedPhotos"
Set fso = CreateObject("Scripting.FileSystemObject")
Set curdir = fso.GetFolder(dir)
newpath = Replace(curdir.Path, src, dest)
If Not fso.FolderExists(newpath) Then
fso.CreateFolder newpath
End If
For Each subdir in curdir.SubFolders
newpath = Replace(subdir.Path, src, dest)
If Not fso.FolderExists(newpath) Then
fso.CreateFolder newpath
End If
Recurse(subdir)
Next
For Each file in curdir.Files
Set regex = New RegExp
regex.Pattern = "jpg|jpeg|wav"
regex.IgnoreCase = True
If regex.Test(file) Then
existingfile = Replace(dir & "\" & file.name, src, dest)
If fso.FileExists(existingfile) Then
Set newfile = fso.GetFile(existingfile)
If (newfile.DateLastModified <> file.DateLastModified) Then
number=2
newfile2 = Replace(file.name, ".", "("+CStr(number)+").")
newfile2 = Replace(dir & "\" & newfile2, src, dest)
while fso.FileExists(newfile2)
number=number+1
newfile2 = Replace(file.name, ".", "("+CStr(number)+").")
newfile2 = Replace(dir & "\" & newfile2, src, dest)
wend
fso.CopyFile dir & "\" & file.name, newfile2
Else
'WScript.Echo "Same date...Don't Copy" & vbCrLf & dir & "\" & file.name & vbCrLf & existingfile
End If
Else
path = Replace(existingfile, file.name, "")
If Not fso.FolderExists(path) Then
fso.CreateFolder path
End If
fso.CopyFile dir & "\" & file.name, existingfile
End If
Else
WScript.Echo "File type is not recognised" & vbCrLf & dir & "\" & file.name
End If
Next
End Sub
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
'WScript.Echo "Copying folder '" + objArgs(I) + "'"
Recurse(objArgs(I))
Next
WScript.Echo "Finished copying image folders"
</script>
</job>
Save to a file such as CopyImages.wsf. Note that Cam2PC passes the root destination folder in lowercase - so my src variable needs to be in lower case as that is what is passed to the subroutine in dir (otherwise the replace does not work).
In the Run Program dialog box, use CopyImages.wsf as the program name and %D as the arguments.
Nick
Not Quite...

Posted:
Tue Sep 14, 2004 9:35 pm
by NACarter
Mmmm. I see that Cam2PC does not always pass the root directory as lower case. On my Win 2000 machine at work it did, but on my XP Home machine at home it conserved the case.
Needs some thought here... :?
Nick