Files with long extensions unexpectedly deleted using the command line

I am trying to delete some files using a batch file .. (winxp)

My problem is that I delete with a wildcard. It matches the name 8.3, as well as the long name.

for example: file list

file1.py
file1.pyc
file2.pycstlongname
file2.pycstlongnamec

if i do

Del *.pyc

deletes everything except file1.py

becuase, if I do dir / X, all of the 8.3 short names end in .PYC

+3
source share
2 answers

When you perform file management using wildcards from the command line, files with long extensions may be unexpectedly displayed, copied, or deleted.

, , Windows XP SP3.

Microsoft Knowledge Base, , . Windows NT 4.0:

: 164351 - :: 1 2006 . - : 1.1

http://support.microsoft.com/kb/164351

UPDATE: #, . , , .

+4

, , , forfiles:

> forfiles /m *.pyc
"file1.pyc"

cmd.

:

> for %i in (*) do @if %~xi==.pyc @echo %i
file1.pyc

, .3 .

,

forfiles /m *.pyc /c del @FILE

for %i in (*) do @if %~xi==.pyc @del "%i"

, , del *.pyc.

ETA:. - , , cmd Win XP SP 2:

S:\Temp>for %i in (file1.py,file1.pyc,file2.pycstlongname,file2.pycstlongnamec) do @copy nul %i
        1 Datei(en) kopiert.
        1 Datei(en) kopiert.
        1 Datei(en) kopiert.
        1 Datei(en) kopiert.

S:\Temp>dir /b
file1.py
file1.pyc
file2.pycstlongname
file2.pycstlongnamec

S:\Temp>del *.pyc

S:\Temp>dir /b
file1.py

S:\Temp>del *

S:\Temp>for %i in (file1.py,file1.pyc,file2.pycstlongname,file2.pycstlongnamec) do @copy nul %i
        1 Datei(en) kopiert.
        1 Datei(en) kopiert.
        1 Datei(en) kopiert.
        1 Datei(en) kopiert.

S:\Temp>for %i in (*) do @if %~xi==.pyc @del "%i"

S:\Temp>dir /b
file1.py
file2.pycstlongname
file2.pycstlongnamec

, , , .


, , :

for %i in (*) do @if %~xi==.pyc @del "%i"

. for %i in (*) . ; %~xi ( 8.3), :

if .py == .pyc del "file1.py"
if .pyc == .pyc del "file1.pyc"
if .pycstlongname == .pyc del "file2.pycstlongname"
if .pycstlongnamec == .pyc del "file2.pycstlongnamec"

, , , , cmd, 8.3. , .

forfiles Win 7 Vista . , , forfiles , cmd. Windows, . , UNIX-. , , .

, , forfiles , 8.3 . , , , .

+4

Source: https://habr.com/ru/post/1712232/


All Articles