The following is a subroutine in a VB script. It works properly
unless the file name already exists in the target directory. If the
target file exists an error occurs and the process stops. This is an
automatic process, and it doesn't matter if the file is written over
so I would like to simply write over the target file even if it
already exists. Is there a parameter to use for that
in the f1.Move command?
'SUBROUTINE to run process and move source file
Sub ProcessAndRenameFiles(folderspec)
Dim fs, f, f1, fc, s, vchange
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if Instr(f1.name,"DEPT.DAT") then
Return = WSHSHELL.Run (vDJ & folderspec & "\" & f1.name, 0,
TRUE)
f1.Move (vFolder & "\arc\" & f1.name)
End if
Next
End Sub
'ENTIRE SCRIPT:
' This script runs the department conversion program
' After conversion the files are moved to the arc directory
' It runs each day at 11:00 AM
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim WSHShell, WshSysEnv, FTPFolder, SwitchFolder, ErrorFolder,
AdminEmail, EmailServer
Dim vPropath, vConvpath, vSwitchProgram, vSwitchid, vMysroot, vDLC,
vfiletocheck, vCostType, vDJ
Set WSHShell = WScript.CreateObject("WScript.Shell")
vDJ = "C:\program_name here"
Dim vext, vnewfile, vcomplete, vfilelist, vFolder
vFolder = "c:\CALLDATA\PSDOWNLOADS"
' Execute Subroutines
ProcessAndRenameFiles(vFolder)
Sub ProcessAndRenameFiles(folderspec)
Dim fs, f, f1, fc, s, vchange
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if Instr(f1.name,"DEPT.DAT") then
Return = WSHSHELL.Run (vDJ & folderspec & "\" & f1.name, 0,
TRUE)
f1.Move (vFolder & "\arc\" & f1.name)
End if
Next
End Sub |
Request for Question Clarification by
webadept-ga
on
08 Jun 2003 08:20 PDT
Hi,
Move doesn't have a switch, but CopyFile does. So you could use
CopyFile, and then DeleteFile to get the effect you are looking for.
However, the code you have there is to the Move function, which is not
a VBasic function. The VBasic function for this is MoveFile, and it is
passing the wrong amount of variables. You need to find the Move sub
function and alter that in your code.
webadept-ga
|
Clarification of Question by
blue_bna-ga
on
14 Jun 2003 14:52 PDT
Sorry to be slow on the clarification. I'll be testing this next week
and will post results then. Thanks for the suggestion.
|
Clarification of Question by
blue_bna-ga
on
01 Jul 2003 15:32 PDT
I need a little more help on this. I can see how it would work using
the "copy" function but I just do not have the VB scripting experience
to place that command in the proper place. Could you send me an
example code to accomplish what I need?
THanks
|
Clarification of Question by
blue_bna-ga
on
03 Jul 2003 18:48 PDT
I don't want to let this expire without paying for the information I
got, but I had hoped to get the syntax example before I closed the
question.
Thanks
|
Request for Question Clarification by
webadept-ga
on
04 Jul 2003 23:06 PDT
Hi, I would be happy to help you further and even give you some code,
but as I mentioned before, I need to see this sub Move function. If
you could post that code here, I will take a look and see if I can
alter it so that it will work as you require.
Thanks,
webadept-ga
|
Clarification of Question by
blue_bna-ga
on
07 Jul 2003 07:09 PDT
Here is the subroutine - it was at the bottom of the code:
Sub ProcessAndRenameFiles(folderspec)
Dim fs, f, f1, fc, s, vchange
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if Instr(f1.name,"DEPT.DAT") then
Return = WSHSHELL.Run (vDJ & folderspec & "\" & f1.name, 0,
TRUE)
f1.Move (vFolder & "\arc\" & f1.name) <<--this is the move command
End if
Next
End Sub
|
Request for Question Clarification by
webadept-ga
on
08 Jul 2003 03:28 PDT
Okay
Move (vFolder & "\arc\" & f1.name) <<--this is the move command
That is not a VB command, it is a custom function.. Just like the
ProccessAndRenameFiles function. Somewhere there is a line that says
Sub Move
I need to see that sub routine.
|
Clarification of Question by
blue_bna-ga
on
08 Jul 2003 07:03 PDT
This is the entire script. To run it, save it to a file
"testmove.vbs", right click and choose run. To test it, create a
directory "C:\junk" and "C:\junk\arc" and place one more files with
"xxx" in their name. The script will run, but as you pointed out
earlier, it will error out if a file already exists, so I need the
commands for "copy" rather than "move". Since this question expires
in a couple of hours, I'll close it out and make payment before then.
Add hotmail.com to my google login name to send a message if you want
to contact me.
' This script runs the PeopleSoft to department conversion
' After conversion the files are move to the arc directory
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim WSHShell, WshSysEnv, FTPFolder, SwitchFolder, ErrorFolder,
AdminEmail, EmailServer
Dim vPropath, vConvpath, vSwitchProgram, vSwitchid, vMysroot, vDLC,
vfiletocheck, vCostType, vDJ
Set WSHShell = WScript.CreateObject("WScript.Shell")
Dim vext, vnewfile, vcomplete, vfilelist, vFolder
vFolder = "c:\junk"
' Execute Subroutines
ProcessAndRenameFiles(vFolder)
Sub ProcessAndRenameFiles(folderspec)
Dim fs, f, f1, fc, s, vchange
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if Instr(f1.name,"xxx") then
f1.Move (vFolder & "\arc\" & f1.name)
End if
Next
End Sub
|