对于循环在CMD ...如何循环A到Z(驱动器字母) [英] For loop in CMD... how to loop A to Z (for drive letters)
本文介绍了对于循环在CMD ...如何循环A到Z(驱动器字母)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Windows命令行(cmd.exe)中使用for循环驱动有效的驱动器号从A到Z?
驱动器根文件夹中的所有文件应该是(概念):
f:\
或近似现有功能:
for / L in(A,Z,1)do echo%f:\
解决方案
for %% p in(ABCDEFGHIJKLMNOPQRSTU VWXYZ)如果不存在,则为do%p :\\\
ul set FREEDRIVELETTER = %% p
编辑:这里是一个PowerShell方式,不知道if
65..90 | foreach {[char] $ _; Write-HostDo Something}
/ p>
97..122 | foreach {[char] $ _; Write-HostDo Something}
批处理文件。
@ECHO OFF
start / b / wait powershell.exe97..122 | foreach {$ a = [char] $ _; dir $ a:\}
PAUSE
How can I get drive the valid drive letters from A to Z with the "for loop" in windows command line (cmd.exe)?
Example, list all files in a drive root folder, should be something like (conceptual):
for %f in (A..Z) do dir %f:\
or aproximating existing functionality:
for /L in (A, Z, 1) do echo %f:\
解决方案
Close, but it's more like this.
for %%p in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if not exist %%p:\nul set FREEDRIVELETTER=%%p
EDIT: Here is a powershell way, not sure if off-topic for your needs
Loops the Upper Case Alphabet
65..90 | foreach {[char]$_;Write-Host "Do Something"}
or Lower Case Alphabet
97..122 | foreach {[char]$_;Write-Host "Do Something"}
Maybe this will work from a batch file.
@ECHO OFF
start /b /wait powershell.exe "97..122 | foreach {$a=[char]$_ ;dir $a:\}"
PAUSE
这篇关于对于循环在CMD ...如何循环A到Z(驱动器字母)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文