| 1. |
Solve : Delete files - help? |
|
Answer» I have a files : I have never worked with the '?' but you could do this: It's works : Code: [Select]del ????-??-??-??-??-??.csv but i don't know why. Question mark DISLIKES minus marks .txt does not mean "txt files with exactly 3 characters in the name", it means "txt files with up to 3 characters in the filename". If you use 8 question marks, that means "everything" - ??.txt is the same as *.txt You can use FOR and a FINDSTR REGULAR expression Delete only csv files with exactly 19 characters in the filename. Note: there are 20 dots - 19 for the characters, then one dot + csv for the extension. for /f %%A in ('dir /b ^| findstr /R "^....................csv"') do del "%%A" Before: f:\data>dir /b 2013-10-28-11-43-56.csv 2013-10-28-11-43-56_data.csv After: f:\data>dir /b 2013-10-28-11-43-56_data.csvWithout testing - you'll find that dir and del also match the short filename, not only the long filename. This can lead to some surprises.Thanks Salmon.More robust version - can process & delete files with or without spaces in the name for /f "delims=" %%A in ('dir /b ^| findstr /R "^....................csv"') do del "%%A" Configurable - CHANGE extension and change number of characters @echo off setlocal enabledelayedexpansion set extension=.csv set chars=19 set regstring= for /l %%A in (1,1,%chars%) do set regstring=!regstring!. for /f "delims=" %%A in ('dir /b ^| findstr /R "^%regstring%%extension%"') do del "%%A" |
|