在当前目录,按照文件名称的前N个字符新建目录,并将文件名前N个字符相同的文件移动到相应新建的文件夹内,测试过多次,如果出现前N个字符相同的文件超过100个,则只移动100个文件,剩余的则不做处理,且cmd窗口也一直显示,请教大神,这该怎么处理?谢谢!- Dim p
- Dim sp
- Dim N
- Set dp = CreateObject("Scripting.Dictionary")
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set Directory = FSO.GetFolder(".")
- p=0
- N=inputbox("输入需要截取文件名的位数(左起)","提示!","",8000,4000)
- if N="" then
- WScript.Quit
- end if
- if (IsNumeric(N)=false) then
- msgbox "输入大于0的正整数"
- WScript.Quit
- end if
- if N<=0 then
- msgbox "输入大于0的正整数"
- WScript.Quit
- end if
- For Each FileName In Directory.Files
- if (right(FileName.Name,4)<>".vbs" ) and (right(FileName.Name,4)<>".bat") and (right(FileName.Name,4)<>".xls" ) and (right(FileName.Name,5)<>".xlsm") then
- sp=Left(FileName.Name,N)
- 'wscript.echo sp
- if not dp.Exists(sp) then
- dp.Add p,sp
- p=p+1
- 'msgbox p
- end if
- end if
- Next
- 'msgbox p & sp
- Set FileName = Nothing
- Set Directory = Nothing
- Set FSO = Nothing
- Set WshShell = CreateObject("WScript.Shell")
- for i=0 to p-1
- Set oExec = WshShell.Exec("cmd /c md "+dp(i)+" && move "+dp(i)+"*.* "+dp(i)+"\")
- Do While oExec.Status = 0
- WScript.Sleep 100
- Loop
- next
- Set WshShell = Nothing
- Set dp = Nothing
复制代码
|