Sub Recycle(LV As HWND)
	'send to "Trash Bin"
	Dim As String FromPath,F,NewF
	Dim As Integer C,L,D
	Dim As FileStats FStats
	'
	If FileExists(MyRecycle+Path_Delim+"Data.ini") = 0 Then
		MkDir MyRecycle
		RecycleStatus
	EndIf
	'
	'C = SendMessage(LV,LVM_GETSELECTEDCOUNT,0,0)
	If LV = FTop(TopLVType) Then
		FromPath = wtTop
	Else
		FromPath = wtBottom
	EndIf
	'loop thru selections
	C = FreeFile
	Open MyRecycle+Path_Delim+"Data.ini" For Append As #C
	L = ListView_GetNextItem(LV, -1, LVNI_SELECTED)
	While L > -1
		FStats = SelFileInfo(LV,L)
		F = FStats.FName
		D = 0
		If (FStats.Att And 16) = 16 Then
			'send whole dir to trash
			Do
				D += 1
				NewF = "Trash"+Right(Str(1000+D),3)'+".dir"
			Loop While Dir(MyRecycle+Path_Delim+NewF,16) <> ""
			D = DoDirComm(FromPath,MyRecycle+Path_Delim,F,"moved")
			Name MyRecycle+Path_Delim+F,MyRecycle+Path_Delim+NewF
		Else
			'a file
			Do
				D += 1
				NewF = "Trash"+Right(Str(1000+D),3)+".fil"
			Loop While FileExists(MyRecycle+Path_Delim+NewF)
			FileCopy(FromPath+F,MyRecycle+Path_Delim+NewF)
			D = My_Kill(FromPath,F,FALSE,FALSE)
		EndIf
		Print #C, F
		Print #C, FromPath
		Print #C, NewF
		L = ListView_GetNextItem(LV, L, LVNI_SELECTED)
	Wend
	Close #C
	If LV = FTop(TopLVType) Then
		GetFileListTop
	Else
		GetFileListBottom
	EndIf
	RecycleStatus
End Sub

Sub EmptyRecycle
	'delete all files and remove "trash" dir
	Dim As String F
	'
	F = Dir(MyRecycle+Path_Delim+"*.*")
	While F <> ""
		If Len(F) > 2 Then My_Kill(MyRecycle+Path_Delim,F,FALSE,FALSE)
		F = Dir()
	Wend
	RmDir MyRecycle
End Sub

Function RestoreRecycle(LV As HWND,Rest As BOOL,All As BOOL) As Integer
	Dim As String V,PassTo,PassFile
	Dim As Integer TCount,fornext,fh,mk
	Dim As BOOL Removed
	Dim As String CD = CurDir
	Dim As HTREEITEM Sel
	ReDim As String OLoc(0),OName(0),NName(0)
	'
	If All Then
		SelAll LV
	EndIf
	'
	fh = FreeFile
	fornext = 0
	Open MyRecycle+Path_Delim+"Data.ini" For Input As #fh
	Do
		ReDim Preserve OLoc(fornext),OName(fornext),NName(fornext)
		Line Input #fh, OName(fornext)
		Line Input #fh, OLoc(fornext)
		Line Input #fh, NName(fornext)
		fornext += 1
	Loop Until Eof(fh)
	Close #fh
	'find selected
	fornext = ListView_GetNextItem(LV, -1, LVNI_SELECTED)
	While fornext > -1
		Removed = TRUE
		fh = 0 'folder?
		If Right(NName(fornext),4) = ".fil" Then fh = 1
		If Rest Then
			'restore this file/folder
			Name MyRecycle+Path_Delim+NName(fornext),MyRecycle+Path_Delim+OName(fornext)
			If fh Then
				'See if dir exists
				V = Dir(OLoc(fornext)+"*",16) 'get a "." or ""
				If Len(V) = 0 Then
					V = OLoc(fornext)
					'go to root of drive wanted
					ChDir(Left(V,2))
					While Len(CurDir) > 3
						ChDir("..")
					Wend
					V = Mid(V,4) 'take off drive spec
					V = Left(V,Len(V)-1) 'take off trailing delim
					'V is now "a/b/c/d/e..."
					V = MyMakeDir(V)
					'V now holds the folder name of first folder to be created
				EndIf
				mk = DoFCopy(MyRecycle+Path_Delim,OLoc(fornext),OName(fornext))
				Name MyRecycle+Path_Delim+OName(fornext),MyRecycle+Path_Delim+NName(fornext)
				If mk Then
					'did not restore
					Removed = FALSE
					If Len(V)>1 Then
						'created folders needs to be deleted
						TCount = InStr(OLoc(fornext),Path_Delim+V+Path_Delim)
						DoDirComm(Left(OLoc(fornext),TCount),"",V,"deleted")
						ChDir(CD)
					EndIf
				Else
					'restored, was a new folder created?
					If Len(V)>1 Then
						'add to tree
						TCount = InStr(OLoc(fornext),Path_Delim+V+Path_Delim)
						PassTo = Left(OLoc(fornext),TCount)
						'even though when disabled/"connected" can still update treeview???
						Sel = FolderExistInTree(DBottom,PassTo)
						If Sel Then PutTree(V,Sel,1)
						Sel = FolderExistInTree(DTop,PassTo)
						If Sel Then PutTree(V,Sel,0)
						ChDir(CD)
					EndIf
				EndIf
			Else
				'is folder
				'DoDirComm handles everything
				mk = DoDirComm(MyRecycle+Path_Delim,OLoc(fornext),OName(fornext),"moved")
				If mk Then Removed = FALSE 'did not restore
			EndIf
		EndIf
		'remove from disk
		If Removed Then
			If fh Then
				My_Kill(MyRecycle+Path_Delim,NName(fornext),FALSE,FALSE)
			Else
				'"Remove selected" clicked
				If Rest = FALSE Then DoDirComm(MyRecycle+Path_Delim,"",NName(fornext),"deleted")
			EndIf
		EndIf
		'
		fornext = ListView_GetNextItem(LV, fornext, LVNI_SELECTED)
	Wend
	'count how many files left
	mk = 0
	fh = FreeFile
	Open MyRecycle+Path_Delim+"Data.ini" For Output As #fh
	For fornext = 0 To UBound(OName)
		'check to see if file still exists in "trash"
		V = Dir(MyRecycle+Path_Delim+NName(fornext),48)
		If V <> "" Then
			Print #fh, OName(fornext)
			Print #fh, OLoc(fornext)
			Print #fh, NName(fornext)
			mk += 1
		EndIf
	Next
	Close #fh
	'Trash dlg will delete file if blank
	Return mk
End Function

Sub DispRecycle(LV As HWND)
	Dim As Integer fh
	Dim As String F,AddThis
	Dim As Double Calc, BFactor
	Dim As String BSuffix = "B KBMBGB"
	'
	SendMessage(LV,LVM_DELETEALLITEMS,0,0)
	fh = FreeFile
	Open MyRecycle+Path_Delim+"Data.ini" For Input As #fh
	While Eof(fh) = 0
		Line Input #fh, AddThis 'Original Name
		Calc = InStrRev(AddThis,".")
		If Calc Then
			'has extention
			AddThis += "|"+UCase(Mid(AddThis,Calc+1)) + "|"
		Else
			AddThis += "|File Folder|"
		EndIf
		Line Input #fh, F 'From path
		AddThis += Left(F,Len(F)-1) + "|"
		Line Input #fh, F 'New name -- use this to get file stats
		If Calc Then
			Calc = FileDateTime(MyRecycle+Path_Delim+F)
			AddThis += Format(Calc, "mm/dd/yyyy hh:mm:ss AM/PM")+"|"
			Calc = FileLen(MyRecycle+Path_Delim+F)
			BFactor = 0
			While Calc > 1024
				Calc /= 1024
				BFactor += 1
			Wend
			If BFactor = 0 Then ' < 1K
				AddThis += Format(Calc,"#,##0")
			Else
				AddThis += Format(Calc,"#,##0.00")
			EndIf
			AddThis += " " + Mid(BSuffix,BFactor*2+1,2)
		Else
			Addthis += "|"
		EndIf
		LVAddItem LV, AddThis
	Wend
	Close #fh
End Sub

Sub RecycleStatus
	Dim As HTREEITEM hti
	Dim As String V,TrashL = "Trash"
	Dim As Integer TCount
	'
	If FileExists(MyRecycle+Path_Delim+"Data.ini") Then
		V = Dir(MyRecycle+Path_Delim+"*",55)
		While V <> ""
			TCount += 1
			V = Dir()
		Wend
		TCount -= 3 'Data.ini and . and ..
	EndIf
	TrashL = "Trash ("+Str(TCount)+")"
	hti = TreeView_GetRoot(DTop) 'first drive in tree
	Do
		V = TreeView_GetItemText(DTop, hti)
		If Left(V,5) = "Trash" Then Exit Do
		hti = TreeView_GetNextSibling(DTop, hti)
	Loop
	TV_NameIt DTop, hti, TrashL
	hti = TreeView_GetRoot(DBottom) 'first drive in tree
	Do
		V = TreeView_GetItemText(DBottom, hti)
		If Left(V,5) = "Trash" Then Exit Do
		hti = TreeView_GetNextSibling(DBottom, hti)
	Loop
	TV_NameIt DBottom, hti, TrashL
End Sub
