Sdel - speedy deletion utility

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Sdel secure speedy deletion utility

#31 Post by Squashman » 21 Dec 2015 16:08

thefeduke wrote: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.

But my posts were 4 days before yours so that was a really really long poker sessions you had.

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

Re: Sdel - speedy deletion utility

#32 Post by batchcc » 21 Dec 2015 17:13

Sorry Squashman,
I was just wondering when to use "!" instead of "%", I thought you had changed that sorry.

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

Re: Sdel secure speedy deletion utility

#33 Post by foxidrive » 21 Dec 2015 19:14

Squashman wrote:But my posts were 4 days before yours so that was a really really long poker sessions you had.


It's John's shout at the bar, he must be bloody rich after that run of wins! ;)

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

Re: Sdel - speedy deletion utility

#34 Post by Squashman » 21 Dec 2015 19:44

batchcc wrote:Sorry Squashman,
I was just wondering when to use "!" instead of "%", I thought you had changed that sorry.

Two people here told you that you needed to use delayed expansion and also in your question on StackOverflow.

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

Re: Sdel - speedy deletion utility

#35 Post by foxidrive » 21 Dec 2015 19:58

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

Code: Select all

sdel /f "file-path-here"


This is untested, and it will need a little study to figure out as it's an unusual way of arranging the code.

It may not work - so test it first - and see below for some comments regarding your deletion technique, which is why this is not exactly the same.

Code: Select all

@echo off
title SDEL - speedy deletion utility

:del-file
if /i "%~1"=="/f" if exist "%~2"  (
   if /i not "%~f0"=="%~f2" call ren "%~2" "%%random%%%%random%%%%random%%%%random%%%%random%%%%random%%%%random%%.sdel.sdel"
   del "%~dp2\*.sdel.sdel" 2>nul
   goto :x
) else (goto :missing)

:del-folder
if /i "%~1"=="/d" if exist "%~2\" (
   for %%a in ("%~2\*.*") do if /i not "%~f0"=="%%~fa" call ren "%%a" "%%random%%%%random%%%%random%%%%random%%%%random%%%%random%%%%random%%.sdel.sdel"
   del "%~2\*.sdel.sdel" 2>nul
   goto :x
) else (goto :missing)

:again
cls
echo  SDEL - File deletion program
echo. (it only scrambles the filename, the data will still exist on the drive)
echo.
echo    F  -  Delete only one file
echo    D  -  Delete all files in a directory/folder that you supply
echo    E  -  Exit this batch file
echo.

set "o="
set /p "o=Please select an option: "
if /i "%o%"=="F" goto :file
if /i "%o%"=="D" goto :folder
if /i "%o%"=="E" goto :EOF
goto :again

rem Delete only one file
:file
   set "f="
   set /p "f=Enter path of file including extension: "
   call :del-file /f "%f%"
   goto :EOF

rem Delete all files in selected directory (folder)
:folder
   set "d="
   set /p "d=enter path of folder to delete: "
   call :del-folder /d "%d%"
   goto :EOF

:missing
echo "%~2" doesn't exist - try again
pause
goto :EOF

:x
echo Deletion complete...
pause



A point you need to research is to understand that deleting a file doesn't remove it from the hard drive, nor does it change the file contents in any way.

Your code scrambles the filename in the file tables - but the data is unchanged and the file can be undeleted.

Using type>nul filename doesn't overwrite the file contents, it just sets the filesize to zero in the file tables, but the file still exists in the same place on the hard drive.

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

Re: Sdel - speedy deletion utility

#36 Post by thefeduke » 22 Dec 2015 02:29

Nice collaboration, moderators! Foxidrive's repackaging addressed the bad CD exposure that concerned me.

Now that I have recovered from Monday night pool, I'll apologize for some "senior moments" over the weekend. This topic piqued my interest about last Friday and I got so consumed in forensics to understand what was happening using Wednesday's code to better explain things to batchcc, that I completely missed the progress on Saturday afternoon. My error, that I was suspended on the last post on page one, but I am content to accept your good-natured humor.

More about the security part. A judicious defragmentation regime improves the chances of really over-writing the data, but is not a guarantee. If I understand correctly, the mechanisms that erase data from removable flash media are more secure than the traditional hard-disk. I must stress that there is no substitute for absolute physical security of the hardware.
John A.

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

Re: Sdel - speedy deletion utility

#37 Post by foxidrive » 22 Dec 2015 04:34

I was suspended on the last post on page one

Been there, done that. :) Will do it again.
More about the security part. A judicious defragmentation regime improves the chances of really over-writing the data, but is not a guarantee. If I understand correctly, the mechanisms that erase data from removable flash media are more secure than the traditional hard-disk.

You may be right John, particularly with the more modern secure versions. Flash drive technology has overtaken me.

Defragmentation does shuffle bits around as you say, but if secure deletion is needed then Microsoft provide a tool from Sysinternals which is perfect for the job. https://technet.microsoft.com/en-us/sys ... elete.aspx

Military grade file deletion probably needs a different tool.

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

Re: Sdel - speedy deletion utility

#38 Post by batchcc » 01 Jan 2016 10:57

I tried to add a /s function to sdel.bat but its not working can someone explain why?

sdel /s

Code: Select all

if /i "%~1"=="/s" (
goto sub
)


:sub
if "%~2"=="" (
   set /p d=enter path of folder to delete:
) else (
   set "d=%~2"
)

cd /d %d%
setlocal EnableDelayedExpansion
FORFILES /S /C "CMD /C ECHO @relpath">slist.txt
for /f "delims=" %%f in (slist.txt) do (
if not "%~nx0"=="%%a" ren "%%~a" "sdel!random!.sdel"
for %%a in (*.sdel) do type nul > %%a
del *.sdel
)
"%%f"
:x

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

Re: Sdel - speedy deletion utility

#39 Post by Squashman » 01 Jan 2016 11:29

Your FOR variable is %%f but you are using %%a.

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

Re: Sdel - speedy deletion utility

#40 Post by batchcc » 01 Jan 2016 14:13

This still doesn't seem to be working for me.

Code: Select all

if /i "%~1"=="/s" (
goto sub
)


:sub
if "%~2"=="" (
   set /p d=enter path of folder to delete:
) else (
   set "d=%~2"
)

cd /d %d%
setlocal EnableDelayedExpansion
FORFILES /S /C "CMD /C ECHO @relpath">slist.txt
for /f "delims=" %%f in (slist.txt) do (
if not "%~nx0"=="%%f" ren "%%~a" "sdel!random!.sdel"
for %%f in (*.sdel) do type nul > %%f
del *.sdel
)
"%%f"
:x

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

Re: Sdel - speedy deletion utility

#41 Post by foxidrive » 01 Jan 2016 17:08

There may be other issues, but examine your for loop variables again.

I'm only pointing this out, rather than helping, because coding takes a really fine attention to detail - many problems are due to typos.

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

Re: Sdel - speedy deletion utility

#42 Post by Squashman » 01 Jan 2016 17:38

Squashman wrote:Your FOR variable is %%f but you are using %%a.

You still did not fix this error.

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

Re: Sdel - speedy deletion utility

#43 Post by batchcc » 01 Jan 2016 18:56

Oh I just replaced %%a with %%f but I also needed to change this

Code: Select all

if not "%~nx0"=="%%f" ren "%%~a" "sdel!random!.sdel"

To this

Code: Select all

if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"

I'm not sure if this is correct and I am unable to check to see if it works right now but I will see to tomorrow.

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

Re: Sdel - speedy deletion utility

#44 Post by batchcc » 02 Jan 2016 06:13

this still doesn't work

Code: Select all

if /i "%~1"=="/s" (
goto sub
)


:sub
if "%~2"=="" (
   set /p d=enter path of folder to delete:
) else (
   set "d=%~2"
)

cd /d %d%
setlocal EnableDelayedExpansion
FORFILES /S /C "CMD /C ECHO @relpath">slist.txt
for /f "delims=" %%f in (slist.txt) do (
if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"
for %%f in (*.sdel) do type nul > %%f
del *.sdel
)
"%%f"
:x

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Sdel - speedy deletion utility

#45 Post by Meerkat » 02 Jan 2016 06:40

batchcc wrote:this still doesn't work

Code: Select all

if /i "%~1"=="/s" (
goto sub
)


:sub
if "%~2"=="" (
   set /p d=enter path of folder to delete:
) else (
   set "d=%~2"
)

cd /d %d%
setlocal EnableDelayedExpansion
FORFILES /S /C "CMD /C ECHO @relpath">slist.txt
for /f "delims=" %%f in (slist.txt) do (
if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"
for %%f in (*.sdel) do type nul > %%f
del *.sdel
)
"%%f"
:x

Hmm... at this part

Code: Select all

for %%f in (*.sdel) do type nul > %%f

I am not sure, but just use another "letter" aside from f because it "interferes" with the another %%f on this code:

Code: Select all

for /f "delims=" %%f in (slist.txt) do (

Another is the "%%f" near the last line. Since this is outside the FOR loop, it will not work. I do not know, but maybe you want to echo the files that will be deleted. If yes, then this would work:

Code: Select all

cd /d %d%
setlocal EnableDelayedExpansion
FORFILES /S /C "CMD /C ECHO @relpath">slist.txt
for /f "delims=" %%f in (slist.txt) do if not "%~nx0"=="%%f" ren "%%~f" "sdel!random!.sdel"
for %%a in (*.sdel) do (
   type nul >"%%a"
   echo "%%a"
   del /f "%%a"
)


Meerkat

Post Reply