Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


What is wrong with my vbscript?

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> What is wrong with my vbscript?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 What is wrong with my vbscript? - 1/25/2006 3:50:35 AM   
  zbx888

 

Posts: 4
Score: 0
Joined: 1/24/2006
Status: offline
I write following vbscript  (listfile.vbs) to write all of files to one output.txt under a given folder.

listfile.vbs
Option Explicit
Dim folder, fso, outputFile, outputText
Dim folderPath, filepath
filepath = WScript.Arguments.Item(1)
Set fso = CreateObject("Scripting.FileSystemObject")
set outputFile = fso.CreateTextFile(filepath)
set outputFile = fso.GetFile(filepath)
set outputText = outputFile.OpenASTextStream(2,0)
folder = WScript.Arguments.Item(0)
getFolder(folder)
set fso = nothing
Function getFolder(root)
dim folders, folder, file, files
If fso.FolderExists(root) Then
For Each file In fso.GetFolder(root).Files
 outputText.WriteLine file
Next
For Each folder In fso.getFolder(root).SubFolders
 getFolder(fso.GetAbsolutePathName(folder))
Next
Else
WScript.Echo "Folder doesn't exist: " & root
Exit Function
End If
End Function

Check the text file output.txt. If we want to keep some files wejust remove them from the file. then I used deletefile.vbs to read all file names from output.txt to delete them. The script just delete some of them instead of all of them. What is problem with the two script???????

deletefile.vbs
 
Option Explicit
Dim folder, fso, outputText, count
folder = WScript.Arguments.Item(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set outputText = fso.OpenTextFile(folder, 1, false, 0)
count = 0
Do Until outputText.AtEndofStream
   if fso.FileExists(outputText.ReadLine) = true then
Wscript.echo "the file " & outputText.ReadLine & " is deleted"
fso.deletefile trim(outputText.ReadLine), true
count = count + 1
    end if
Loop
Wscript.echo "Total " & count & " files are deleted"
set fso = nothing
 
 
Post #: 1
 
 RE: What is wrong with my vbscript? - 1/25/2006 4:08:54 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Every time taht you do outputText.ReadLine it reads a new line from the text file. so essentially you are trying to delete every third file that is listed. Try this instead:


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to zbx888)
 
 
Post #: 2
 
 RE: What is wrong with my vbscript? - 1/25/2006 5:50:08 AM   
  zbx888

 

Posts: 4
Score: 0
Joined: 1/24/2006
Status: offline
Thanks! Your code works!

(in reply to ebgreen)
 
 
Post #: 3
 
 
 
  

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 >> What is wrong with my vbscript? Page: [1]
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