Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto copying files but not replicating existing files

Status
Not open for further replies.

soteman

Technical User
Jul 4, 2009
3
Hi everyone,

With a bit of help, I have the following script to use;

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")

'First locate the users desktop
strDsk = WshShell.SpecialFolders("Desktop")

'Now add our base photo location
photobase = "\photos\"

'Ask For a new folder to create
newFolder = InputBox("Enter name of new photo directory to create", "New directory name")
photopath = strDsk & photobase & newFolder
If Not objFSO.FolderExists(photopath) Then
objFSO.CreateFolder(photopath)
End If

'Now we copy from the thumb drive/flash card: replace G: With the appropriate flash drive
Call WshShell.Run("cmd.exe /k robocopy H:\DCIM\100_Fuji " & photopath & "\ /E /ZB /COPY:DAT /XO")

I am using it to automatically copy all photos from my grandfather's camera to a folder on the desktop, as he has little technical knowhow, and wouldn't cope with learning to make new folders, and searching for photos and copy/pasting.

Can anyone suggest a way of only taking new photos off the camera? For the same tech-phobia related reasons, he doesn't really delete photos from the camera itself very often so rather than copying all his old photos too, can the script search all existing folders in desktop/photos and not replicate file names that already exist within the subfolders?

Thanks a lot to anyone who has gotten this far and actually understood my convoluted explanation and still wants to help :)
 
I'm a photographer and feel this is the wrong approach to managing the photos. Normally you get some software with your camera that will download the new photos for you to a folder, if you do not have software then look at something like Picasa, it is a free download: You can set your computer or software to auto download the photos when the memory card is inserted in the card reader.
It is considered best practice to remove photos from the disk once they are downloaded for various reasons, one obvious one being that the disk eventually fills up. It is also best to format the disk in the camera to clear out downloaded photos, this is a simple and quick process.
With a bit of couching it should not be too difficult to nudge even the most tech-phobia person in the right direction.
Just my thoughts...
 
Have you tried using robocopy, with the correct switches it will only copy new files added and any files that you have changed... Here is an example of a script I use in my production environment...


' *** NOTE1::: You MUST have a copy of ROBOCOPY.EXE in the c:\program files\CCMCTools\Apps\ folder for this script to WORK !! ***
' *** NOTE2::: A backup.txt file will be written to and appended to each time the user runs this script. You can find
' ************ this file on the root of c:\ ***
'File backup Script
Dim backupdriveletter,objnetwork,WshNetwork,backupfolder,stime,objshell,objShell1,objFSO
Dim spath,dpath,s0,strpath,StrHost, objFolder, objFolderItem, S1,objExec, strCmd, strTemp,RoboChk

'Declarations :: S0 = the backup switches for Robocopy, Will write a log file on the root of C:\
' called laptopbackup.txt
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell1 = CreateObject("Shell.Application")
s0 = "/MIR /R:5 /W:15 /V /NP /LOG+:C:\LaptopBackup.txt"
s1 = "\\"
spath = objShell.SpecialFolders("MyDocuments") & S1
strUser = objNetwork.UserName
backupdriveletter = "I"
strpath = "I:\My Documents\\"
roboChk = "C:\robocopy.exe"
' ******************************************* Prompt Customer for VPN Connection ******************************
' First user prompt that asks the user if they are connected via VPN, if yes, the script will start the main subroutine
' Called Start Backup, If NO, the script will end.

X=MsgBox(" Good Afternoon todays date is " & Date & " **** Are you currently logged into the network ?? **** ",36,"My Documents BackUp Utility")

If X = 6 Then
X=MsgBox("Please press OK to proceed with your file backup",48,"My Documents BackUp Utility")

RobocopyCheckMain()

Else

X=MsgBox("Please make sure you first login to the network before trying again ",48,"My Documents BackUp Utility")
WScript.Quit
End If

' ********************************************* MAIN PROGRAM *************************************************
' 1.) The Script will first check to see if Robocopy.exe is found in the c:\program files\CCMCTools\Apps folder. If it
' is not found, the script will display a message box and then end.
' 2.) The script will then check to see if the end users I drive is mapped, if not the script will map a drive To
' I:\KASAPP|Users\%UserName%...
' 3.) After the drive mapping is established the script will check to see if a folder called My Documents already
' exists, if NO, one will be created, if YES the script will continue on to the Robocopy portion of the script.
' 4.) Robocopy runs, copying only the files that are new or have been changed since the last time the user ran this
' Script. If this is the first time running the script all files\subdirectories will be copied over to the network
' folder for the customer.
' ************************************************************************************************************


Sub RobocopyCheckMain()

If objFSO.FileExists(RoboChk) Then

StartBackup()

Else
X=MsgBox("I am sorry but you not have RoboCopy.exe in the C:\ root, please copy Robocopy.exe to this folder and try again")
WScript.Quit
End If

End Sub



Sub StartBackup()

If (objFSO.DriveExists(BackupDriveLetter)) Then
Else
' Chenge the server name to your local servers name
objNetwork.MapNetworkDrive "I:" , "\\YourServerName\users\" & strUser

End If



If objFSO.FolderExists(strPath) Then

Else
backupfolder = "\My Documents"
objFSO.CreateFolder(backupdriveletter & ":\" & backupfolder)

End If

Call objShell.Run("cmd.exe /c C:\robocopy.exe """ & spath & """ """ & strpath & """ " & s0)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top