如何使用其标签访问USB驱动器并使用CMD导航 [英] how to access a usb drive using its label and navigate with CMD

查看:52
本文介绍了如何使用其标签访问USB驱动器并使用CMD导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想知道是否可以使用其标签访问USB驱动器我可以使用PowerShell导航到驱动器,但我想知道如何在CMD中执行与此类似的操作

I would like to know if it's possible to access a usb drive using its label, for example I can navigate to the drive with PowerShell but I would like to know how to do something similar to this in CMD

$usbPath = Get-WMIObject Win32_Volume | ? { $_.Label -eq 'volumelabel' } | select name ; cd $usbPath.name 

推荐答案

加载 的问题,方法是使用 VOL 命令

For %G 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 @Vol %G: 2>NUL|%__AppDir__%find.exe /I "volumelabel">NUL&&CD /D %G:

@For %%G 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 @Vol %%G: 2>NUL | %__AppDir__%find.exe /I "volumelabel" >NUL && CD /D %%G:

您不仅可以检查每个可能的驱动器号,还可以使用 MountVol 将其减少为仅挂载的驱动器号:

Instead of just checking every possible drive letter, you could reduce that to only mounted drive letters by using MountVol:

来自的问题:

For /F "Delims=\ " %G In ('"%__AppDir__%mountvol.exe 2>NUL|%__AppDir__%find.exe ":\""') Do @Vol %%G 2>NUL|%__AppDir__%find.exe /I "volumelabel">NUL&&CD /D %%G

来自

@For /F "Delims=\ " %%G In ('"%__AppDir__%mountvol.exe 2>NUL|%__AppDir__%find.exe ":\""'
) Do @Vol %%G 2>NUL | %__AppDir__%find.exe /I "volumelabel" >NUL && CD /D %%G


如果您仍然想使用的问题,那么您已经足够了特权,然后使用 Path Win32_Volume (或其别名 Volume )……


If you still wanted to use wmi and you have sufficient privileges to use Path Win32_Volume, (or its alias Volume), with it then…

来自的问题:

For /F "Skip=1Tokens=2" %G In ('%__AppDir__%wbem\WMIC.exe Volume Where "Label='volumelabel'" Get DriveLetter^,Name 2^>NUL')Do @CD /D %G

然后从:

@For /F "Skip=1 Tokens=2" %G In (
    '%__AppDir__%wbem\WMIC.exe Volume Where "Label='volumelabel'" Get DriveLetter^,Name 2^>NUL'
) Do @CD /D %G

否则,您可以改用 Path Win32_LogicalDisk (或其别名 LogicalDisk )

Otherwise you could use Path Win32_LogicalDisk, (or its alias LogicalDisk) instead…

来自的问题:

For /F "Skip=1Tokens=2" %G In ('%__AppDir__%wbem\WMIC.exe LogicalDisk Where "VolumeName='volumelabel'" Get DeviceID^,Name 2^>NUL')Do @CD /D %G

然后从:

@For /F "Skip=1 Tokens=2" %%G In (
    '%__AppDir__%wbem\WMIC.exe LogicalDisk Where "VolumeName='volumelabel'" Get DeviceID^,Name 2^>NUL'
) Do @CD /D %%G

这篇关于如何使用其标签访问USB驱动器并使用CMD导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆