VBS如何为连接的USB闪存驱动器生成连续的字母

时间:2016-08-10 16:13:32

标签: vbscript usb usb-flash-drive

我有以下问题。我连接到Windows 12 USB闪存驱动器和12端口集线器。我正在编写一个脚本,用户可以双击它,将特定文件夹中的所有文件下载到桌面上创建的文件夹中。为了使它通用我让用户输入他的Windows用户名和Windows分区字母。然后(此刻)我要求用户逐个输入所有12个字母,这些字母非常粗糙。我想这样做,以便用户只需输入驱动器的第一个字母,然后自动为剩余的11个驱动器生成字母,因为总是这样的情况下,驱动器安装时具有正确的字母顺序,具体取决于第一个。

正如在代码中可以看到的那样,我尝试将其转换为ascii,而不是回到字符,但它不起作用,我找不到任何我能理解或实现的内容。

我希望这很清楚,并提前感谢您的帮助!

这是代码(当我尝试进行ascii转换时):

DIM fso
Set fso=CreateObject("Scripting.FilesystemObject")
On Error Resume Next   

Set oDrive = fso.Drives

username = InputBox("Enter winows user name")
wl = Inputbox("Enter Your windows partition drive letter")


l0 = Inputbox("Enter Your 1st camera drive letter")
'l1 = Inputbox("Enter Your 2nd camera drive letter")
'l2 = Inputbox("Enter Your 3rd camera drive letter")
'l3 = Inputbox("Enter Your 4th camera drive letter")
'l4 = Inputbox("Enter Your 5th camera drive letter")
'l5 = Inputbox("Enter Your 6th camera drive letter")
'l6 = Inputbox("Enter Your 7th camera drive letter")
'l7 = Inputbox("Enter Your 8th camera drive letter")
'l8 = Inputbox("Enter Your 9th camera drive letter")
'l9 = Inputbox("Enter Your 10th camera drive letter")
'l10 = Inputbox("Enter Your 11th camera drive letter")
'l11 = Inputbox("Enter Your 12th camera drive letter")


fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam0"
fso.CopyFile ""& l0 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam0\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam1"
'fso.CopyFile ""& l1 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam1\"
fso.CopyFile "Chr(Asc('"& l0 &"') + 1):\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam1\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam2"
fso.CopyFile ""& l2 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam2\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam3"
fso.CopyFile ""& l3 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam3\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam4"
fso.CopyFile ""& l4 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam4\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam5"
fso.CopyFile ""& l5 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam5\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam6"
fso.CopyFile ""& l6 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam6\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam7"
fso.CopyFile ""& l7 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam7\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam8"
fso.CopyFile ""& l8 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam8\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam9"
fso.CopyFile ""& l9 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam9\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam10"
fso.CopyFile ""& l10 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam10\"

fso.CreateFolder ""& wl &":\Users\"& username &"\Desktop\recording\cam11"
fso.CopyFile ""& l11 &":\DCIM\100HDDVR\*.*", ""& wl &":\Users\"& username &"\Desktop\recording\cam11\"


Wscript.Echo "File copy complete."

1 个答案:

答案 0 :(得分:1)

使用Asc() / Chr()在数字和字符之间进行转换。确保在Z'停止。如:

>> Function min(a, b) : If a <= b Then : min = a : Else : min = b : End If : End Function
>> For Each d In Split("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")
>>     a = Asc(d)
>>     WScript.Stdout.Write d & " " & a & ":"
>>     For i = a To min(Asc("Z"), a + 11)
>>         WScript.Stdout.Write " " & Chr(i)
>>     Next
>>     WScript.Stdout.WriteLine
>> Next
>>
A 65: A B C D E F G H I J K L
B 66: B C D E F G H I J K L M
C 67: C D E F G H I J K L M N
D 68: D E F G H I J K L M N O
E 69: E F G H I J K L M N O P
F 70: F G H I J K L M N O P Q
G 71: G H I J K L M N O P Q R
H 72: H I J K L M N O P Q R S
I 73: I J K L M N O P Q R S T
J 74: J K L M N O P Q R S T U
K 75: K L M N O P Q R S T U V
L 76: L M N O P Q R S T U V W
M 77: M N O P Q R S T U V W X
N 78: N O P Q R S T U V W X Y
O 79: O P Q R S T U V W X Y Z
P 80: P Q R S T U V W X Y Z
Q 81: Q R S T U V W X Y Z
R 82: R S T U V W X Y Z
S 83: S T U V W X Y Z
T 84: T U V W X Y Z
U 85: U V W X Y Z
V 86: V W X Y Z
W 87: W X Y Z
X 88: X Y Z
Y 89: Y Z
Z 90: Z
>>