|
|
|||||||
Does anyone know what: Code: Const RECYCLE_BIN = &Ha& is setting the constant to? |
||||||||
|
|
|||||||
It's setting it to 10 isn't it? |
||||||||
|
|
|||||||
OK, I was prompted by the empty recycle bin question in the basic forum. I didn't like that he was using a batch file to delete the entire bin and then remake it. So, I did a quick search and found: Code: A simple script to clear the recycle bin === Set fso = CreateObject("Scripting.FileSystemObject") Const RECYCLE_BIN = &Ha& Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(RECYCLE_BIN) Set objFolderItems = objFolder.Items For i = 0 to objFolderItems.Count - 1 fso.DeleteFile objFolderItems.Item(i).Path, 1 Next === I translated that as: Code: Dim $objFSO, $intRB, $objShell, $objFolder, $objFoldItm, $i $objFSO = CreateObject("Scripting.FileSystemObject") $intRB = 10 $objShell = CreateObject("Shell.Application") $objFolder = $objShell.NameSpace($intRB) $objFoldItm = $objFolder.Items For $i = 0 To $objFoldItm.Count-1 $objFSO.DeleteFile $objFoldItm.Item($i).Path,1 Next Everything seems to work up until the delete line. Any thoughts? |
||||||||
|
|
|||||||
Made one small change to the delete line and now it works great. Tested it on WinXPPro SP3 and kix 4.60 and it works as expected. Might be usefull as a UDF. EmtyRecycleBin() or something. Code: Dim $objFSO, $intRB, $objShell, $objFolder, $objFoldItm, $i $objFSO = CreateObject("Scripting.FileSystemObject") $intRB = 10 $objShell = CreateObject("Shell.Application") $objFolder = $objShell.NameSpace($intRB) $objFoldItm = $objFolder.Items For $i = 0 to $objFoldItm.Count - 1 $objFSO.DeleteFile($objFoldItm.Item($i).Path, 1) Next |
||||||||
|
|
|||||||
doesn't delete Folders in the recycle bin... this one does, but doesn't distinguish between files and folders. Allthough it seems a bit brute it doesn't choke ![]() Code: Dim $objFSO, $intRB, $objShell, $objFolder, $objFoldItm, $i $objFSO = CreateObject("Scripting.FileSystemObject") $intRB = 10 $objShell = CreateObject("Shell.Application") $objFolder = $objShell.NameSpace($intRB) $objFoldItm = $objFolder.Items For $i = 0 to $objFoldItm.Count - 1 $objFSO.DeleteFile($objFoldItm.Item($i).Path, 1) $objFSO.DeleteFolder($objFoldItm.Item($i).Path, 1) Next I may come up with a better way later (or may not ![]() |
||||||||
|
|
|||||||
.Type seemed to be promising, but I get Type results in German, so it is a nogo |
||||||||
|
|
|||||||
A UDF was what I was thinking about. I just think deleting the entire recycle bin and then re-creating it eventually is going to get you in trouble. |
||||||||
|
|
|||||||
Originally Posted By: Jochen doesn't delete Folders in the recycle bin... .... D#mn ![]() |
||||||||
|
|
|||||||
Originally Posted By: BradV .... I just think deleting the entire recycle bin and then re-creating it eventually is going to get you in trouble. Agreed. |
||||||||
|
|
|||||||
OK, I think this is pretty close to a final solution: Code: Dim $objFSO, $intRB, $objShell, $objFolder, $objFoldItm, $i $objFSO = CreateObject("Scripting.FileSystemObject") $intRB = 10 $objShell = CreateObject("Shell.Application") $objFolder = $objShell.NameSpace($intRB) $objFoldItm = $objFolder.Items For $i = 0 to $objFoldItm.Count - 1 If $objFSO.FileExists($objFoldItm.Item($i).Path) $objFSO.DeleteFile($objFoldItm.Item($i).Path, 1) Else If $objFSO.FolderExists($objFoldItm.Item($i).Path) $objFSO.DeleteFolder($objFoldItm.Item($i).Path, 1) Endif Endif Next |
||||||||
|
|
|||||||
Very nice! the search for distinguishing files and folders based on item properties was a dead end ![]() Here as a function a bit shorted (I think if it is not a file it must be a folder (at least in the bin) ) Code: function EmptyRecycleBin() dim $objFSO, $objShell, $objFolder, $objFoldItm, $i $objFSO = createobject("Scripting.FileSystemObject") $objShell = createobject("Shell.Application") $objFolder = $objShell.NameSpace(10) $objFoldItm = $objFolder.Items for $i = 0 to $objFoldItm.Count - 1 if $objFSO.FileExists($objFoldItm.Item($i).Path) $objFSO.DeleteFile($objFoldItm.Item($i).Path, 1) else $objFSO.DeleteFolder($objFoldItm.Item($i).Path, 1) endif next endfunction sufficient? |
||||||||
|
|
|||||||
Amazing this has UDF has not existed before now. I do see it has been discussed some 4 years ago with Jens coming up with a different solution. http://www.kixtart.org/forums/ubbthreads...true#Post112135 |
||||||||
|
|
|||||||
OK, put it in the UDF forum. Let me know if I made any typos! Empty Recycle Bin UDF |
||||||||
|
|
|||||||
A bit late but an optional parameter to indicate what to delete would be nice. Something like 1 for just folders and 2 for just file. If none is given then just delete everything (default). I have no direct use for it but can see some in the future. |
||||||||
|
|
|||||||
Yes, I was also thinking someone might only want to delete things older than x (a parameter passed) days, or something else. The basis is there. |