vadre1121
vadre1121

Reputation: 23

Odd behavior with the DEL command

Was writing a short script to search out all files with a certain extension, rename them and delete them... but I noticed some odd behavior in the delete script.

Let's say I have four files: file.lo, file.log, file.logs, & file.logarithm

If I use the command del /s /q /f *.lo then only file.lo is deleted. If I use the command del /s /q /f *.logs then only file.logs is deleted.

But if I use the command del /s /q /f *.log then .log, .logs, and .logarithm are deleted. The only file that remains is file.lo

Can anyone explain this behavior?

Upvotes: 2

Views: 54

Answers (2)

Dennis van Gils
Dennis van Gils

Reputation: 3452

According to this answer, using an extension of exactly 3 characters in a search pattern causes the search to also return matching files with longer extensions, and otherwise allways finds exactly the right files. You should apparently use "file?.log", "file.log." as Stephan suggests, or one of these suggestions

Upvotes: 1

Stephan
Stephan

Reputation: 56180

Explanation: file.logarithm matches the 8.3 short name file.log

Workaround: del file.log.

Upvotes: 2

Related Questions