i had 4 files name cp1_26_09_2015.txt
, cp1_22_02_2015
, cp1_28_09_2015
, etc in same date format in 4 different subfolders of d:\drive
.
i wanted search file 1 one when using for
command list files in directory , subdirectory.
then lists out 4 names of text file in 4 different folders wanted path extracted 1 one perform operations 1 one on each file. till have constructed this:
setlocal enabledelayedexpansion setlocal set /a maxj=1 set /a j=1 set _t1=%date:.=% set _year=%_t1:~-4,4% set _month=%_t1:~-10,2% set _day=%_t1:~-7,2% cp1_26_09_2015.txt set _prefix=cp1 pause /f "usebackq tokens=*" %%i in (`dir /s /b d:\cp1*.txt`) ( if not "%%~nxi"==**%_prefix%_%_year%_%_month%_%_day%.txt** ( set xcount_!j!=%%~i set maxj=!j! set /a j+=1 ) ) set xcount set /a j-=1 @echo count of files : %j% pause
now problem here when try remove today's date file in search file name cp1_28_09_2015.txt
date variables in extension name provided in %_month%
, %_year%
, %_day%
not working, reporting syntax error.
make bat file , try :
@echo off /r "d:\" %%i in (*_26_09_2015.txt) call:test %%i echo done ! exit/b :test echo working on : %1 echo want %1
new edit :
try :
@echo off set "_year=%date:~6,4%" set "_month=%date:~3,2%" set "_day=%date:~0,2%" set "_prefix=cp1" /f "tokens=*" %%i in ('dir /s /b cp1*.txt') ( if /i not "%%~nxi"=="%_prefix%_%_day%_%_month%_%_year%.txt" ( call:next "%%~nxi") ) exit/b :next echo make : %1 echo don't have today date pause
Comments
Post a Comment