i need to copy test.swf to all subfolders of c:/test folder's that doesn't contain "git" word
just tried something like that but not worked
@setlocal enableextensions enabledelayedexpansion
@echo off
for /r %%a in (.) do
(
if not x%a:git=%==x%a% do
(
@copy "C:\test.swf" %a > nul
)
)
endlocal
There is certainly nothing wrong with using vbscript :-) (see OP's answer)
But I thought I would point out where your batch code went wrong.
.
will include the parent directory. You want*
instead to get just the children.C:\test\_git_\test
should get the file because the folder name does not contain "git" (though the parent does). Your code would look for git anywhere in the path.Additional points for improvement, though not errors:
@echo off
at the top then prefix each command with@
.Here is the correct code for your algorithm. (actually none of the code solutions below have been tested, but I think I got them correct)
The above usually works. But it fails if a folder name contain
!
because delayed expansion would corrupt the expansion of %%F. The solution is to toggle delayed expansion on and off within the loop.But there is a much simpler method. You can pipe the results of DIR to FINDSTR with a regex that will filter out folders with "git" in the name. Then use FOR /F to process the results.
Edit - I simplified the regex.
The entire process can be done on one line from the command line
just did it by vbscript