[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

Improve speed

The attached script needs a bit of improvement to work faster. I'm fairly new to VB. I had to use this WScript.sleep because the script was jumping to the next command before finishing the previous one. Feel free to do all necessary changes.

Any help ?
Thanks
Cheers

SAP2AUPRIFILE01.vbs
0
Bianchi928
Asked:
Bianchi928
  • 5
  • 4
1 Solution
 
RobSampsonCommented:
Hi, assuming the FSO isn't waiting for the file operations to complete, I have substituted those for the good old DOS commands, and therefore removed your WScript.Sleep statements.

Rob.
On Error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell  = CreateObject("WScript.Shell") 

InputPath   = "\\tyrenet-14\sapunix\costarextracts\"
OutputPath  = "\\auprifile01\costar\integration\uploads\"
ArchivePath = "\\tyrenet-14\sapunix\costarextracts\archive\"
Logfilename = "\\tyrenet-14\sapunix\costarextracts\temp\logfile.txt"

Const intForAppending = 8

Set objOutput = objFSO.OpenTextFile(LogFileName, intForAppending, True)

If objFSO.FolderExists(InputPath)  = False Then
   ObjOutput.WriteLine Date() & " " & Time() & " " & InputPath & " Not Found"
   objOutput.Close
   Wscript.Quit 
End If

If objFSO.FolderExists(ArchivePath)  = False Then
   ObjOutput.WriteLine Date() & " " & Time() & " " & Archivepath & " Not Found"
   objOutput.Close
   Wscript.Quit 
End If

If objFSO.FolderExists(Outputpath) = False Then
   ObjOutput.WriteLine Date() & " " & Time() & " " & OutputPath & " Not Found"
   objOutput.Close
   Wscript.Quit 
Else
   'objfso.DeleteFile("\\auprifile01\costar\integration\uploads\*.*") 
End If

Set ObjFolder = objFSO.GetFolder(InputPath)

If objFolder.Files.Count = 0 then
   ObjOutput.WriteLine Date() & " " & Time() & " " & "No files found in " & InputPath & " for Australia"
   objOutput.Close
   Wscript.Quit 
Else
   For Each strFile In ObjFolder.Files 
       If InStr(strfile, "AU") > 0 Then
          strfile.Copy outputpath
          Afile = mid(strFile , 37, 36) & ".txt"
          Bfile = mid(strFile , 37, 30) & ".txt"
          Cfile = mid(strFile , 37, 30) & ".OK"
          objShell.Run "cmd /c copy /y """ & OutputPath & Afile & """ """ & Archivepath & Afile & """", 0, True
          objShell.Run "cmd /c move /y """ & OutputPath & Afile & """ """ & OutputPath & Bfile & """", 0, True
          objShell.Run "cmd /c del /y """ & Inputpath & Afile & """", 0, True
          Set objFile = objFSO.CreateTextFile(outputpath & Cfile, True)
          objFile.Close
       End if
   Next 
End If

ObjOutput.WriteLine Date() & " " & Time() & " OZ Job completed successfully"
objOutput.Close

Open in new window

0
 
Bianchi928Author Commented:
Thanks Rob. I will test tonight and let you iknow how it went.
Cheers
0
 
Bianchi928Author Commented:
Hi Rob,

None of cmd worked...I don't know why..Now, in my original script am I using the right command
to
objFSO.CopyFile OutputPath & Afile , Archivepath & Afile      to copy
objFSO.MoveFile OutputPath & Afile , OutputPath & Bfile        to rename

Thanks
Cheers
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
RobSampsonCommented:
OK, try this version. It will output the commands it tries to run to the log file.  After running it, check the log file, and make sure the dos commands are correctly formatted.

If they are correctly formatted, you can copy and paste them directly to a DOS prompt to see what happens, minus the cmd /c bit on the front (not required because you're already in a DOS prompt).

Regards,

Rob.
On Error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell  = CreateObject("WScript.Shell") 

InputPath   = "\\tyrenet-14\sapunix\costarextracts\"
OutputPath  = "\\auprifile01\costar\integration\uploads\"
ArchivePath = "\\tyrenet-14\sapunix\costarextracts\archive\"
Logfilename = "\\tyrenet-14\sapunix\costarextracts\temp\logfile.txt"

Const intForAppending = 8

Set objOutput = objFSO.OpenTextFile(LogFileName, intForAppending, True)

If objFSO.FolderExists(InputPath)  = False Then
   ObjOutput.WriteLine Date() & " " & Time() & " " & InputPath & " Not Found"
   objOutput.Close
   Wscript.Quit 
End If

If objFSO.FolderExists(ArchivePath)  = False Then
   ObjOutput.WriteLine Date() & " " & Time() & " " & Archivepath & " Not Found"
   objOutput.Close
   Wscript.Quit 
End If

If objFSO.FolderExists(Outputpath) = False Then
   ObjOutput.WriteLine Date() & " " & Time() & " " & OutputPath & " Not Found"
   objOutput.Close
   Wscript.Quit 
Else
   'objfso.DeleteFile("\\auprifile01\costar\integration\uploads\*.*") 
End If

Set ObjFolder = objFSO.GetFolder(InputPath)

If objFolder.Files.Count = 0 then
   ObjOutput.WriteLine Date() & " " & Time() & " " & "No files found in " & InputPath & " for Australia"
   objOutput.Close
   Wscript.Quit 
Else
   For Each strFile In ObjFolder.Files 
       If InStr(strfile, "AU") > 0 Then
          strfile.Copy outputpath
          Afile = mid(strFile , 37, 36) & ".txt"
          Bfile = mid(strFile , 37, 30) & ".txt"
          Cfile = mid(strFile , 37, 30) & ".OK"
          strCommand = "cmd /c copy /y """ & OutputPath & Afile & """ """ & Archivepath & Afile & """"
          objOutput.WriteLine "Running " & strCommand
          objShell.Run strCommand, 0, True
          strCommand = "cmd /c move /y """ & OutputPath & Afile & """ """ & OutputPath & Bfile & """"
          objOutput.WriteLine "Running " & strCommand
          objShell.Run strCommand, 0, True
          strCommand = "cmd /c del /y """ & Inputpath & Afile & """"
          objOutput.WriteLine "Running " & strCommand
          objShell.Run strCommand, 0, True
          Set objFile = objFSO.CreateTextFile(outputpath & Cfile, True)
          objFile.Close
       End if
   Next 
End If

ObjOutput.WriteLine Date() & " " & Time() & " OZ Job completed successfully"
objOutput.Close

Open in new window

0
 
Bianchi928Author Commented:
All good now.
Cheers
0
 
RobSampsonCommented:
OK, cool.  Did you change the commands a bit?
0
 
Bianchi928Author Commented:
For some stupid reason I missed part of the new dos command you gave me. So it's all good now as I tested the dos command and the results were perfect.,
Thanks again
0
 
RobSampsonCommented:
Awesome!  I don't know why, sometimes the FileSystemObject file operations don't seem to wait for the system to complete before running the next line of code.  In times like those, I shell out to DOS....the net start and net stop commands in place of objService.Start and objService.Stop commands of WMI is another example.

Rob.
0
 
Bianchi928Author Commented:
That's right. I have other scripts that does almost exactly the same thing and do wait for  before running the next line.

I will remember that

At least it's working now.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now