batchcc wrote:Foxdrive what i want to do is allow the user to call the file like this
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.