Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i found a VB script that uses FileSystemObject to delete every folder on a drive except ones i specify, my problem is that the FileSystemObject cannot see or enumerate folder with trailing / leading - period / space, but DIR command can,

I trying to run a command to delete all folders on a drive (it's from winPE during OS Deployment so it's ok) EXCEPT for the one i specify, this is part of what i work with which works fine but doesn't pick special named folders... is there a way i can use DIR command to feed the "Select Case"?

For each oFolder in oFSO.GetFolder(oEnvironment.Item("DestinationLogicalDrive") & "\").Subfolders

Select Case lcase(oFolder.Name)

Case "minint", "recycler", "system volume information", "deploy", "drivers", "_smstasksequence", "smstslog", "sysprep", "userstate"
oLogging.CreateEntry "Skipping " & oFolder.Path, LogTypeInfo
Case Else
oLogging.CreateEntry "Deleting " & oFolder.Path, LogTypeInfo

sCmd = "cmd /c rd ""\\?\" & oFolder.Path & """ /S /Q"

iRc = RunAndLog(sCmd, false)
TestAndLog iRc,"Execution: " & sCmd
If iRC <> 0 Then
If oFSO.FolderExists(oFolder.Path) Then

oLogging.CreateEntry "Failed to delete " & oFolder.Path & " will try to rename", LogTypeError
sCmd = "cmd /c rename """ & oFolder.Path & """ """ & oFolder.Name & ".bad"""
iRc = RunAndLog(sCmd, false)
TestAndLog iRc,"Execution: " & sCmd

If iRC <> 0 Then
If oFSO.FolderExists(oFolder.Path) Then
oLogging.CreateEntry "Failed to delete or rename " & oFolder.Path & " the image WILL fail with NTLDR", LogTypeError
' TODO: notify, sit and wait
End If
End If
End If
End If

End Select
share|improve this question

1 Answer 1

okay, instead of using the filesystemobject i decided to use simple DIR command in FOR loop,

@echo off

for /f "tokens=*" %%i in ('dir /s /a:D /b \\?\C:\*.*^|"%~dp0"\findstr /I /V /G:"%~dp0\exclusion.txt"') do Call :Delete "%%i"

:Delete

echo found %1

rd /s /q %1

here's what happens:

DIR list all directories on \?\C:\ recursively and outputs a bare list pipe the output to findstr which exclude names found on that text file and then calls the delete command, the file exclusion.txt contains the items i want to exclude thanks to you and "TheOutcaste" from this thread: forums.techguy.org/.../833910-solved-help-r-loop.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.