![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Workaround for using wildcard "*" with FileExists method Hello all. I want to delete all files in a folder that have a .txt extension. This does NOT work: Set objFSO = CreateObject("Scripting.FileSystemObject") IF objFSO.FileExists("D:\Test\*.txt") Then objFSO.DeleteFile("D:\Test\*.txt") End IF Set objFSO = nothing This workaround does work: Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("WScript.Shell") sCMD = "%COMSPEC% /c DIR /B D:\Test\*.txt" Set objWshScriptExec = objShell.Exec(sCMD) Set objStdOut = objWshScriptExec.StdOut Do Until objStdOut.AtEndOfStream sLine = objStdOut.ReadLine IF Instr(sLine,".txt") Then sFilepath = "D:\Test\" & sLine objFSO.DeleteFile(sFilepath) End IF Loop Set objFSO = nothing Set objShell = nothing Set objWshScriptExec = nothing Set objStdOut = nothing My question is if there's any way to streamline and shorten my workaround script. Any help would be greatly appreciated. Thanks! - Dave |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Workaround for using wildcard "*" with FileExists method On Aug 15, 1:51*pm, Highlander <tron9...@xxxxxx> wrote: Quote: > Hello all. > > I want to delete all files in a folder that have a .txt extension. > > This does NOT work: > > Set objFSO = CreateObject("Scripting.FileSystemObject") > IF objFSO.FileExists("D:\Test\*.txt") Then > * objFSO.DeleteFile("D:\Test\*.txt") > End IF > Set objFSO = nothing > > This workaround does work: > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objShell = CreateObject("WScript.Shell") > sCMD = "%COMSPEC% /c DIR /B D:\Test\*.txt" > Set objWshScriptExec = objShell.Exec(sCMD) > Set objStdOut = objWshScriptExec.StdOut > Do Until objStdOut.AtEndOfStream > * sLine = objStdOut.ReadLine > * IF Instr(sLine,".txt") Then > * * sFilepath = "D:\Test\" & sLine > * * objFSO.DeleteFile(sFilepath) > * End IF > Loop > Set objFSO = nothing > Set objShell = nothing > Set objWshScriptExec = nothing > Set objStdOut = nothing > > My question is if there's any way to streamline and shorten my > workaround script. > > Any help would be greatly appreciated. Thanks! > > - Dave Set objShell = CreateObject("WScript.Shell") sCMD = "%COMSPEC% /c del D:\Test\*.txt" objShell.Run sCMD, 0, True Set objShell = nothing or even ... sCMD = "%COMSPEC% /c del D:\Test\*.txt" CreateObject("WScript.Shell").Run sCMD, 0, True Tom Lavedas =========== |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Workaround for using wildcard "*" with FileExists method Dim FSO, oFol, oFils, oFil Set FSO = CreateObject("Scripting.FileSystemObject") Set oFol = FSO.GetFolder("D:\Test") Set oFils = oFol.Files For Each oFil in oFils If UCase(right(oFil.Name, 4)) = ".TXT" Then oFil.Delete Next Set oFils = Nothing Set oFol = Nothing Set FSO = Nothing Quote: > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objShell = CreateObject("WScript.Shell") > sCMD = "%COMSPEC% /c DIR /B D:\Test\*.txt" > Set objWshScriptExec = objShell.Exec(sCMD) > Set objStdOut = objWshScriptExec.StdOut > Do Until objStdOut.AtEndOfStream > sLine = objStdOut.ReadLine > IF Instr(sLine,".txt") Then > sFilepath = "D:\Test\" & sLine > objFSO.DeleteFile(sFilepath) > End IF > Loop > Set objFSO = nothing > Set objShell = nothing > Set objWshScriptExec = nothing > Set objStdOut = nothing > > My question is if there's any way to streamline and shorten my > workaround script. > > Any help would be greatly appreciated. Thanks! > > - Dave |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Seeking a safe workaround for "An unknown program wants access to your computer" | System Security | |||
| Windows Contacts "last name" bug, and a stange workaround | Vista mail | |||
| Action Pack "upgrade" install workaround.... | Vista General | |||
| Help wanted: Vistas "Windows Mail" and older SSL encryption method | Vista mail | |||
| My downloaded Vista with OEM emulation workaround, passed WGA and is considered "legit" !! | Vista General | |||