trying to recursively search for files with a certain word in their file name using CMD (windows) -
i'm trying write script search file recursively in folder , run command and/or list of commands on each file. here's example of how need work:
- search folder files containing "1080p" in file name
- copy file local directory but remove "1080p" filename
- run batch script on files (i have part working)
all needs automated.
i need in windows command prompt , i'm willing use other programs required.
i'm using sed in similar batch script.
@echo off setlocal disabledelayedexpansion set "src=sourcepath" set "dst=destinationpath" set "search=1080p" /r "%src%" %%f in (*%search%*) ( set "full=%%~ff" set "name=%%~nxf" setlocal enabledelayedexpansion copy "!full!" "%dst%\!name:%search%=!" endlocal ) rem call batch script here process copied files you have problems if same filename exists in multiple source folders. general problem stated requirements.
explanation:
%%~ff gives full path file contained in %%f
$$~nxf gives name , extension of file contained in %%f
type help for or for /? more information modifiers available for variable expansion.
!name:%search%=! uses delayed expansion search contents of name , replace search value nothing. in example %search%=1080p. note search not case sensitive.
i need use delayed expansion when doing search , replace within loop because normal expansion using percents occurs when statement parsed. entire construct, encluding contents of parentheses, parsed 1 logical statement. normal expansion give value of name prior loop executing. won't work :-) delayed expansion gives current value each time line executed.
type help set or set /? more information search , replace , delayed expansion.
i need toggle delayed expansion on , off because ! valid character in filename, , %%f expansion corrupt value if contains !.
Comments
Post a Comment