How do I re-use my wildcard match?

2019-09-08 05:41发布

问题:

There's some advanced file moving that needs to be done with the Windows command prompt; Is it possible to do it with wildcards?

Using regular expressions in UNIX, I could do something like this to find all files that begin with "s" and then do something else with them (echo).

ls s(.*) ; echo Found file \1 , needs to be moved to C:\unicorns\(\1)

I want to do something like that in Windows command prompt:

:: find all files that begin with "s" and then do something else with them (echo)
dir s(*) ; echo Found file \1

回答1:

Do something like this:

for %%f in (*) do (echo %%f)

This will echo a list of files found in current directory. Find more description here