i want make .bat files can allow me delete file if string of characters appears inside. example, if want delete files have string harp inside of , files in folder are:
harp1.txt mellowharp.txt highharplow.txt i want able delete of these files. figured out how if starts or ends string, merely writing
del harp*.* del *harp.* but can't figure out how if harp found in middle of string.
i've tried things putting asterisk on each side of harp catch case, doesn't work.
this literally first day , experience .bat files, , appreciate on this, please gentle , explain because i'm coming no knowledge whatsoever.
well, since using del *harp*.* didn't work you, iterate through files in specified directory delete when substring "harp" found in file name.
this should it:
@echo off /f %%f in ('dir /b * ^| find /i "harp"') del %%f echo files deleted... pause>nul exit make sure .bat file in same directory other files.
explanation:
the
forcommand loops through files in directory , assigns them variable%%f, searches substring "harp" in file name. then, when found,do del %%ftells program delete file (%%f). read moreforstatements here.the
echocommand prints line of text console window. read moreechoclick here.the
pause>nulpauses program , waits user press key, without text being displayed on screen. (the normal text appear press key continue...). morepausehere.the exit command stops program. more on
exithere.
Comments
Post a Comment