safe delete files command

Jan 13, 2013
27
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]
 
Jan 13, 2013
27
0
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
 
Jan 13, 2013
27
0
That's what I want to do. Thanks. I was making it more complex than it needed to be, it seems.
 
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
 
Jan 13, 2013
27
0
I tried that but got a file not found error. Why does your alias begin with * ? I did not do that.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,495
91
Albuquerque, NM
prospero.unm.edu
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"?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,495
91
Albuquerque, NM
prospero.unm.edu
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.
 
Jan 13, 2013
27
0
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
 
Similar threads
Thread starter Title Forum Replies Date
mikea Error when attempting to launch "Safe in Cloud" Support 3
A Installers delete EVerything service if already installed Support 0
Chen Touboul When i try to delete an empty folder i got "the dirctoy name is invalid" Support 3
I zip /M fails to delete file after adding to zip file Support 2
D SYNC /W copies back instead of propagating a delete Support 2
M Delete multiple Alternate Datastreams Support 5
P How to? Delete subfolders but not the folder itself Support 11
P Can't do something to a file and then delete it? Support 6
nickles WAD del unable to delete files ending in "." Support 18
gschizas Fixed Cannot use extended path to delete invalid file Support 3
M Can't delete files... Support 8
aedthuio REG ADD/DELETE Support 1
vefatica Cut/delete Support 3
D TCMD16 Delete Toolbar Button bug Support 7
G FOLDERMONITOR created also firing for delete (and maybe other events) Support 7
T How to? Select and Delete text Support 6
Joe Caverly How to? Delete a line from a file Support 4
CWBillow Delete based on dates Support 5
JohnQSmith How to? Delete descriptions Support 2
vefatica How do I delete "spaces.txt "? Support 21
A How to? Instruct COPY to delete file if only partially copied (via FTP) Support 8
M Why am I unable to delete files? Support 8
R Delete command sets directory attributes to hidden & system Support 46
S 4NT - delete from command prompt and recycle bin Support 12
Phileosophos COPY /W does not delete files in the target Support 4
T Possible to delete the new standard tab? Support 1
P Sync /w won't delete in ftp folder Support 1
MickeyF TCC crashing when copying multiple files (now resolved) Support 6
fpefpe How to? shortcuts and batch files Support 4
C v28 key files Support 2
J ffind does not find files Support 4
C duplicate files in multiple plugin sites Support 9
Dmitry L. Kobyakov Fixed The SETARRAY /R command works incorrectly with cyrillic files Support 2
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
vefatica FFIND, temp files? ... not deleted? Support 0
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
vefatica Tmp files from in-process pipes not deleted Support 6
vefatica Finding files with alternate data streams? Support 4
rps Multi-column DIR /v not displaying all files. Support 5
D How to skip files in a fileset? Support 6
vefatica PIPEVIEW leaves TMP files Support 18
K "copy /z /w" command not deleting read-only files in destination Support 10
Jesse Heines "Taken" date for JPG and PNG files Support 4
O I cannot use links to .btm files Support 5
C How to? rename files with spaces Support 8
R How to? Append files in multiple subfolders using copy? Support 8
Joe Caverly "Functions" in cmd.exe batch files Support 6
S Batch files Calling Batch Files Support 2
vefatica Find Files/Text dialog: does it work? Support 0
Joe Caverly UNZIPping older .ZIP files Support 3

Similar threads