Sdel - speedy deletion utility
Moderator: DosItHelp
Re: Sdel - speedy deletion utility
Sorry Meerkat but the code doesn’t delete the files in sub directories like it was intended to do you have any idea why and how to fix it
Re: Sdel - speedy deletion utility
Sorry, my bad. My previous code is terrible because I am not familiar with FORFILES command.
Now, I tested this, and this worked for me, but I have some reminders on this code:
So, here is the code snippet:
UPDATE: This will fail if file name contains exclamation (!) because of delayed expansion. I know it is in this code:
Meerkat
Now, I tested this, and this worked for me, but I have some reminders on this code:
- We must NOT rename directories. It is because files inside it will not be found, renamed, overwritten, deleted. Therefore, only files will be renamed, not the folders.
- We must put the slist.txt out (%tmp% folder will do), so that it will not be renamed.
- I do not think this will be speedy anymore, but I know it works.
- Code looks ugly, but commented.
So, here is the code snippet:
Code: Select all
setlocal EnableDelayedExpansion
FORFILES /S /C "CMD /C ECHO @relpath:@isDir">"%TMP%\slist.txt"
::Rename FILES, but NOT folders.
for /f "tokens=1* delims=:" %%f in ('type "%TMP%\slist.txt"') do (
if %%g==FALSE if /i not "%~f0"=="%%~ff" ren "%%~f" "sdel!random!.sdel"
)
::Do some sadistic actions on files.
for /r %%a in (*.sdel) do (
type nul >"%%a"
del /f "%%a"
)
::Delete folders
for /f "tokens=1* delims=:" %%a in ('type "%TMP%\slist.txt"') do if %%b==TRUE rd "%%~a"
del "%TMP%\slist.txt"
UPDATE: This will fail if file name contains exclamation (!) because of delayed expansion. I know it is in this code:
Code: Select all
for /f "tokens=1* delims=:" %%f in ('type "%TMP%\slist.txt"') do (
if %%g==FALSE if /i not "%~f0"=="%%~ff" ren "%%~f" "sdel!random!.sdel"
)
Meerkat
Re: Sdel - speedy deletion utility
Thanks Merkat the code works great!
Re: Sdel - speedy deletion utility
You sure are doing a lot of work for a program that really does not do secure deletion of a file. I could download a dozen different utilities from the web that could recover the files you are trying to "securely" delete.
Re: Sdel - speedy deletion utility
Squashman wrote:You sure are doing a lot of work for a program that really does not do secure deletion of a file. I could download a dozen different utilities from the web that could recover the files you are trying to "securely" delete.
Squashman I have decided to change the objective of sdel.bat from securly deleting files to speedily deleting files, I also want to add features to save time like
Code: Select all
if "%~1"=="/e" goto ext
:ext
if "%~2"=="" (
set /p d=enter path of folder to delete:
) else (
set "d=%~2"
)
if "%~3"=="" (
set /p d=enter extension:
) else (
set "ext=%~3"
)
cd /d %d%
setlocal EnableDelayedExpansion
for %%a in (*.%ext%) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)
but i would like to add a function that allows the user to exclude an extension but it doesn't work do you know why?
Code: Select all
if "%~1"=="/em" goto extm
:extm
if "%~2"=="" (
set /p d=enter path of folder to delete:
) else (
set "d=%~2"
)
if "%~3"=="" (
set /p d=enter extension:
) else (
set "ext=%~3"
)
cd /d %d%
for /f "eol=: delims=" %%F in ('dir /b /a-d^|findstr /vire "\.%extm%"') do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)
"%%F"
Re: Sdel - speedy deletion utility
I do not see how your objective has changed because the code is still doing a pseudo secure delete which slows everything down and even if it was just doing deletion it would not be any faster then just navigating with explorer and deleting the file.
Re: Sdel - speedy deletion utility
batchcc wrote:but i would like to add a function that allows the user to exclude an extension but it doesn't work do you know why?
Surely you can't be serious.
Debug your code!!!!!!!!!!!!!!!!!!!!!!!
I will even give a hint. If I had to give you a grade for that code I would give you an F.
Re: Sdel - speedy deletion utility
Thank you so much
your grade was very helpful!Squashman wrote:If I had to give you a grade for that code I would give you an F.
Code: Select all
if "%~1"=="/em" goto extm
:extm
if "%~2"=="" (
set /p d=enter path of folder to delete:
) else (
set "d=%~2"
)
if "%~3"=="" (
set /p d=enter extension:
) else (
set "extm=%~3"
)
cd /d %d%
for /f "eol=: delims=" %%f in ('dir /b /a-d^|findstr /vire "\.%extm%"') do (
if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"
for %%f in (*.sdel) do type nul > %%f
del *.sdel
"%%f"
)
Re: Sdel - speedy deletion utility
Several things there will cause your script to fail with certain names.
Did you notice the error messages on the console screen? Try it with the pause I added.
batchcc wrote:cd /d %d%
for /f "eol=: delims=" %%f in ('dir /b /a-d^|findstr /vire "\.%extm%"') do (
if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"
for %%f in (*.sdel) do type nul > %%f
del *.sdel
"%%f"
)
pause
[/code]
Did you notice the error messages on the console screen? Try it with the pause I added.
Re: Sdel - speedy deletion utility
foxidrive wrote:Several things there will cause your script to fail with certain names.batchcc wrote:Code: Select all
cd /d %d%
for /f "eol=: delims=" %%f in ('dir /b /a-d^|findstr /vire "\.%extm%"') do (
if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"
for %%f in (*.sdel) do type nul > %%f
del *.sdel
"%%f"
)
pause
Did you notice the error messages on the console screen? Try it with the pause I added.
Okay Foxdrive but I am unsure of how to fix these errors
Re: Sdel - speedy deletion utility
Why do you have "%%f" on a line by itself.
Re: Sdel - speedy deletion utility
Squashman wrote:Why do you have "%%f" on a line by itself.
When I was looking at other codes on SO there was %%f at the end of the line so I placed it at the end of the code I'm not sure if that's correct or not.
Re: Sdel - speedy deletion utility
batchcc wrote:Squashman wrote:Why do you have "%%f" on a line by itself.
When I was looking at other codes on SO there was %%f at the end of the line so I placed it at the end of the code I'm not sure if that's correct or not.
Well you got a 50/50 chance of being wrong.
Re: Sdel - speedy deletion utility
batchcc wrote:Okay Foxdrive but I am unsure of how to fix these errors
Here's a method to do the same thing you are doing, which should be robust.
Ask any questions you have, as it seems that you're struggling a little at this point in time.
Those first two lines below do nothing, but you may know that.
Code: Select all
if /i "%~1"=="/em" goto extm
:extm
:re-enter-path
set "d=%~2"
if not defined d set /p "d=enter path of folder to delete: "
if not exist "%d%\" echo Have another bash at that! & goto :re-enter-path
set "extm=%~3"
if not defined extm set /p "extm=enter extension: "
if not exist "%d%\*.%extm%" echo There are no "*.%extm%" files & pause & goto :EOF
cd /d "%d%"
del sdel*.sdel 2>nul
for /f "delims=" %%f in ('dir /b /a-d^|findstr /vire "\.%extm%"') do (
if /i not "%~nx0"=="%%f" for %%g in ("sdel!random!.sdel") do (
ren "%%f" "%%~g"
break>"%%~g"
del "%%~g"
)
)
pause
Re: Sdel - speedy deletion utility
foxidrive wrote:batchcc wrote:Okay Foxdrive but I am unsure of how to fix these errors
Here's a method to do the same thing you are doing, which should be robust.
Ask any questions you have, as it seems that you're struggling a little at this point in time.
Those first two lines below do nothing, but you may know that.Code: Select all
if /i "%~1"=="/em" goto extm
:extm
:re-enter-path
set "d=%~2"
if not defined d set /p "d=enter path of folder to delete: "
if not exist "%d%\" echo Have another bash at that! & goto :re-enter-path
set "extm=%~3"
if not defined extm set /p "extm=enter extension: "
if not exist "%d%\*.%extm%" echo There are no "*.%extm%" files & pause & goto :EOF
cd /d "%d%"
del sdel*.sdel 2>nul
for /f "delims=" %%f in ('dir /b /a-d^|findstr /vire "\.%extm%"') do (
if /i not "%~nx0"=="%%f" for %%g in ("sdel!random!.sdel") do (
ren "%%f" "%%~g"
break>"%%~g"
del "%%~g"
)
)
pause
when added to the main file the first two lines will have a purpose (I know the're useless now) but the code doesnt work on my computer Foxdrive
Code: Select all
H:\1\A\del>Delete /em H:\1\A\del bat
H:\1\A\del>if /I "/em" == "/em" goto extm
H:\1\A\del>set "d=H:\1\A\del"
H:\1\A\del>if not defined d set /p "d=enter path of folder to delete: "
H:\1\A\del>if not exist "H:\1\A\del\" echo Have another bash at that! & goto :
re-enter-path
H:\1\A\del>set "extm=bat"
H:\1\A\del>if not defined extm set /p "extm=enter extension: "
H:\1\A\del>if not exist "H:\1\A\del\*.bat" echo There are no "*.bat" files & p
ause & goto :EOF
H:\1\A\del>cd /d "H:\1\A\del"
H:\1\A\del>del sdel*.sdel 2>nul
H:\1\A\del\sdel!random!.sdel
H:\1\A\del>for /F "delims=" %f in ('dir /b /a-d|findstr /vire "\.bat"') do (if /
I not "Delete.bat" == "%f" for %g in ("sdel!random!.sdel") do (
ren "%f" "%~g"
break1>"%~g"
del "%~g"
) )
H:\1\A\del>(if /I not "Delete.bat" == "sdel!random!.sdel" for %g in ("sdel!rando
m!.sdel") do (
ren "sdel!random!.sdel" "%~g"
break1>"%~g"
del "%~g"
) )
H:\1\A\del>(
ren "sdel!random!.sdel" "sdel!random!.sdel"
break1>"sdel!random!.sdel"
del "sdel!random!.sdel"
)
Access is denied.
H:\1\A\del\sdel!random!.sdel
Access is denied.
H:\1\A\del>(if /I not "Delete.bat" == "New Bitmap Image.bmp" for %g in ("sdel!ra
ndom!.sdel") do (
ren "New Bitmap Image.bmp" "%~g"
break1>"%~g"
del "%~g"
) )
H:\1\A\del>(
ren "New Bitmap Image.bmp" "sdel!random!.sdel"
break1>"sdel!random!.sdel"
del "sdel!random!.sdel"
)
A duplicate file name exists, or the file
cannot be found.
Access is denied.
H:\1\A\del\sdel!random!.sdel
Access is denied.
H:\1\A\del>(if /I not "Delete.bat" == "hi.txt" for %g in ("sdel!random!.sdel") d
o (
ren "hi.txt" "%~g"
break1>"%~g"
del "%~g"
) )
H:\1\A\del>(
ren "hi.txt" "sdel!random!.sdel"
break1>"sdel!random!.sdel"
del "sdel!random!.sdel"
)
A duplicate file name exists, or the file
cannot be found.
Access is denied.
H:\1\A\del\sdel!random!.sdel
Access is denied.
H:\1\A\del>pause
Press any key to continue . . .