Login | |
|
 |
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
|
|
| |
|
|
|
|
|