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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map Drive, Copy and Rename Files, delete source files

Status
Not open for further replies.

jasonphillipstx

Technical User
Dec 10, 2001
43
US
I need to write a batch or script to do something like the following. I can do it in Access, but I need a .bat or .vbs file that I can just copy over to a vpn client machine. Thanks in advance for your help.


dim i
dim strCustomer, strSourcePath, strDestDrive, strDestPath
strCustomer = Input Customer Name
strSourcePath = "e:\DCIM\100MSDCT"
strDestDrive = "z:\"
strDestPath = strDestDrive & "\" & strCustomer
map network drive with authentication
net use z: \\server\share
makedir Z:\strCustomer
for each i (jpg files frmo camera)
copy i strDestPath & "\" & strCustomer & "-" & DateTime & ".jpg"
next
If yes, Delete strSourcePath & "\*"
message "all done"

Can this all be done easily?
 
Take a look at FileSystemObject and WshNetwork

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok, here is where I am so far. Can someone please look it over and see if this is remotely close.


dim i, FS
dim strCustomer, strSourcePath, strDestDrive, strDestPath, strRepFolder

Set FS = CreateObject("Scripting.FileSystemObject")
strSourcePath = "c:\a\"
strDestDrive = "C:"
strCustomer = "Joe_Blow"
strRepFolder = "David"
strDestPath = strDestDrive & ":\" & strRepFolder & "\" & strCustomer

'add later, map network drive with authentication
'net use z: \\server\share

'check to see if source drive exists
'return error if not
if not fs.driveexists(fs.getdrive(strSourcePath )) then
exit
end if

'check to see if source folder exists
'return error if not
if not fs.folderexists(strsourcepath) then
exit
end if

'check to see if destination drive exists
'return error if not
if not fs.driveexists(strDestDrive) then
exit
end if

'check to see if destination folder exists
'if not then create it
if not fs.folderexists(strdeskpath) then
fs.CreateFolder strDestPath
end if

'copy files
for each i (jpg files from camera)
filecopy i strDestPath & "\" & strCustomer & "-" & DateTime & ".jpg"
next

'notify of completion

'ask to delete source files after successful copy
If yes, Delete strSourcePath & "\*"

'notify message "all done
 
strDestDrive = "C:"
strCustomer = "Joe_Blow"
strRepFolder = "David"
strDestPath = strDestDrive & ":\" & strRepFolder & "\" & strCustomer

i think strDestPath will look like

c::\david\joe_blow

the double :: are not good

Also, i would say it is bad practice to have so many Exits!
In vbscript we tend to use

Wscript.Quit

The trouble with so many exits? i think it makes it hard to follow the logic of the code. it is the sort of thing you see a lot of in batch programming. with the extra constructs in vbscript you should try to avoid them where possible.

You might be better of nesting some of your If statements

I think you dont need your first fs.driveexists(fs.getdrive(strSourcePath) because you do a FolderExists(strSourcePath)

SO you mighe end up with something like


if fs.folderexists(strsourcepath) then
'check to see if destination folder exists
'if not then create it
if not fs.folderexists(strdeskpath) then
fs.CreateFolder strDestPath
end if

'copy files
for each i (jpg files from camera)
filecopy i strDestPath & "\" & strCustomer & "-" & DateTime & ".jpg"
next
end if





 
Ok, I nested the if statements and changed the exits to wscript.quit. I would prefer to keep the ifs in for the drives so I cna later add notifications to tell the user the exact problem of wrong drive, folder, etc.

Here's where I am. I am assuming I can just name this file copyfiles.vbs and run it. Is this correct?

dim i, FS
dim strCustomer, strSourcePath, strDestDrive, strDestPath, strRepFolder

Set FS = CreateObject("Scripting.FileSystemObject")
strSourcePath = "c:\a\"
strDestDrive = "C"
strCustomer = "Joe_Blow"
strRepFolder = "David"
strDestPath = strDestDrive & ":\" & strRepFolder & "\" & strCustomer

'add later, map network drive with authentication
'net use z: \\server\share

‘check to see if source drive exists because it is
‘digital camera that turns off automatically, return error if not
if not fs.driveexists(fs.getdrive(strSourcePath )) then
Wscript.Quit
Else
'check to see if source folder exists
'return error if not
if not fs.folderexists(strsourcepath) then
Wscript.Quit
Else
'check to see if destination drive exists
'return error if not
if not fs.driveexists(strDestDrive) then
Wscript.Quit
Else
'check to see if destination folder exists
'if not then create it
if not fs.folderexists(strdeskpath) then
fs.CreateFolder strDestPath
end if
'copy files
for each i (jpg files from camera)
filecopy i strDestPath & "\" & strCustomer & "-" & DateTime & ".jpg"
next i
'notify of completion
'ask to delete source files after successful copy
‘If yes, Delete strSourcePath & "\*"
'notify message "all done"
end if
end if
end if
 
there is still a lot of pseudo code there.

hmm, the point i am trying to make is that you can use If Then statements, for loops, select cases, sub, functions, booleans so that you DONT need the Wscript.Quits.

The way you have your If Then statements now means that the Wscript.Quit's are required. the statement logic will take care that nothing happens.

your CreateFolder method may cause you an error.
The CreateFOlder method only works for one folder.
so if you have deep folder you wnat to create then i tend to split the strDestFld string using aArray = Split(strDestFolder, "\") and then perform a loop on the aArray
 
so if you have deep folder you wnat to create then i tend to split the strDestFld string using aArray = Split(strDestFolder, "\") and then perform a loop on the aArray

I am a little confused on this part. Can you show sample code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top