Page 1 of 1 1
Topic Options
#194387 - 2009-06-24 01:59 PM visual basic help
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
Does anyone know what:

 Code:
Const RECYCLE_BIN = &Ha&


is setting the constant to?

Top
#194388 - 2009-06-24 02:09 PM Re: visual basic help [Re: BradV]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
It's setting it to 10 isn't it?
Top
#194389 - 2009-06-24 02:37 PM Re: visual basic help [Re: BradV]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
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?

Top
#194390 - 2009-06-24 03:18 PM Re: visual basic help [Re: BradV]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4671
Loc: The Netherlands
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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194391 - 2009-06-24 03:28 PM Re: visual basic help [Re: Mart]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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 ;\) )
_________________________



Top
#194392 - 2009-06-24 03:31 PM Re: visual basic help [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
.Type seemed to be promising, but I get Type results in German, so it is a nogo
_________________________



Top
#194395 - 2009-06-24 03:48 PM Re: visual basic help [Re: Jochen]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
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.
Top
#194397 - 2009-06-24 04:09 PM Re: visual basic help [Re: Jochen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4671
Loc: The Netherlands
 Originally Posted By: Jochen

doesn't delete Folders in the recycle bin...
....


D#mn , didn't test with folder just file.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194398 - 2009-06-24 04:11 PM Re: visual basic help [Re: BradV]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4671
Loc: The Netherlands
 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.


Edited by Mart (2009-06-24 04:11 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194401 - 2009-06-24 04:40 PM Re: visual basic help [Re: Mart]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
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

Top
#194402 - 2009-06-24 04:51 PM Re: visual basic help [Re: BradV]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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?
_________________________



Top
#194404 - 2009-06-24 05:13 PM Re: visual basic help [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4534
Loc: USA
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

Top
#194406 - 2009-06-24 05:22 PM Re: visual basic help [Re: BradV]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
OK, put it in the UDF forum. Let me know if I made any typos!

Empty Recycle Bin UDF

Top
#194426 - 2009-06-25 11:04 AM Re: visual basic help [Re: BradV]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4671
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194432 - 2009-06-25 12:45 PM Re: visual basic help [Re: Mart]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 685
Loc: Maryland, USA
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.
Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 400 anonymous users online.
Newest Members
jtpk2022, Rayvenhaus, Insecurity, KGSOFT, fobrien
17791 Registered Users

Generated in 0.076 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org