I have a folder structure like this:

  • c:/foo/bar1/a002345.vi
  • c:/foo/bar1/somefilename.vi
  • c:/foo/bar2/b005632.vi
  • ...
  • c:/foo/bar26/z002345.vi

Now I want to execute a batch file in the folder c:/foo/ which writes the following output to a .txt file:

@@/bar1/a002345.vi
@@/bar2/b005632.vi
@@/bar26/z002345.vi

(Without somefile.vi) What's the most elegant way to do this?

有帮助吗?

解决方案

Could you please specify how you will differentiate "somefile.vi", does it not contain any numbers, or do you know its individual name?

If it is the latter, I believe this should work if run from the C:\foo folder

for /r %%a in (*) do (if %%~na NEQ somefile echo %%~pa%%~na%%~xa >> output.txt)

Note instead of "@@\bar..." you will get "\foo\bar..." If there are multiple files you want to exclude simple nest more if commands:

for /r %%a in (*) do (if %%~na NEQ somefile1 if %%~na NEQ somefile2 if %%~na NEQ somefile3 echo %%~pa%%~na%%~xa >> output.txt)

And so on.... I've tried this on my computer and it worked fine.

Yours, Mona

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top