cmd - Windows delete with wildcards deleting erratically -


this driving me crazy. basically, have program outputs tables flat file multiple databases same structure. these files named in format tablename_####.dat, #### 4 digit company number. after these created, program combines of files tablename, , adds timestamp on end. so, final file name in format tablename_yyyymmdd_hhmmss.dat. finally, want delete of individual .dat files, leaving combined, time stamped files.

this works fine of tables, except table vex. example, have files:

vex_1234.dat vex_5678.dat vex_0987.dat 

which combine form vex_20150414_144352.dat. after this, run command:

`del *_????.dat` 

this deletes of tables' individual files (v_1234.dat, pat_9534.dat, etc.), while leaving combined files (v_20150414_142311.dat, pat_20150413_132113.dat) ...except vex. deletes both individual files , combined file. shouldn't delete files end underscore, 4 characters, , ".dat"?

i know has simple i'm missing. going on?

most issue caused short 8.3 file names.

the ? wildcard can match 0 or 1 character if precedes dot. file mask of *_????.dat match name has number of characters, followed _, followed 0 4 characters, followed .dat extension. tricky thing attempt match both long file name, and short 8.3 name, if exists.

try issuing dir /x *.dat, , @ short name of problem file. suspect match file mask.

there patterns how short names derived, there no way predict short name of given file unless aware of existing short names within folder, , relying on undocumented behavior.

this common problem. if files on ntfs drive , have admin rights, can disable short file name generation. not remove existing short names.

the best general solution pipe dir /b through findstr remove unwanted files, , process result /f delete each file individually. findstr below exclude file names contain 2 or more _ characters.

for /f "delims=" %%f in ('dir /b *.dat^|findstr /v "_.*_"') del "%%f" 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -