This has been previously answered over on Stack Overflow, which is where I've taken the main thrust of this answer from.
Try the following command, you can run it from within cmd
:
for /d /r . %d in (bin,obj) do @if exist "%d" rd /s/q "%d"
If you need other folders to be changed, then just add new items to the (bin,obj)
set in the middle of the command.
This will delete everything matched without warning and without using the recycle bin - so, if you want a bit of extra safety, drop the /q
from the call to rd
at the end, and the system should ask you before each deletion.
for /d /r . %d in (bin,obj) do @if exist "%d" rd /s "%d"
If you intend to run the command from within a batch file, you will need to replace every instance of the variable %d
with %%d
, like so:
for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"
OR
for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s "%%d"
As per the conversion had in the question comments
If the command refuses to run in a batch file (unable to replicate here), try prefixing the command with start
. Although this will start the process to run concurrently with the batch file, which may cause other issues, it seems more likely to work correctly.
Also, if you have files named obj
or bin
within the folder tree the command is working on, then you will receive an error message for each file encountered that has a matching name. These matched files are not deleted, and should not get in the way of the command deleting what it should. In other words, they can be ignored safely.
Short Answer: add /t
to (i)cacls
Long answer:
Here is my script I use when I want the file to be accessible to any user. It includes comments on what each flag does. Just put this in a batch file somewhere in the %AppData%
folder.
REM --v2 -----------------------------------------------------------
takeown /r /d y /f %1
icacls %1 /t /grant Everyone:F
REM takeown /r /d y /f will set the owner to the Administrators group recursively.
REM /t makes it recursive
REM /grant Sets the permision to the following user, replaces existing permissions for the specified uesr.
REM :f Grants full controll permission.
REM ----------------------------------------------------------------
REM --v1 -----------------------------------------------------------
REM cacls %1 /t /e /g Everyone:f
REM /t makes it recursive
REM /e Edits the ACL instead of replaceing it
REM /g Grants permissions to the following users
REM :f Grants full controll permission.
REM ----------------------------------------------------------------
Then in %AppData%\Microsoft\Windows\SendTo
create a shortcut to the batch script.
Edit the properties of that shortcut and go to Advanced...
and check the box Run as Administrator.
Now in your right click menu -> Send To
you will have a item called Fix Permissions
any file or folder you do a Send To
on will have the Everyone group given Full Access
permissions. If you perform it on a folder it will recursively go through it and apply the permissions to all of the children in the folder.
I save the batch file the %AppData%
folder because I am on a domain and that makes it part of my roaming profile so it will be on and ready to use on any computer I connect to.
Best Answer
From: https://stackoverflow.com/questions/1420965/redirect-stdout-and-stderr-to-a-single-file
You can redirect both the standard output (stdout) as well as the standard error (stderr) to the same log file.
Such as