"Delete" files by moving it to the Trash Can/Recycler from the command line?

P

per9000

Hi all,

I work a lot in windows from the command line. I'd like to be able to,
instead of only deleting a file (f.x. "del *.tmp") be able to move it
to the trashcan.

I could just move to C:\MyTrashCan, but I'd like it to be able to
browse, and preferably replace files later with the standard trash can
view.

Thanks,
Per
 
W

Wesley Vogel

Move
Moves one or more files from one directory to the specified directory.

Type in a command prompt: Move /?

More Move HELP.
Paste the following line into Start | Run and click OK...

hh ntcmds.chm::/move.htm

Each hard disk or partition contains a hidden folder named Recycler. The
Recycler folder is used only on NTFS partitions. On FAT32 the RECYCLED
folder is used. The Recycler folder contains a Recycle Bin for each user
that logs on to the computer, sorted by their security identifier (SID).

My hard drive is formatted NTFS.

This is MY SID #
S-1-5-21-1708537768-15xx36667-1202660629-1003

This is MY Recycle Bin
C:\RECYCLER\S-1-5-21-1708537768-15xx36667-1202660629-1003

Your Recycle Bin would be similar, but you need to know your SID #.

This registry key lists all of the SIDs.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

To tell which user has which SID, click on each SID, look at
ProfileImagePath, the Data has the user name at the end of the path. I.e.
%SystemDrive%\Documents and Settings\Wesley P. Vogel

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
P

per9000

Hi Wesley,

yes, indeed this seems to move files to the trashcan-folder. From the
command line I can now see the file (I emptied the trashcan so it was
empty before I put hello_world.log in there)

....
Directory of C:\RECYCLER\S-1-5-21-*NUMBERS*05

2006-02-13 14:13 2 180 hello_world.log
1 File(s) 2 180 bytes
....

But when I look in the trashcan using the standard GUI I cannot see the
file in there. The trashcan looks as if is empty.

Also, I'd like to be able to restore the files put in the trashcan
(even if I put them there from the command line). Typically a file has
an original location, a date it was removed etc.

Just to illustrate: I created a file "testing_2.txt" and put it in
trash from the regular gui.

Now if I look in the folder from DOS it looks like this:

Directory of C:\RECYCLER\S-1-5-21-*NUMBERS*05

2006-11-22 09:08 0 Dc12466.txt
2006-02-13 14:13 2 180 hello_world.log

Or using Cygwin "ls -lh"
total 9.0K
-rwx------+ 1 per None 0 Nov 22 09:08 Dc12466.txt
-rwx------+ 1 per None 820 Nov 22 09:08 INFO2
-rwx------+ 1 per None 65 Nov 1 11:42 desktop.ini
-rwx------+ 1 per None 2.2K Feb 13 2006 hello_world.log

The file INFO2 seems to contain the info I need to integrate
type INFO2
♣ u☺ ▒0 ♥ æö♀☺C:\Documents and
Settings\per\Desktop\testing_2.txt

♫╟☺ C : \ D o c u m e n t s a n d S e t t i n g s \ p e r
\ D e s k t o p \ t e s t i n g _ 2 . t x t

My ultimate goal would be a bat-file (f.x. foobar.bat) in my bin-folder
looking something like this:
move /Y %* C:\RECYCLER\S-1-5-21-*NUMBERS*05
That integrates with the regular trashcan. Being able to restore later
is my goal.

Is there perhaps some other exe-file that is run when a user presses
the "delete" button in a regular folder view? and/or generates the info
in INFO2?

Thanks,
Per
 
W

Wesley Vogel

Hi Per,

When you delete a file, the complete path and file name is stored in a
hidden file called Info2 in the Recycler folder.

for example, Dc12466.txt

D means Deleted.
c means the dile was deleted from the C: drive.
12466 means it was the 12466th deleted file.
txt means it was a text file, probably testing_2.txt

I wonder why the high number, 12466? INFO2 messed up?

If I paste this into the Run command (Start | Run ) and click OK
C:\RECYCLER\S-1-5-21-1708537768-1580436667-1202660629-1003\info2
the Open With applet comes up.
Select Notepad and click OK or just double click on Notepad from the list.
INFO2 opens.

Or you can do this in a command prompt...

start C:\RECYCLER\S-1-5-21-1708537768-1580436667-1202660629-1003\info2

the Open With applet comes up.
Select Notepad and click OK or just double click on Notepad from the list.
INFO2 opens.

This what's in my INFO2...
C:\Documents and Settings\Wesley P. Vogel\Desktop\278startmenupin.reg

C : \ D o c u m e n t s a n d S e t t i n g s \ W e s l e y P . V o
g e l \ D e s k t o p \ 2 7 8 s t a r t m e n u p i n . r e g

C:\Documents and Settings\Wesley P. Vogel\Desktop\startmenupin.reg

C : \ D o c u m e n t s a n d S e t t i n g s \ W e s l e y P . V o
g e l \ D e s k t o p \ s t a r t m e n u p i n . r e g

C:\Documents and Settings\Wesley P. Vogel\Desktop\pinlistenable.reg

C : \ D o c u m e n t s a n d S e t t i n g s \ W e s l e y P . V o
g e l \ D e s k t o p \ p i n l i s t e n a b l e . r e g

C:\Documents and Settings\Wesley P. Vogel\Desktop\New Text Document.txt

C : \ D o c u m e n t s a n d S e t t i n g s \ W e s l e y P . V o
g e l \ D e s k t o p \ N e w T e x t D o c u m e n t . t x t
------------

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>cd C:\RECYCLER\S-1-5-21-1708537768-1580436667-1202660629-1003

C:\RECYCLER\S-1-5-21-1708537768-1580436667-1202660629-1003>dir
Volume in drive C is Local Disk
Volume Serial Number is 901E-9F82

Directory of C:\RECYCLER\S-1-5-21-1708537768-1580436667-1202660629-1003

22-Nov-06 10:46 AM 1,454 Dc1.reg
22-Nov-06 10:43 AM 1,454 Dc2.reg
22-Nov-06 10:45 AM 161 Dc3.reg
22-Nov-06 11:42 AM 0 Dc4.txt
4 File(s) 3,069 bytes
0 Dir(s) 2,128,506,880 bytes free

C:\RECYCLER\S-1-5-21-1708537768-1580436667-1202660629-1003>
--------------

You can see how Dc1.reg, Dc2.reg, Dc3.reg and Dc4.txt relate to
278startmenupin.reg, startmenupin.reg, pinlistenable.reg and New Text
Document.txt.
Also, I'd like to be able to restore the files put in the trashcan
(even if I put them there from the command line).

Would probably be some sort of a Shell function or call. I have no idea
which one and am not going to go look. Most of that stuff is over my head.
But when I look in the trashcan using the standard GUI I cannot see the
file in there. The trashcan looks as if is empty.

[[No files may appear in the Recycle Bin if the files in the Recycled folder
are damaged.]]

Run chkdsk. Reboot. Look at the Recycle Bin again.

INFO2 can become corrupted and if it cannot be fixed it needs to be deleted.

Cannot Delete Any Files in Windows
http://support.microsoft.com/kb/246726

How the Recycle Bin Stores Files
http://support.microsoft.com/kb/136517
Is there perhaps some other exe-file that is run when a user presses
the "delete" button in a regular folder view? and/or generates the info
in INFO2?

My silly wild a** guess would be explorer.exe and shell32.dll.

I just found this one, looks interesting haven't read it yet.

Forensic Analysis of Microsoft Windows Recycle Bin Records
http://www.e-fense.com/helix/Docs/Recycler_Bin_Record_Reconstruction.pdf
or view as html
http://72.14.253.104/search?q=cache...ion.pdf+"INFO2+file"&hl=en&gl=us&ct=clnk&cd=2


--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
P

per9000

Hi Wesley,

When you delete a file, the complete path and file name is stored in a
hidden file called Info2 in the Recycler folder.

Ok, I suspected something like that.

I wonder why the high number, 12466? INFO2 messed up?

I create tons of log files at work (most of which I just delete - these
are the ones I'd like to put in the trash instead of hard-killing
them). Probably that's why I have the large number.

I'll try to avoid hacking INFO2 - but I am tempted :)

Would probably be some sort of a Shell function or call. I have no idea
which one and am not going to go look. Most of that stuff is over my head.

Ok, that's too bad - I was hoping for some way to '"press the delete
button in the gui" from the console'.

But when I look in the trashcan using the standard GUI I cannot see the
file in there. The trashcan looks as if is empty.

[[No files may appear in the Recycle Bin if the files in the Recycled folder
are damaged.]]

This was probably an artifact from
move /Y *.* C:\RECYCLER\*numbers*

I put a file in there from the console - I could not see the file from
the trashcan view. Probably because there was no info of it in INFO2. I
removed the file from the console and now the trashcan seems healthy.

Forensic Analysis of Microsoft Windows Recycle Bin Records
http://www.e-fense.com/helix/Docs/Recycler_Bin_Record_Reconstruction.pdf

Seems interesting - but I don't want to risk a trash-can-crash by
hacking INFO2. I was looking for some exe/dll-file to call to do the
dirty work for me.

Hope this helps. Let us know.

Well, it didn't solve my "problem" but it explained a lot. Thanks.

/Per
 
W

Wesley Vogel

Howdy Per,
Ok, that's too bad - I was hoping for some way to '"press the delete
button in the gui" from the console'.

I believe that the del command is the same as hitting Shift + Delete on the
keyboard.

Warning
After you delete a file from your disk using del, you cannot retrieve it.

Type in Start | Run
hh ntcmds.chm::/del.htm

SHIFT+DELETE
Delete selected item permanently without placing the item in the Recycle
Bin.

To permanently delete a file, press and hold down SHIFT and drag it to the
Recycle Bin. The item is permanently deleted and cannot be retrieved from
the Recycle Bin.
This was probably an artifact from
move /Y *.* C:\RECYCLER\*numbers*

I put a file in there from the console - I could not see the file from
the trashcan view. Probably because there was no info of it in INFO2. I
removed the file from the console and now the trashcan seems healthy.

That would explain it.

You ought to buy a mouse. That right click is the latest thing. ;-)

You might use a VBS script, see...
To delete a text file and send it to the Recycle Bin
here...
How to: Delete a File in Visual Basic
http://msdn2.microsoft.com/en-gb/library/tdx72k4b(VS.80).aspx

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
per9000 said:
Hi Wesley,

When you delete a file, the complete path and file name is stored in a
hidden file called Info2 in the Recycler folder.

Ok, I suspected something like that.

I wonder why the high number, 12466? INFO2 messed up?

I create tons of log files at work (most of which I just delete - these
are the ones I'd like to put in the trash instead of hard-killing
them). Probably that's why I have the large number.

I'll try to avoid hacking INFO2 - but I am tempted :)

Would probably be some sort of a Shell function or call. I have no idea
which one and am not going to go look. Most of that stuff is over my
head.

Ok, that's too bad - I was hoping for some way to '"press the delete
button in the gui" from the console'.

But when I look in the trashcan using the standard GUI I cannot see the
file in there. The trashcan looks as if is empty.

[[No files may appear in the Recycle Bin if the files in the Recycled
folder are damaged.]]

This was probably an artifact from
move /Y *.* C:\RECYCLER\*numbers*

I put a file in there from the console - I could not see the file from
the trashcan view. Probably because there was no info of it in INFO2. I
removed the file from the console and now the trashcan seems healthy.

Forensic Analysis of Microsoft Windows Recycle Bin Records
http://www.e-fense.com/helix/Docs/Recycler_Bin_Record_Reconstruction.pdf

Seems interesting - but I don't want to risk a trash-can-crash by
hacking INFO2. I was looking for some exe/dll-file to call to do the
dirty work for me.

Hope this helps. Let us know.

Well, it didn't solve my "problem" but it explained a lot. Thanks.

/Per
 
P

per9000

Hi.

Wesley said:
You ought to buy a mouse. That right click is the latest thing. ;-)

Mouse schmouse, me like qwerty :-D

You might use a VBS script, see...
To delete a text file and send it to the Recycle Bin
here...
How to: Delete a File in Visual Basic
http://msdn2.microsoft.com/en-gb/library/tdx72k4b(VS.80).aspx

Yes, that could be perfect (I always needed an excuse to learn Visual
Basic (but I would have thought I'd learn VB.NET before VBS)) so this
could be really excellent.

The key seems to be (in VB.NET):
My.Computer.FileSystem.DeleteFile("C:\test.txt", _
FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin)

I'll try it out and tell you what happens - unless I make a bad loop...

Thanks,
Per
 
W

Wesley Vogel

Hi Per,
Mouse schmouse, me like qwerty :-D

At least not Dvorak.
The key seems to be (in VB.NET):

I'd use VB, you already have cscript.exe and wscript.exe on your machine. I
have even done a *little* vbs scripting. Use a vbs extension.

For example, this will open the Run command

-------FileRun.vbs---------
Dim objShell
set objShell = CreateObject("Shell.Application")
objShell.FileRun
-------FileRun.vbs---------

You can drag .vbs files into the command prompt to run them. I know, the
schmouse deal.


cscript /?

wscript /?

---------------------------
Windows Script Host
---------------------------
Usage: WScript scriptname.extension [option...] [arguments...]

Options:
//B Batch mode: Suppresses script errors and prompts from displaying
//D Enable Active Debugging
//E:engine Use engine for executing script
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
//I Interactive mode (default, opposite of //B)
//Job:xxxx Execute a WSF job
//Logo Display logo (default)
//Nologo Prevent logo display: No banner will be shown at execution time
//S Save current command line options for this user
//T:nn Time out in seconds: Maximum time a script is permitted to run
//X Execute script in debugger
---------------------------
OK
---------------------------

Windows Scripting Guide
http://www.winguides.com/scripting/

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
P

per9000

Hi,

since I still need (sooner or later) to use Visual Basic .NET (we will
soon launch a product in .NET so we need to support users using Visual
Basic (and all the other .NET languages)) I installed MS Visual Basic
2005 Express Edition (big thank you to MS for the MSV*2005EE-series, I
have installed C++, C# and now the VB version) and did my first little
VB'ing.

At first I got a popup asking me if I really wanted to move the file to
trash, but using FileIO.UIOption.OnlyErrorDialogs instead of the option
in a previous message did the trick.

----------------
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello VB.NET World!")
My.Computer.FileSystem.DeleteFile("C:\temp\time.txt",
FileIO.UIOption.OnlyErrorDialogs,
FileIO.RecycleOption.SendToRecycleBin)
End Sub
End Module
----------------

Now I only have to learn to import arguments from the console to VB and
incorporate wildcards (f.x "trashem prefix*suffix.log") - should not be
to hard if I want to finish this.

So it's "problem solved" (all that remains are some details) and again:
Thanks.

/Per
 
P

per9000

Hi again,

just to finish thing up, here is the Visual Basic code that works fine
for me. No switches, no fancy stuff at all, I might add some later

(Perhaps "/S" (or "-r") to get it recursive, matches to arguments 2, 3,
.... and a quiet switch).

Puts all files in present working directory that matches wildcard in
args(0) in trashcan.

----------------
Imports System
Imports System.IO
Module ToTrash
Sub Main(ByVal Args() As String)

Dim pwd As String = Directory.GetCurrentDirectory()
Dim files() As String = Directory.GetFiles(pwd, Args(0),
System.IO.SearchOption.TopDirectoryOnly)

Dim I As Integer = files.Length
Dim J As Integer = 0

For J = 0 To I - 1
Console.WriteLine("Trash: " & files(J))
My.Computer.FileSystem.DeleteFile(files(J),
FileIO.UIOption.OnlyErrorDialogs,
FileIO.RecycleOption.SendToRecycleBin)
Next

End Sub
End Module
----------------

To even more motivate the need of this (or any equivalent scripts) I
today had 10300-something log files that I have no need of (but that I
just might need later). When I selected these files in the regular
windows explorer window and pressed delete the open window jammed and
stopped responding.

My first tries with toTrash tells me that this is a lot slower than
"del *.*", but on the other hand I print lots of stuff on the console.

Thanks again for pointers and patience,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top