开发者

match all files in current directory

开发者 https://www.devze.com 2023-01-04 06:33 出处:网络
How do I achieve this in Windows using either Command-prompt or PowerShell? myprog * EDIT: I want to call myprog with each file in the current 开发者_运维问答directory as an argument.If your goal i

How do I achieve this in Windows using either Command-prompt or PowerShell?

myprog *

EDIT: I want to call myprog with each file in the current 开发者_运维问答directory as an argument.


If your goal is to call "myprog.exe" for each file in a directory, assuming that "myprog.exe" does not handle wildcards by itselef, it should be something like that in powershell :

dir | % {prog $_.FullName} 

Edit : taking your comment into account, try this :

prog (get-childItem -name)

Hope it helps...


I wrapped Cédric Rup's solution in a function ea (ExpandAll?). Not as clean as the Unix approach though.

function ea ($p="*") { dir $p | foreach { '"{0}" ' -f $_.Name } }

.\Myprog.exe (ea)
.\Myprog.exe (ea *)
.\Myprog.exe (ea *.txt)


In a .CMD or .BAT file:

SETLOCAL EnableDelayedExpansion
FOR %%f in (*) DO SET params=!params! "%%f"
CALL myprog %params%

The SETLOCAL EnableDelayedExpansion and !variable! syntax allow you to accumulate the results. (See this page for explanation and examples.)

Edit: Added quotes around the %%f, and changed the listing to be '*'... see comments below.


Do you mean the following construct in command shell (cmd.exe):

for %f IN (*.*) DO echo %f
0

精彩评论

暂无评论...
验证码 换一张
取 消