How to store the result of a command expression in a variable using bat scripts?

前端 未结 5 1977
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 23:10

I have the command below to count all directories that that follow the pattern 20?????? :

\'dir /b \"20??????\" | find /c \"2\"\'
5条回答
  •  既然无缘
    2020-12-02 23:42

    (dir /b "20??????" | find /c "2")>>x.txt  
    set /p variable=

    That's all.

    Of course, if you don't want the file, just do this afterwards:

    del x.txt
    

    EDIT -- How to make the filename unique:

    @Mai: use this to create a uniqe file name:

    set timestamp=%date:.=%%time::=%
    set timestamp=%timestamp:,=%
    set timestamp=%timestamp:/=%
    set timestamp=%timestamp:-=%
    set filename=file%timestamp%.tmp
    

    Add more replacements if the date format of your system culture has other characters inside

提交回复
热议问题