Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have several scripts that do some

Status
Not open for further replies.

Ox73

IS-IT--Management
Nov 5, 2004
16
0
0
I have several scripts that do somewhat that but not quite I have the read all but I think I need some kind of IF statement that says look for these words...
1. logged on user profile because file will be in the user profile C:\Users\USERNAME\AppData\Local\LOGFOLDERHASMANYFILES
2. In this folder there will be multiple files I'm only after the latest file this is the one that will have the error
3. Search for the error "error keyword here"
4. Have a message found folder with problem do you want to delete it? folder... patch shown e.g.
5. After the key word a path of a folder (file really but I need that folder path to delete that folder)
System.IO.FileNotFoundException: error keyword here 'C:\Users\USERNAME\AppData\Local\SOMEAPPLICATIONFOLDER\SOMESUBFOLDER\3\IGNORESOMEXMLFILE.xml'.

So really the folder that needs to be deleted is called "3"

SO IN OTHERWORDS ONE FILE WILL HAVE THE MESSAGE THAT SHOWS THE FOLDER PATH AND THE OTHER IS DELETE THE ACTUAL FOLDER WITH PROBLEM.

 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Bear with me if I'm not making any sence I'm really new at this. I have never really had to do something so involved. This was my first attempt ... I really want a checker to find the latest file in that folder based on date it has to be latest date so the latest date could be today or yesterday but it will be the latest date this file will have the path of the folder I want to delete. I don't have that in this script...what I have thus far is show me the line in which you find the desired text which it does, however I added the show the date created and the user logged on and these two are not showing up in my message not sure why...ultimatly I want to read a file, based on the contents it will have a path then I want to go to that path and delete the folder. I guess I'm having difficulty putting it all together in my head lead alone in the script. I wanted to start small with known values but I really need to migrate to reading the file, the file contains an error of where some file is missing so in that case since the file is missing I want to delete the folder in which that file is stored but all of this is happening on the user folder (windows 7 user folder) logged on so the path would end up being something like...System.IO.FileNotFoundException: error keyword here 'C:\Users\USERNAME\AppData\Local\SOMEAPPLICATIONFOLDER\SOMESUBFOLDER\3\IGNORESOMEXMLFILE.xml'.
****************************BEGINING OF ONE SCRIPT**************************
Option Explicit
'// SETTINGS
Const ForReading = 1
Const strFile = "c:\Temp\Error.txt"
'// DECLARATIONS
Dim objFSO, objFile, strFileProperties
Dim sText, sFound, myuser
Dim arr, x
On Error Resume Next

'// CREATE OBJECT
Set objFSO = CreateObject("Scripting.FileSystemObject")
' // OPEN FILE
Set objFile = objFSO.OpenTextFile(strFile,ForReading)
' //GET USER
Set WshNetwork = wscript.createObject("wscript.network")
' // GET FILE TEXT
sText = objFile.ReadAll
' // CLOSE FILE
Set objFile = Nothing
' // CLOSE OBJECT
Set objFSO = Nothing
' // CLOSE STRING
Set strFileProperties = Nothing

' //IF TEXT EXISTS IN FILE
If Len(sText) Then

'// SPLIT TEXT BY LINES
arr = Split(sText,vbCrLf)
' // LOOP THROUGH EACH LINE
For x = 0 To UBound(arr)

' // REMOVE SPACES AT ENDS
sText = Trim(arr(x))

' //IF LINE HAS TEXT
If Len(sText) Then
' // IF LINE MATCHES SEARCH
If Instr(1,sText,"Error keyword here",vbTextCompare) Then
' // SHOW THE LINE
sFound = sFound & "Found Test on Line: " & x+1 & vbCrLf
' // SHOW THE USER LOGGED ON
myuser = WshNetwork.UserName & "User is: " & myuser
' // SHOW THE DATE CREATED ON FILE
strFileProperties = strFileProperties & "Date created: " & objFile.DateCreated & VbCrLf
MsgBox strFileProperties

End If
End If

Next

' // RESULTS FOUND
If Len(sFound) Then
MsgBox sFound
Else
' //NO RESULTS
MsgBox "No Search Results"
End If

Else

If Err = 0 Then
' // NO TEXT
MsgBox "No Text To Read"
Else
MsgBox "Error!" & vbCrLf & Err.Description
End If

End If
****************************END OF ONE SCRIPT**************************
***This is the script to delete a folder but not sure how I would even incorporate that in here

*******************************DELETE FOLDER********************************
Dim FSO, Folder
set FSO=CreateObject("Scripting.FileSystemObject")
Folder="\TestDelete"
wscript.echo
wscript.echo "Delete a Folder"
FSO.DeleteFolder(Folder)
wscript.echo Folder,"now deleted"
wscript.echo
*******************ISSUE WITH THIS IS THAT i DON'T KNOW THE FOLDER NAME YET SO i PROBABLY NEED SOME KIND OF VARIABLE TO PASS DOWN SOMEWHERE ONCE i READ THE FILE i PASS DOWN THE PATH*************************
 
Thanks Geates... I removed the error resume and stumbled my way through it...I ended up with 3 sub functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top