You are not logged in.

#1 11 Nov 2015 21:22

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Sdel - secure delete utility

I have been working a a batch file that will securely delete file and it is now complete however I would like to make it like a cmd command perhaps by turning it in to a hybrid but I don't know how to do this here's the code.

@echo off
title SDEL - secure, speedy deltetion
: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 %o%==d goto folder
if %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
pause>WARNING- This file will delete all files named *.sdel in %filepath% press any key to continue...
del *.sdel
goto x

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

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
goto :x

rem Exit this batch
:x
echo.
echo coded by Batchcc
echo Special thanks to Trebor68 for helping.
echo http://www.dostips.com/forum/viewtopic.php?p=43862#p43862
echo this file may be redistributed but do NOT remove the credits.
echo You are now exiting this batch file, deletion complete...
pause
goto :eof

Can I turn this into a file that I can just run a command for it to work like sdel filePath\file.extension /f or /d ?
Thanks.

Offline

#2 11 Nov 2015 21:33

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Sdel - secure delete utility

If you're trying to be able to run it from any directory on your computer, all you have to do is put the script in one of the directories listed in your system PATH.

Open the command prompt, type echo %PATH%, pick one of the directories listed, and put the script in there. You will then be able to run the script without needing to type the full path.

Offline

#3 13 Nov 2015 14:58

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Sdel - secure delete utility

See here for details about using command line arguments:

http://ss64.com/nt/syntax-args.html


cmd | *sh | ruby | chef

Offline

#4 13 Nov 2015 21:16

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Re: Sdel - secure delete utility

i was looking for something like this but it doesnt work

@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal

for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
   set "jsc=%%v"
)

if not exist "%~n0.exe" (
   "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
)

%~n0.exe %*

endlocal & exit /b %errorlevel%

*/

import System;

var arguments:String[] = Environment.GetCommandLineArgs();

var newLine = false;
var output = "";
var foregroundColor = Console.ForegroundColor;
var backgroundColor = Console.BackgroundColor;
var evaluate = false;
var currentBackground=Console.BackgroundColor;
var currentForeground=Console.ForegroundColor;


//http://stackoverflow.com/a/24294348/388389
var jsEscapes = {
  'n': '\n',
  'r': '\r',
  't': '\t',
  'f': '\f',
  'v': '\v',
  'b': '\b'
};

function decodeJsEscape(_, hex0, hex1, octal, other) {
  var hex = hex0 || hex1;
  if (hex) { return String.fromCharCode(parseInt(hex, 16)); }
  if (octal) { return String.fromCharCode(parseInt(octal, 8)); }
  return jsEscapes[other] || other;
}

function decodeJsString(s) {
  return s.replace(
      // Matches an escape sequence with UTF-16 in group 1, single byte hex in group 2,
      // octal in group 3, and arbitrary other single-character escapes in group 4.
      /\\(?:u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(.))/g,
      decodeJsEscape);
}


function printHelp( ) {
   print( arguments[0] + "  [path] [file name + extension] -d or -f" );
   print( " " );  
   print( "   -d             Deletes all files in a directory " );
   print( "   -f             Deletes one specifies file ");
   print( "" );
} 
   

if ( arguments.length == 1 || arguments[1].toLowerCase() == "-help" || arguments[1].toLowerCase() == "-help"   ) {
   printHelp();
   Environment.Exit(0);
}


for (var arg = 0; arg < arguments.length; ++arg) {
   if ( arguments[arg].toLowerCase() == "-f" ) {
      evaluate=true;
   }
   
   if ( arguments[arg].toLowerCase() == "-d" ) {
      output=arguments[arg+1];
   }
}

Offline

#5 14 Nov 2015 08:15

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Sdel - secure delete utility

But why are you trying to turn it into a hybrid script? I don't see a single good reason to do so.

Offline

#6 14 Nov 2015 13:58

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Re: Sdel - secure delete utility

Shadow thief I am unable to call sdel from the command line using the command

Sdel H:\folder /d

Or

Sdel H:\file /f

Am I calling it wrong?

Offline

#7 14 Nov 2015 14:47

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Sdel - secure delete utility

It's not that you're calling it wrong, it's that your code currently doesn't support parameters. Read this: http://ss64.com/nt/syntax-args.html

Offline

Board footer

Powered by