Ad

Batch Command Explanation Del %~dp0 + "test.txt"

- 1 answer

for test I've executed this bat file

del %~dp0 + "test.txt"

on my desktop which contained a test.txt file. The test goal was to delete test.txt file.

After the execution, some files disappears. Why? What have I done??

Thanks in advance

Ad

Answer

A batch file containing the code del %~dp0 + "test.txt" does: 1. prompting you whether or not to delete everything in the directory containing the batch file itself (if you answered y, all files in that directory are deleted, including the batch file itself); 2. deleting a file called + in the current directory; 3. deleting the file test.txt in the current directory. The current directory is not necessarily the same as the parent directory of the batch file (although in your case it is, I think...)!

Thank you aschipfl for the answer (as comment of question).

Ad
source: stackoverflow.com
Ad