I was trying to copy a file to every sub directory in a directory that had an *.inf file in it. This proved to be more complicated than it should be when I needed to factor in UNC paths as well as a drive mapping. Here's the cmd file I ended up with.
cls
@echo off
:findmodel
cls
echo.
echo.
set /P model=[What is the model of the device you are using?]
echo.@echo off
:findmodel
cls
echo.
echo.
set /P model=[What is the model of the device you are using?]
echo.
set /P directory=[What directory are you searching?]
echo.
echo.
echo.
echo You are about to copy %model%.txt to all directories in:
echo %directory%
echo that contain an inf file.
echo.
set /P ready=[Are you ready to proceed? (y/n)]
if /i %ready%==y goto proceed
if /i %ready%==n goto findmodel
goto end
:proceed
for /F "delims=+ tokens=*" %%a in ('dir /AD /s /b "%directory%"') do (
rem for /F %%a in ('dir /AD /s /b "%directory%"') do (
if exist "%%a\*.inf" (
echo %model% > "%%a\%model%.txt"
))
echo %model%> "%directory%\%model%.txt"
:end
Echo File copy should be complete.
pause
No comments:
Post a Comment