
Hello:
At the end of this posting are two VBS script files. The first is designed to move a file from one folder (the "OnDeck" folder) and place the file into another folder (the "Input" folder), as a renamed file.
The renamed file in the "Input" folder is, then, to be used as the source file for an application called Scribe that imports data from that source file into Microsoft Dynamics GP 2013 R2.
The second script, CopyFile.vbs, seems to work fine. It simply archives the source file in the "OnDeck" folder and places it into the "Archive" folder within "Input" as a Scribe "post job" step.
I believe that the issue lies with the first script--MoveAndRenameFile.vbs.
Here's the "issue" that I speak of. Prior to the running of the MoveAndRenameFile.vbs file, there is already a source file within the "Input" folder, from the previous time that the Scribe job ran. But, the problem is that this MoveAndRenameFile.vbs causes the source file in "Input" to disappear.
The source file is called "AP_Trans.txt".
The thrust of the MoveAndRenameFile.vbs file is to, again, simply move the file from the "OnDeck" folder and place it into the "Input" folder as a renamed source file for Scribe to process and import data from.
I have attached a screenshot from a Word document of the Scribe window that controls the "pre job" task and parameter and the "post job" task parameter. The issue, like I said, is with the "pre job" section
I have, also, attached a screenshot of Step 3 showing the "OnDeck" directory.
I know it seems odd to have the "OnDeck" directory in Step 3 and not Step 2, since Step 3 represents where Scribe pulls the source file from and the source file "Input" folder is shown in Step 2. But, a consultant tells me that Scribe runs Step 3, prior to Step 2--as odd as that sounds.
Any thoughts?
Thanks!
Much appreciated!
John
MoveAndRenameFile.vbs:
'****************************************************************************************
' MoveAndRenameFile.VBS
' This script takes three parameters that indicate where the
' Parameters:
' SourceFilePath (the original file, with the full path)
' TargetFolder (moves the file here)
' TargetFile (renames the file to this name)
'****************************************************************************************
Option Explicit
const APPLICATION_NAME = "MoveAndRenameFile"
Dim exitcode : exitcode = 0
Call Main()
WScript.Quit exitcode
Function Main()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FSO, logFile
Dim sSourceFilePath, sSourceFile, sTargetFolder, sTargetFile, sTargetFilePath
Set FSO = CreateObject("Scripting.FileSystemObject")
Set logFile = FSO.OpenTextFile( "C:\Files.log", ForAppending, True )
logFile.Write vbCrLf
logFile.Write FormatDateTime( Now, 0 ) + vbCrLf
' Ensure that a valid target file has been specified
On Error Resume Next
sTargetFile = WScript.Arguments(2)
If (Err.Number <> 0) Then
' Call MsgBox("The following parameters must be specified:" & vbCrLf & _
' " SourceFilePath (the original file, with the full path)" & vbCrLf & _
' " TargetFolder (moves the file here)" & vbCrLf & _
' " TargetFile (renames the file to this name)", _
' vbOKOnly, APPLICATION_NAME)
exitcode = 901
Exit Function
End If
On Error GoTo 0
sSourceFilePath = WScript.Arguments(0)
sTargetFolder = WScript.Arguments(1)
logFile.Write "Source File: " + sSourceFilePath + vbCrLf
logFile.Write "Target Folder: " + sTargetFolder + vbCrLf
logFile.Write "Target File: " + sTargetFile + vbCrLf
' Validate the source file
If Not (FSO.FileExists(sSourceFilePath)) Then
' Call MsgBox(sSourceFilePath & " is not a valid source folder/file.", _
' vbOKOnly, APPLICATION_NAME)
exitcode = 901
Exit Function
End If
' Validate the target folder
If Not (FSO.FolderExists(sTargetFolder)) Then
' Call MsgBox(sTargetFolder & " is not a valid target folder.", _
' vbOKOnly, APPLICATION_NAME)
exitcode = 901
Exit Function
End If
sSourceFile = FSO.GetFileName(sSourceFilePath)
sTargetFilePath = sTargetFolder & "\" & sTargetFile
' Call MsgBox(sSourceFile & vbCrLf & sTargetFilePath, vbOKOnly, APPLICATION_NAME)
' Delete the target file if it's already there
If (FSO.FileExists(sTargetFilePath)) Then
FSO.DeleteFile(sTargetFilePath)
End If
' Move and rename the file
On Error Resume Next
FSO.MoveFile sSourceFilePath, sTargetFilePath
If (Err.Number <> 0) Then
exitcode = 901
End If
On Error GoTo 0
logFile.Close
End Function
CopyFile.vbs:
'****************************************************************************************
' MoveAndRenameFile.VBS
' This script takes three parameters that indicate where the
' Parameters:
' SourceFilePath (the original file, with the full path)
' TargetFolder (moves the file here)
' TargetFile (renames the file to this name)
'****************************************************************************************
Option Explicit
const APPLICATION_NAME = "MoveAndRenameFile"
Dim exitcode : exitcode = 0
Call Main()
WScript.Quit exitcode
Function Main()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FSO, logFile
Dim sSourceFilePath, sSourceFile, sTargetFolder, sTargetFile, sTargetFilePath
Set FSO = CreateObject("Scripting.FileSystemObject")
Set logFile = FSO.OpenTextFile( "C:\Files.log", ForAppending, True )
logFile.Write vbCrLf
logFile.Write FormatDateTime( Now, 0 ) + vbCrLf
' Ensure that a valid target file has been specified
On Error Resume Next
sTargetFile = WScript.Arguments(2)
If (Err.Number <> 0) Then
' Call MsgBox("The following parameters must be specified:" & vbCrLf & _
' " SourceFilePath (the original file, with the full path)" & vbCrLf & _
' " TargetFolder (moves the file here)" & vbCrLf & _
' " TargetFile (renames the file to this name)", _
' vbOKOnly, APPLICATION_NAME)
exitcode = 901
Exit Function
End If
On Error GoTo 0
sSourceFilePath = WScript.Arguments(0)
sTargetFolder = WScript.Arguments(1)
logFile.Write "Source File: " + sSourceFilePath + vbCrLf
logFile.Write "Target Folder: " + sTargetFolder + vbCrLf
logFile.Write "Target File: " + sTargetFile + vbCrLf
' Validate the source file
If Not (FSO.FileExists(sSourceFilePath)) Then
' Call MsgBox(sSourceFilePath & " is not a valid source folder/file.", _
' vbOKOnly, APPLICATION_NAME)
exitcode = 901
Exit Function
End If
' Validate the target folder
If Not (FSO.FolderExists(sTargetFolder)) Then
' Call MsgBox(sTargetFolder & " is not a valid target folder.", _
' vbOKOnly, APPLICATION_NAME)
exitcode = 901
Exit Function
End If
sTargetFile = FSO.GetFileName(sTargetFile)
sTargetFilePath = sTargetFolder & "\" & sTargetFile
' Call MsgBox(sTargetFile & vbCrLf & sTargetFilePath, vbOKOnly, APPLICATION_NAME)
' Delete the target file if it's already there
If (FSO.FileExists(sTargetFilePath)) Then
FSO.DeleteFile(sTargetFilePath)
End If
' Move and rename the file
On Error Resume Next
FSO.CopyFile sSourceFilePath, sTargetFilePath
If (Err.Number <> 0) Then
exitcode = 901
End If
On Error GoTo 0
logFile.Close
End Function
*This post is locked for comments
I have the same question (0)