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!

output results of "RM" command

Status
Not open for further replies.

weezy6902

IS-IT--Management
Jun 2, 2003
46
0
0
US
Hey guys I have a script i want to use but it doesnt allow me to output the results of the RM command i have in here. Someone, anyone know how to output these results if the folder was not found or successfully deleted?

Thanks much for input!!!

Code:
'nsf search and destroy and folder remove
Dim objOutputFile
Dim strOutputFile

Dim oFSO
Const OPEN_FILE_FOR_APPENDING = 8 
strOutputFile = "logs\delresults.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
Set oTextStream = oFSO.OpenTextFile("passlist.txt")
Set objOutputFile = oFSO.OpenTextFile(strOutputFile, OPEN_FILE_FOR_APPENDING, True)

RemotePC = Split(oTextStream.ReadAll, vbCrLf)
oTextStream.Close
For Each strWorkstation In RemotePC
   objOutputFile.WriteLine "Deleting files and folders on "& strWorkStation
   Call WSHShell.run("cmd.exe /c del \\"& strWorkstation &"\c$\*.nsf /s >> "& strOutputFile)
objOutputFile.Close 
Set objOutputFile = oFSO.OpenTextFile(strOutputFile, OPEN_FILE_FOR_APPENDING, True)
   objOutputFile.WriteLine "Deleting Selected folders on "& strWorkStation
   Call WSHShell.run("cmd.exe /c RD /S /Q ""\\"& strWorkstation &"\c$\New Folder\"" >> "& strOutputFile)
next
objOutputFile.Close
 
I use this to pipe a command to a file:

Code:
Option Explicit

Private Sub Form_Load()
  Shell ("C:\Windows\System32\cmd.exe /c  " & _
     "C:\Windows\System32\ipconfig >> d:\myip.txt"), vbNormalFocus
End Sub

The problem is that delete doesn't report what isn't deleted, and will crash if it can't delete something in the middle. Hope that this helps.

-David
2006 Microsoft Most Valueable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
yeha i use the stdout method but when using the "rm" command it doesnt pipe anything out to the txt file. I think im gonna have to find a small file to do a fake copy to so that it errors out when not seeing the file. sucks...
 
as a thought - can't you check existence of the file (folder) before and after delete - to see if it exists (ans still exists, so had not been deleted)?
 
well if i knew how i would do that... Im very green on the subject of scripting so forgive me.

Would this be a if exists type thing? I would totally do that if known how then write a line to a txt file.

If you have any ideas let me know...

Thanks
 
Look at the help files for the FileSystemObject, in particular the FileExists method.

Code:
If (fso.FileExists(filespec)) Then
   msg = filespec & " exists."
Else
   msg = filespec & " doesn't exist."
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top