Sdel - speedy deletion utility

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Sdel secure speedy deletion utility

#16 Post by Squashman » 16 Dec 2015 16:14

batchcc wrote:like this? and it still doesn't work.

Code: Select all

cd /d %d%
for %%a in (*.*) do type nul > %%a
for %%a in (*.*) do ren "sdel%random%.sdel" %%a
for %%a in (*.*) do del *.sdel %%a


Looking at my original comments you partially did one of the few things I said.
You only put quotes around one of four file name variables.
And you still have the rename in the wrong order.
You also need to use delayed expansion with the RANDOM variable.
Your last for command can be removed and just use DEL *.sdel

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Sdel secure speedy deletion utility

#17 Post by batchcc » 19 Dec 2015 11:35

I have updated the code

Code: Select all

@echo off
title SDEL - secure, speedy deltetion
if /i "%~1"=="/f" (
goto file
)
if /i "%~1"=="/d" (
goto folder
)
:again
cls
echo  SDEL - Secure delete program
echo.
echo    F  -  Delete only one file
echo    D  -  Delete all files in this directory (folder)
echo    E  -  Exit this batch
echo.
set /p o=Please select a option:
if /i %o%==F goto file
if /i %o%==D goto folder
if /i %o%==E goto x
goto again

rem Delete only one file
:file
set /p f=Enter path of file including extension:
If exist %f% goto del else goto f && echo path invalid
:del
set file=%f%
FOR /f %%i IN ("%file%") DO (

set filepath=%%~pi

)
cd /d %filepath%
type nul> %f%
ren %f% sdel%random%.sdel
del *.sdel
goto x

rem Delete all files in selected directory (folder)
:folder
set /p d=enter path of folder to delete:

cd /d %d%
setlocal EnableDelayedExpansion
for %%a in (*.*) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)

:x
echo deletion complete...
pause

how can i make sdel work with the command sdel /f C:\folder
rather than having to do sdel /f than type the file path? thanks

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Sdel secure speedy deletion utility

#18 Post by Squashman » 19 Dec 2015 12:28

Do the same thing you are doing for argument 1. You are checking if argument 1 is equal to something and if it is, it does something. So logic might tell you to then check argument 2 and then do something.

Let us know when you decide to post your questions on other forums and ignore our attempts to help you.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Sdel secure speedy deletion utility

#19 Post by batchcc » 19 Dec 2015 19:01

Sorry squashman and sorry but Im not sure how to do this I am relatively new to batch coding would you mind helping me do that. Thank you squashman!

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Sdel - speedy deletion utility

#20 Post by Squashman » 19 Dec 2015 19:25

Do you even understand any of the code you are using then?
Tell me what this code does and how you could replicate it too solve your question.

Code: Select all

if /i "%~1"=="/f" (
goto file
)

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Sdel secure speedy deletion utility

#21 Post by thefeduke » 19 Dec 2015 23:29

batchcc wrote:like this? and it still doesn't work.

Code: Select all

cd /d %d%
for %%a in (*.*) do type nul > %%a
for %%a in (*.*) do ren "sdel%random%.sdel" %%a
for %%a in (*.*) do del *.sdel %%a
It does show symptoms of not working because it produces error messages, but it IS working but not as intended.
  • When changing the current directory, you have provided no validity check as you did for deleting a single file. This means that a typing error will cause the 'CD' command to fail with an error message, but all actions will apply to the existing CD and not the intended one. Extreme danger!
  • I recommend a 'pushd %d%' instead of 'CD %d%' with a 'popd' before exiting to leave the working directory undisturbed.
  • Zeroing each does work as desired.
  • The order in the rename command appears to be reversed compared to the single file rename command. Nothing happens but error messages are produced.
  • If the rename order is corrected, errors will occur when multiple files are renamed to the same filename. Use !random! instead of %random% and ensure that delayed expansion is enabled.
  • The delete command has two operands and fails because one of the original file or renamed file does not exist depending on the success of the rename command. As well, all *.sdel files are deleted on the first file and will never be found for multiple files. Ironically, the files that are found are deleted, but as originals, not as scrambled names as was the objective. Replace the 'for' loop with:

    Code: Select all

    del *.sdel 
    because once is all that is required after the rename is fixed.
  • If the 'deletion complete' message is moved to before the appropriate 'goto x' command it won't lie if one selects 'E' as an option.
That's enough for now.
Edit: Sorry, Squashman. While I broke for supper and poker, a page 2 happened while I replied with some points already made by you. I notice a new requirement, too.
John A.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Sdel - speedy deletion utility

#22 Post by batchcc » 20 Dec 2015 12:40

Do you even understand any of the code you are using then?
Tell me what this code does and how you could replicate it too solve your question.
Code:
if /i "%~1"=="/f" (
goto file
)

I only know how it works based on the context of the code.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Sdel - speedy deletion utility

#23 Post by Squashman » 20 Dec 2015 12:56

batchcc wrote:
Do you even understand any of the code you are using then?
Tell me what this code does and how you could replicate it too solve your question.
Code:
if /i "%~1"=="/f" (
goto file
)

I only know how it works based on the context of the code.

What? Why would you say that? That code needs no context or description to know what it is doing.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Sdel - speedy deletion utility

#24 Post by batchcc » 20 Dec 2015 14:11

Based on

Code: Select all

if /i "%~1"=="/?"

I could tell it was a help section I then modied the code to /f but I am still not sure how to use this to intemperate a file path with what I am assuming would look like this

Code: Select all

If /I "%~2"=="something here"

But I am not sure what would go there.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Sdel - speedy deletion utility

#25 Post by foxidrive » 20 Dec 2015 18:10

batchcc wrote:Based on

Code: Select all

if /i "%~1"=="/?"

I could tell it was a help section I then modied the code to /f but I am still not sure how to use this to intemperate a file path with what I am assuming would look like this

Code: Select all

If /I "%~2"=="something here"

But I am not sure what would go there.


When asking for help in coding, you need to explain the aim - tell us what you are trying to do or where the problem is.

Your mother tongue may not be English, as "intemperate" has no meaning above - but please try to explain your task using words.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Sdel - speedy deletion utility

#26 Post by batchcc » 21 Dec 2015 13:57

sorry for the error I meant Interpret
batchcc wrote:Based on

Code: Select all

if /i "%~1"=="/?"

I could tell it was a help section I then modied the code to /f but I am still not sure how to use this to intemperate a file path with what I am assuming would look like this

Code: Select all

If /I "%~2"=="something here"

But I am not sure what would go there.

Foxdrive what i want to do is allow the user to call the file like this

Code: Select all

sdel /f "file-path-here"

so that they can delete the file in one command but I am not sure how to do this. I would think something like this

Code: Select all

If /I "%~2"=="More code here"

but I am not sure what the "More code here" would be.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Sdel - speedy deletion utility

#27 Post by Squashman » 21 Dec 2015 14:23

Code: Select all

@echo off
title SDEL - secure, speedy deltetion
if /i "%~1"=="/f" (
goto file
)
if /i "%~1"=="/d" (
goto folder
)
:again
cls
echo  SDEL - Secure delete program
echo.
echo    F  -  Delete only one file
echo    D  -  Delete all files in this directory (folder)
echo    E  -  Exit this batch
echo.
set /p o=Please select a option:
if /i %o%==F goto file
if /i %o%==D goto folder
if /i %o%==E goto x
goto again

rem Delete only one file
:file
IF "%~2"=="" (
   set /p f=Enter path of file including extension:
) else (
   set "f=%~2"
)

If exist "%f%" (
   goto del
) else (
   echo path invalid
   GOTO :EOF
)

:del
set file=%f%
FOR /f %%i IN ("%file%") DO set filepath=%%~pi
cd /d %filepath%
type nul> %f%
ren %f% sdel%random%.sdel
del *.sdel
goto x

rem Delete all files in selected directory (folder)
:folder
set /p d=enter path of folder to delete:

cd /d %d%
setlocal EnableDelayedExpansion
for %%a in (*.*) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)

:x
echo deletion complete...
pause

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Sdel - speedy deletion utility

#28 Post by batchcc » 21 Dec 2015 15:11

Thank you Squashman, the code works perfectly but I do have a question about it. I noticed that you changed

Code: Select all

sdel%random%.sdel
to

Code: Select all

sdel!random!.sdel
is the a reson why you replaced the "%" with "!"

Code: Select all

cd /d %d%
setlocal EnableDelayedExpansion
for %%a in (*.*) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)

Thank you again -Batchcc

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Sdel - speedy deletion utility

#29 Post by thefeduke » 21 Dec 2015 16:01

batchcc wrote: is the a reson why you replaced the "%" with "!"

Please re-read my post above where I wrote:
If the rename order is corrected, errors will occur when multiple files are renamed to the same filename. Use !random! instead of %random% and ensure that delayed expansion is enabled.
Without that %random% is evaluated once and all files will be renamed to the same name.
!! caused a new random number for each file.
John A.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Sdel - speedy deletion utility

#30 Post by Squashman » 21 Dec 2015 16:05

batchcc, Not sure what you are talking about. The only changes I made were in reference to the second argument being passed to the batch file.

Your code from this post:
viewtopic.php?f=3&t=6775&start=15#p44465

Code: Select all

cd /d %d%
setlocal EnableDelayedExpansion
for %%a in (*.*) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)

My code from this post does not look any different.
viewtopic.php?f=3&t=6775&start=15#p44495

Code: Select all

cd /d %d%
setlocal EnableDelayedExpansion
for %%a in (*.*) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)

Post Reply