Really simple one here: I have the following code to strip out small files in a folder: Code: Dim strPath Dim lngSize Dim fso Dim fold Dim files Dim file lngSize = 12 strPath = "C:\FOLDER" Set fso = CreateObject("scripting.filesystemobject") Set fold = fso.GetFolder(strPath) Set files = fold.files For Each file In files If file.Size <= lngSize Then file.Delete True Next My question is: If I want to add in another check so that it only deletes files under 12 bytes that begin with shirty_is_sexy what do I need to do to my script? Internet handjob cookie may be available for the first answer. I am not a coder so I don't know jack about this sort of stuff.
This might work: Code: For Each file In files If StrComp(Left(file.Name, Len("shirty_is_sexy")),"shirty_is_sexy") = 0) Then If file.Size <= lngSize Then file.Delete True Next
Looks good, but returns an error: Line: 17 Char:78 Error: Expected 'Then' Code: 800A03F9 Source: Microsoft VBScript compilation error Any thoughts?
This should do what you want Code: $path = "C:\folder" $bytes = "12" $namematch = "shirty_is_sexy*" Get-ChildItem $path | ? {$_.PSIsContainer -eq $false -and $_.length -lt $bytes -and $_.name -like $namematch} | % Remove-Item -Confirm:$false -Force You can test it without deleting anything by using WhatIf like so: