Re: Batch Job
"dr_ahmed" wrote in message
news:20594AB7-013F-490F-927B-8CA0AF5E052D@microsoft.com...
> when i tried that it tolds me that: The system cannot find the file
> specified.
> i just copy and paste it
DO NOT RUN THE FOLLOWING BATCH SCRIPT
Only showing what could be done in a .bat file.
Running this batch script will clean out the Recycle Bin but also render
it unusable until the next reboot.
Windows will withhold permissions from some programs for "special"
folders. You cannot use the 'del' command at a DOS prompt. Instead use
the 'for' command to walk through every subfolder to delete the files
within each one. The 'for', like the 'cd' command, will let you
navigate into those special folders and then you can use relative
references to delete the files.
pushd
C:
for /r c:\recycler %I in (.) do (
cd /d "%I"
attrib -h -s *
del /f /q *
)
popd
The above works from the DOS prompt. In a batch file, you need to
double up on the percent signs; i.e., %I becomes %%I. That is to ensure
the command parser sees in a batch file that you are identifying a
replaceable parameter (variable) rather than trying to retrieve its
value.
- The /r switch means to recurse through the subfolders. The 'for'
command can get into special folders that 'del' cannot.
- The "." for the set will return the list of subfolders rather than
files (since 'del' might not work into the special folder).
- The /d switch is required on the 'cd' command to ensure that you
actually change to that path when you follow with the 'attrib' and 'del'
commands. Otherwise, 'cd' (without /d) while you are on D: would end up
changing the working path on C: but you are still on D: when the
'attrib' and 'del' command executed which means you would be deleting
the wrong files.
- I added the C: just before the for-loop merely for precaution to
ensure you really are on the C: drive in case 'cd' doesn't have the /d
switch in your version of Windows.
- 'del' won't work on files with the hidden and system file attributes,
so 'attrib' removes those.
- The pushd saves where you were before changing drives/folders using
'cd /d' and popd returns you there. That way, you won't be left in some
subfolder that is different than where you started.
The above only delete the files. It won't delete any subfolders under
the <d>:\Recycler folder.
Yeah, while the above will delete the deleted files from the Recycle Bin
but it also deletes configuration files used by the Recycle Bin. When
you delete all the files, the config files are also deleted. The
Recycle Bin won't work after that; i.e., you can still delete files but
they won't get moved into the Recycle Bin. To see that the above batch
script actually works (too well), you could replace 'del /f /q *' with
'dir'. In fact, you could replace both the 'attrib' and 'del' commands
with 'dir /ah'. Then instead of deleting the files, you get a directory
listing of them in case you are curious as to what is in there.
Rather than figure out which files to delete, there are a couple
options:
1 - Delete the folder.
rmdir /s /q c:\recycler
This deletes the Recycle Bin folder (on the C: drive). That means
deleted files will no longer be saved in the Recycle Bin anytime after
that in your Windows session because the save folder doesn't exist
anymore. When you reboot Windows, and after the first file that you
delete, Windows will recreate the Recycler folder. That means you
delete the folder and reboot to continue using a cleaned up Recycle Bin.
2 - Use the Disk Clean utility.
Read
http://support.microsoft.com/kb/253597/en-us. cleanmgr.exe is the
same program as Disk Cleanup found under Start -> Programs ->
Accessories -> System Tools -> Disk Cleanup. Note that cleanmgr.exe ran
from the command-line will not prompt on which drive to do the cleanup,
so all local hard drives get cleaned up using the same settings that you
specify. To me, this is handy in that I don't need to save settings for
each drive and repeatedly execute cleanmgr.exe on each one. First run:
cleanmgr.exe /sageset:1
to save the settings (in the registry). Then run:
cleanmgr.exe /sagerun:1
in your .bat file or as a scheduled task to do the cleanup. You can use
whatever number you like in the range of 0 to 64K under which to save
the settings for a drive. You could use 0 to have all items selected
for a full cleanup, 1 is for just the temp files and Recycle Bin, 2 is
just offline files, etc. I'd much prefer using strings so I could use
names that help me remember what each set of settings will do but it's
not my program.
When the window pops open in which you select what items to purge, I
select all of them except the last 3 (offline files, compress old files,
catalog files for indexer). The purpose of offline files is to have a
local copy if the file server becomes unavailable. I'm not going to
waste time compressing "old" files and then have to uncompress them
later. The program still wastes time calculating how much space would
be returned by using compression but I don't want it to actually do any
compression. I'll buy a bigger drive instead. I don't run the Indexing
Service (it is Disabled) but even if I did then I wouldn't want it to
consume CPU cycles and data bus bandwidth to reindex everything again.
This is probably the safest way included in Windows to do the cleanup
other than to use a 3rd party tool, like CCleaner (CrapCleaner). You
can specify to include the Recycle Bin in the saved settings. Because
it is a GUI program with command-line switches, you will still see its
window pop open when you run cleanmgr.