Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

safe delete files command

Jan
40
0
I wrote a simple batch file I call drydel.btm

echo off
rem drydel means dry run for del command
rem
dir %1$
INKEY /k"YN" del? %%ans
IFF %ans EQ Y THEN
del %1$
ENDIFF

I would like to make this behave like a command, that is, not have to be in the directory I want to use it in. What is the best way for me to do this?

Thx
 
Actually you don't need to be in the directory where you want to delete:
Code:
DRYDEL other\file.a
must work.
If you want to delete several files in the same directory you can use "include lists"
Code:
DRYDEL other\first.a;second.b
To improve the script you could add a test after DIR so that drydel exits if the files don't exist.
There are also alternatives without script
Code:
DEL /P other\first.a;second.b
SELECT DEL [other\first.a;second.b]
 
I thought of those. I was hoping it would be easy, like it was in bash. For bash, I wrote a function and placed it into my .bashrc file.

I thought that function would work that way her also. I read the help file and did not understand it to work that way. I tried defining a function in tcc but it did not work. I guess I don't understand function in the tcc sense. I was expecting bash capability.

As a side note, I'm sure others have also read that Win10 is getting bash this summer. This interests me also.
 
I don't know if I understand what exactly is troubling you. Your mentioning a function in .bashrc could mean that you want to have this DRYDEL.BTM in one place and be able to access it from any directory.
I use to set up my systems with a D:\User\bin directory, where I put all my .BTMs, and have TCSTART.BTM (equivalent to .bashrc) with a line like
Code:
set PATH=D:\User\bin;%PATH
 
I wrote a simple batch file I call drydel.btm

echo off
rem drydel means dry run for del command
rem
dir %1$
INKEY /k"YN" del? %%ans
IFF %ans EQ Y THEN
del %1$
ENDIFF

I would like to make this behave like a command, that is, not have to be in the directory I want to use it in. What is the best way for me to do this?

Thx
One way would be to define an alias that points to DryDel.btm:
ALIAS DRYDEL=`*<drydel's location>\DRYDEL.BTM`

-- Howard
 
I tried that but got a file not found error. Why does your alias begin with * ? I did not do that.
 
Incidentally, it seems you can't use the * prefix after the ? command:
Code:
?*del foobar
gives an "Unknown command" error if you hit Y at the prompt.

Do I win the coveted prize for "Most Antique Bug Ever Reported"?
 
I tried that but got a file not found error. Why does your alias begin with * ? I did not do that.

The asterisk prevents alias expansion on the following command. It's almost certainly not necessary in this case -- you're not gonna have an alias name matching the name of your batch file. This feature is most useful if you're using aliases to intercept internal commands, an advanced and potentially confusing technique.
 
That does what I want. I'm glad I posted. I made it
alias drydel=`del /n %$ & if %_del_files GT 0 ?del %$`

Thanks guys
 
Back
Top
[FOX] Ultimate Translator
Translate