convert vb .net to vbscript?
I'd like to convert the below VB code to VBscript.
Path = "C:\test1"
folderNameMask = "RTX64_####"
delDate = DateAdd("d", 30, Now())
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Path)
Set colSubFolders = objFolder.SubFolders
For Each objSubFolder In colSubFolders
If objSubFolder.Datecreated < delDate And UCase(objSubFolder.Name) Like folderNameMask Then
objSubFolder.Delete
End If
Next
February 13th, 2015 8:57am
this is what I have for vbscript but it needs code to delete the folders 30 days old as well.
im re : Set re = New RegExp
re.Pattern = "RTX64_[0-9]{4}$"
re.IgnoreCase = True
With CreateObject("Scripting.FileSystemObject")
With .GetFolder("C:\test1")
For Each Folder In .SubFolders
If re.Test(Folder.Name) Then Call Folder.Delete(True)
Next
End With
End With
February 13th, 2015 8:59am
Why do you need to convert to VBScript? Just use PowerShell.
February 13th, 2015 10:15am
It works great! except if I have a file or folder in those folders it won't delete them. is there a way I can get it to delete the sub folders as well?
February 13th, 2015 10:58am
If you're referring to the Powershell solution, try adding the -Force
parameter to Remove-Item :)
February 13th, 2015 11:00am
get-childitem C:\test1 -recurse | where-object { ($_.LastWriteTime -lt
(get-date).AddDays(-30)) -and ($_.Name -match 'RTX64_[0-9]{4}$') } |
remove-item -Force
I tried -Force and it still not touching the folder but the other folders without anything in them are gone.
February 13th, 2015 11:04am
A snap, got the wrong parameter actually, sorry. Adding -Recurse to Remove-Item ought to do the job.
February 13th, 2015 11:16am
thanks that worked!
February 13th, 2015 11:32am
I just was told that the RTX64_XXXX folder where XXXX is just build numbers it could be just X or up to 5 XXXXX not just 4 numbers. How can I get it to delete just those folders after RTX64_XXXXXX currently I have it working for just 4 numbers. I hope
this isn't too confusing.
February 13th, 2015 1:38pm
Just adjust the regular expression.
February 13th, 2015 1:48pm
I'd like to convert the below VB code to VBscript.
Path = "C:\test1"
folderNameMask = "RTX64_####"
delDate = DateAdd("d", 30, Now())
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Path)
Set colSubFolders = objFolder.SubFolders
For Each objSubFolder In colSubFolders
If objSubFolder.Datecreated < delDate And UCase(objSubFolder.Name) Like folderNameMask Then
objSubFolder.Delete
End If
Next
Don't be silly. This is VBScript code.
February 13th, 2015 2:03pm