Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Searching a folder to see if a file exsists

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,26902
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Searching a folder to see if a file exsists
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Searching a folder to see if a file exsists - 10/27/2005 7:49:12 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
Fisrt off have you tested the other VBScripts you are calling?  Do they work properly if you just run them by themselves?

Second post your primay script along with a directory listing of the directory that contains the target VBScripts.  This way I can see exactly what you have and ensure the path to the target files are correct.  I tested the script aganist each task  and I know it does work.  I even had a target VBScript that executed properly.  So lets take a look and see where the disconnect is.

Cybex

(in reply to mnman66)
 
 
Post #: 21
 
 RE: Searching a folder to see if a file exsists - 10/28/2005 2:48:16 AM   
  mnman66

 

Posts: 49
Score: 0
Joined: 3/16/2005
From:
Status: offline
Okay, Cybex. The other vbs scripts do work on their own. I created a test file called AGUS.txt and put it in the source directory.
Here is the primary script I'm using. It's the last one you recommended:

Set fso = CreateObject("Scripting.FileSystemObject")
srcDir = "C:\RCCTS\data\outgoing"
ftypes = Array("AGTT", "AGBN", "AGUS")

If fso.FolderExists(srcDir) Then
     For Each file In fso.GetFolder(srcDir).Files
         Set ws = WScript.CreateObject("WScript.Shell")
         gfName = UCase(Left(fso.GetBaseName(file),4))
            For Each x In ftypes
                If x = gfname Then
                        sFile = "C:\Temp\" & gfName & "\" & gfName & "vs.vbs"
                        If fso.FileExists(sFile) Then
                            srun = ws.Run(sFile, 0, "True")
                        Else
                            errmsg = MsgBox("There is no corresponding script for " & Chr(34) & gfName & Chr(34) & " In the given directory.", 0, "No Script Found!")
                        End If
                End If
            Next
     Next
End If


Here is the script I'm calling:

'*************************************************************************
'**              Variables that can change to adjust the program        **
'**                   State Variables for this program                  **               
'*************************************************************************
strProgName = "AGUSvs.vbs"
DebugFile = "AGUSFX.txt"  'Error file name
'*************************************************************************
DateToday = Date()
MonthToday = Month(DateToday)
If MonthToday < 10 then
MonthToday = "0" & MonthToday
end if
DayToday = Day(DateToday)
If DayToday < 10 then
DayToday = "0" & DayToday
end if
YearToday = Year(DateToday)

MyDate = YearToday & MonthToday & DayToday

'*************************************************************************
'**                      This section of code retrieves the parent folder path of this                      **
'**                            script then uses this path to save the Debugfile.                                  **
'*************************************************************************
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strProgName)
if Right(f.ParentFolder,1) <> "\" then
  DebugPath = f.ParentFolder & "\"
else
  DebugPath = f.ParentFolder
end if
DebugPath = DebugPath & DebugFile

'*************************************************************************
'**                        Create fso (File System Object) and open the DebugFile                         **
'*************************************************************************
Set OutObj = CreateObject("Scripting.FileSystemObject")
Set DebugStream = OutObj.OpenTextFile(DebugPath,8,1)
  
DebugStream.WriteLine(strNewLine)
DebugStream.WriteLine("****************************************************")
DebugStream.WriteLine("Transmission Server")
DebugStream.WriteLine("Program:  " & strProgName)
DebugStream.WriteLine(Date() & " -- " & Time()) 
DebugStream.WriteLine("****************************************************")

'***************************************************************************
'*                                   Use SFTP to push file to Destination                                                      *
'***************************************************************************
Set ws = WScript.CreateObject("WScript.Shell")
ret = ws.Run("agusftp.bat",0,"True")
If ret = 0 Then
Dim fso
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
fso.MoveFile "C:\RCCTS\data\outgoing\AGUS.txt", "C:\Archive\AGUS" & MyDate & ".txt"
DebugStream.WriteLine("AGUS.txt file has been sent to Destination.")
Set fso=Nothing
Else
DebugStream.WriteLine("Problem with the FTP Transfer!")
DebugStream.WriteLine("Please check all system logs!")
End If
Set fso = Nothing
Set f = Nothing
Set ws = Nothing

The contents of the target directory for the VBS script contains the following:
agusftp.bat - SecureFX batch file
AGUSFX.txt - Debug log
AGUSvs.vbs - Transfer script
TRSFTP.log - FTP log for SecureFX

Now when I ran the primary script, nothing was moved, and the popup box never came up.


(in reply to Cybex)
 
 
Post #: 22
 
 RE: Searching a folder to see if a file exsists - 10/28/2005 3:25:29 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
I can not test your second script but the first part works fine for me.

I only changed the SrcDir location.

Set fso = CreateObject("Scripting.FileSystemObject")
'srcDir = "C:\RCCTS\data\outgoing"
srcdir="C:\scripts"
ftypes = Array("AGTT", "AGBN", "AGUS")
If fso.FolderExists(srcDir) Then
    For Each file In fso.GetFolder(srcDir).Files
    Set ws = WScript.CreateObject("WScript.Shell")
    gfName = UCase(Left(fso.GetBaseName(file),4))
        For Each x In ftypes
            If x = gfName Then
                sFile = "C:\Temp\" & gfName & "\" & gfName & "vs.vbs"
                If fso.FileExists(sFile) Then
                    srun = ws.Run(sFile, 0, "True")
                Else
                    errmsg = MsgBox("There is no corresponding script for " & Chr(34) & gfName & Chr(34) & " In the given directory.", 0, "No Script Found!")
                End If
            End If
        Next
    Next
End If

I even test the error message if the corosponding vbs file was not found.

My "C:\scripts" directory contains 1 file "agbn.txt"
I run the script, it finds the folder, looks through the file names, matches "AGBN" to X, which is ftypes(1), sets sfile to "C:\temp\AGBN\AGBNvs.vbs", and runs sfile.
In "c:\temp\agbn" is "agbnvs.vbs", this file contains one line of code "msgbox("The second script ran!").
I run the first script and the message box from the second script pops up.

What OS and script engine are you running?

Cybex

(in reply to mnman66)
 
 
Post #: 23
 
 RE: Searching a folder to see if a file exsists - 10/28/2005 6:08:56 AM   
  mnman66

 

Posts: 49
Score: 0
Joined: 3/16/2005
From:
Status: offline
Okay, what I did was take the best of both worlds. I combined your script with the transfer script to get it running. Somewhere, I seem to remember that you can't run a VBS script within a VBS script. Is that true? Anyhow, I'll post the script that is currently working. I've made some minor adjustments as I needed the original file to be moved to an archive directory with a date stamp in the file name. Probably not as great a script can look, but it's getting the job done now.
Thanks again for all of the help!

FileSearch.vbs:

'*************************************************************************
'**              Variables that can change to adjust the program        **
'**                   State Variables for this program                  **               
'*************************************************************************
strProgName = "filesearch.vbs"
DebugFile = "filexsist.txt"  'Error file name
'*************************************************************************
DateToday = Date()
MonthToday = Month(DateToday)
If MonthToday < 10 then
MonthToday = "0" & MonthToday
end if
DayToday = Day(DateToday)
If DayToday < 10 then
DayToday = "0" & DayToday
end if
YearToday = Year(DateToday)

MyDate = YearToday & MonthToday & DayToday

'*************************************************************************
'**     This section of code retrieves the parent folder path of this   **
'**         script then uses this path to save the Debugfile.           **
'*************************************************************************
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strProgName)
'troubleshooting code
'Msgbox "name: " & f.Name
'Msgbox "parent name: " & f.ParentFolder
if Right(f.ParentFolder,1) <> "\" then
  DebugPath = f.ParentFolder & "\"
else
  DebugPath = f.ParentFolder
end if
DebugPath = DebugPath & DebugFile

'*************************************************************************
'**       Create fso (File System Object) and open the DebugFile        **
'*************************************************************************
Set OutObj = CreateObject("Scripting.FileSystemObject")
Set DebugStream = OutObj.OpenTextFile(DebugPath,8,1)
  
DebugStream.WriteLine(strNewLine)
DebugStream.WriteLine("****************************************************")
DebugStream.WriteLine("File Exsist program for File Transfer")
DebugStream.WriteLine("Program:  " & strProgName)
DebugStream.WriteLine(Date() & " -- " & Time()) 
DebugStream.WriteLine("****************************************************")
Set fso = CreateObject("Scripting.FileSystemObject")
srcDir = "C:\RCCTS\data\outgoing"
ftypes = Array("AGTT", "AGBN", "AGUS", "AGWF", "BLRJ", "CCRJ", "COLL", "EFTT", "NEAG", "NECL", "RJCT", "SOAG", "TRCC", "TREA", "UPAY")

If fso.FolderExists(srcDir) Then
     DebugStream.WriteLine("Searching folder for files...")
     For Each file In fso.GetFolder(srcDir).Files
         Set ws = WScript.CreateObject("WScript.Shell")
         gfName = UCase(Left(fso.GetBaseName(file),4))
         vsName = UCase(Left(fso.GetBaseName(file),4))
            For Each x In ftypes
                If x = gfname Then
                        sFile = "C:\Temp\" & gfName & "\" & gfName & "sftp.bat"
                        vFile = "C:RCCTS\data\outgoing\" & vsName & ".txt"
                            If fso.FileExists(sFile) Then
                               DebugStream.WriteLine("File Found! Running transfer script!")
                               srun = ws.Run(sFile, 0, "True")
              End If
                                  If fso.FileExists(vFile) Then
                                    DebugStream.WriteLine("File will be sent to Destination.")
                                  End If
                        If srun = 0 Then
                            fso.MoveFile "C:\RCCTS\data\outgoing\" & vsName & ".txt", "C:\TSArchive\temp\" & vsName & MyDate & ".txt"
                            DebugStream.WriteLine("File has been sent to VeriSign.")
                             
                        Else
                            DebugStream.WriteLine("Problem with the FTP Transfer!")
                            DebugStream.WriteLine("Please check all system logs!")
                        End If
                End If
            Next
     Next
End If

Thanks again for your help. Go ahead and modify accordingly, to make it look better or flow better! You ALL rock!

(in reply to Cybex)
 
 
Post #: 24
 
 RE: Searching a folder to see if a file exsists - 10/28/2005 6:45:12 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
For the current date time stamp for file names I have used this in the past.

    Set objMName = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2")
    Set MNameInfo = objMName.ExecQuery("SELECT * FROM Win32_OperatingSystem")
    For Each objInfo In MNameInfo
        CurDT = Left(objInfo.LocalDateTime, 8) & "_" & Mid(objInfo.LocalDateTime,9,6)
    Next

wscript.echo CurDT & ".txt"

Cybex

(in reply to mnman66)
 
 
Post #: 25
 
 RE: Searching a folder to see if a file exsists - 10/28/2005 6:50:21 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
As to your other question, I was able to run another VBScript from a VBScript.  As far as I know you can run mutiple instances of the scripting engine at the same time. I even tested to make sure the other script was still running by adding another msgbox after the other script had finished running and it worked fine.

Cybex

(in reply to Cybex)
 
 
Post #: 26
 
 RE: Searching a folder to see if a file exsists - 10/31/2005 4:21:35 AM   
  mnman66

 

Posts: 49
Score: 0
Joined: 3/16/2005
From:
Status: offline
Thanks Cybex! I'll see if I can work that into the script. I'll work on the other portions as well. Don't know why my other VBS script isn't running when called. Would it have to do with the WSH on the server itself?

(in reply to Cybex)
 
 
Post #: 27
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Searching a folder to see if a file exsists Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts