Search for files in a batch script and process those files?

前端 未结 6 387
萌比男神i
萌比男神i 2021-02-04 11:38

I\'m trying to do some things during the pre-build phase of a visual studio project. Specifically, I\'m trying to execute some commands on all *.resx files within the project.

相关标签:
6条回答
  • 2021-02-04 11:52

    You can use findutils for Windows - it includes both "find" and "xargs"

    0 讨论(0)
  • 2021-02-04 11:54

    You could also install cygwin to get a full-blown Unix-esque shell, which comes with the trusty old "find" command, plus a bunch of other tools. For example,

    find . -name "*.resx" | xargs grep MyProjectName
    
    0 讨论(0)
  • 2021-02-04 12:06

    You are running into inadvertant use of the default space delimeter. You can fix that by resetting the delims like so:

    for /f "delims=" %%a in ('dir /B /S *.resx') do echo "%%a"
    
    0 讨论(0)
  • 2021-02-04 12:11

    To generate a simple file list of all the relevant files for later processing

    @echo create a results file…
    if exist results.txt (del results.txt)
    echo. >NUL 2>results.txt
    
    @echo minimal recursive subdirectory search for filespec...
    dir /s /a /b "*.resx" >>results.txt
    
    0 讨论(0)
  • 2021-02-04 12:15

    Stick with the For text parser of the shell

    for /f "delims=|" %%a in ('dir /B /S *.resx') do echo "%%a"
    

    just add a delims option (for a delim character which obviously couldn't exist), et voila!

    In the absense of this delims option, /f will do what it is supposed to, i.e. parse the input by splitting it at every space or tabs sequence.

    0 讨论(0)
  • 2021-02-04 12:17

    You know that for can also run recursively over directories?

    for /r %%x in (*.resx) do echo "%%x"
    

    Much easier than fiddling with delimiters and saves you from running dir.

    0 讨论(0)
提交回复
热议问题