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

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

automated wscript command causes error in vbs program

Hi,

I have a .vbs file that zipps up my archived database files. I would like to automate this procedure so it kicks off once per week.

I found a nifty little tool called delyer(tm) by cottonwood. It allows you to kick off a program and set when you want it to start and if you want to repeat it.

Both work independently but when I combine the two I get a file not found error.

The command line for Delayer is:

C:\DELAYER\DELAYER.EXE "C:\WINDOWS\system32\wscript.exe C:\Zip_files.vbs" /D20

the vb script is as follows:

Dim fso, dir_initial, dir_initial_zip, zip_files, read_file, reply, f, fc, fl

dir_initial     = "D:\oracle\oradata\testp1\archive"
dir_initial_zip = "D:\oracle\oradata\testp1\archive\zipped"

set fso       = CreateObject("Scripting.FileSystemObject")
set zip_files = CreateObject("WScript.shell")

set f  = fso.Getfolder(dir_initial)
set fc = f.files
reply = 0

for each fl in fc
    if reply = 0 then
   
          zip_files.run "cmd /c cd " & dir_initial & " & pkzip -n+ -exx " & dir_initial_zip & "\" & left(fl.name,4) & ".zip " & fl.name,0,true
        wscript.sleep 5000
          zip_files.run "cmd /c cd " & dir_initial_zip & " & pkzip " & left(fl.name,4) & " -n+ -v > list.txt 2>&1",0,true
         wscript.sleep 5000
          Set read_file = fso.OpenTextFile(dir_initial_zip & "\list.txt", 1)
          reply = InStr(1, read_file.ReadAll, fl.name, 1)
            if reply <> 0 then
                fso.deletefile(fl)
                reply = 0
             end if
          read_file.close
     
     end if
next

--------------------------

It falls over on line:

  Set read_file = fso.OpenTextFile(dir_initial_zip & "\list.txt", 1)

saying

error: File not found
code: 800A0035
can anyone explain why I cannot run the two together?



0
joehodge
Asked:
joehodge
  • 6
  • 4
1 Solution
 
GrahamSkanCommented:
The most obvious possibility is that 5 seconds is not long enough to wait for the file creation.
0
 
joehodgeAuthor Commented:
Hi,

If i double click on the .vbs file it works perfectly so I think it has something to do with the wscipt object?
0
 
EDDYKTCommented:
You don't really need to sleep since you specify true (third parameter) on the line, the system will wait to finish


>>zip_files.run "cmd /c cd " & dir_initial & " & pkzip -n+ -exx " & dir_initial_zip & "\" & left(fl.name,4) & ".zip " & fl.name,0,true
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
joehodgeAuthor Commented:
Hi,

I commented out both the sleep commands and it does not solve the initial problem (running them together)
but when I run the file on its own it still works so I did not need them in there.

thanks anyway
0
 
EDDYKTCommented:
by the way, do you see the file exist on that directory?
0
 
joehodgeAuthor Commented:
I've tried to do a bit of debugging but I still get an error.

I put a test.txt file in the
dir_initial     = "D:\oracle\oradata\testp1\archive"

and then put a list.txt in the
dir_initial_zip = "D:\oracle\oradata\testp1\archive\zipped"

and I get

Error: Input past end of file

If I only put list.txt in the
dir_initial_zip = "D:\oracle\oradata\testp1\archive\zipped"
I get success and it will remove list.txt
0
 
EDDYKTCommented:
don't know what is the program C:\DELAYER\DELAYER.EXE  is

If you said it works when click on the vbs itself then something may relate to that program
0
 
joehodgeAuthor Commented:
It is a piece of freeware software that allows you to enter a program and then a file to run at a selected interval.

in this case I call wscript.exe and when that is running it will launch my .vbs program

Its the same as typing C:\WINDOWS\system32\wscript.exe C:\Zip_files.vbs at the command prompt.
0
 
joehodgeAuthor Commented:
Hi,

I think I've found the problem.

when I put everything into the same drive it almost works!

e.g.

dir_initial     = "c:\initial"
dir_initial_zip = "c:\initial\zipped"

and then from a dos prompt

C:\WINDOWS\system32\wscript.exe C:\Zip_files.vbs

it will create a zip file but will not remove the initla .txt file

why and where would I have to specify the drives in order to get this to work?
0
 
EDDYKTCommented:
Ok


>>zip_files.run "cmd /c cd " & dir_initial & " & pkzip -n+ -exx " & dir_initial_zip & "\" & left(fl.name,4) & ".zip " & fl.name,0,true

>>zip_files.run "cmd /c cd " & dir_initial_zip & " & pkzip " & left(fl.name,4) & " -n+ -v > list.txt 2>&1",0,true


fl.name only return the file name, you may want to use fl.path to get file name and path for your second command
0
 
joehodgeAuthor Commented:
Hi,

I asked a colleague and he pointed me to windows scheduler which does exactly what I wanted this delayer program to do!

thanks for all your help though
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.

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