[英]Translating batch to script (Windows)
totally new to scripting, trying to translate a piece of batch script to go into a script. 脚本编写完全陌生,它试图将一个批处理脚本翻译成一个脚本。
The batch parts are commented. 批处理零件已注释。 I am trying to move all files that are alone in a directory up one directory, deleting the empty directory.
我试图将一个目录中所有单独的文件上移一个目录,删除空目录。
Any help will be appreciated. 任何帮助将不胜感激。
Here's my code: 这是我的代码:
strDir = "j:\"
set FSO = createobject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
getInfo objDir
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.SubFolders
getInfo aItem
Next
if pCurrentDir.Files.Count = 1 then
if pCurrentDir.Subfolders.Count = 0 then
' Move all files inside the subdirectory up one level.
move /s %%d\*.* %%d\..\.
' Delete the directory
RD /y %%d
end if
end if
End Sub
strDir = "j:\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
getInfo objDir
Sub getInfo(pCurrentDir)
WScript.Echo pCurrentDir
For Each aItem In pCurrentDir.SubFolders
getInfo aItem
Next
If pCurrentDir.Files.Count = 1 Then
If pCurrentDir.Subfolders.Count = 0 Then
' Move all files inside the subdirectory up one level.
For Each f In FSO.GetFolder(pCurrentDir).Files
f.Move f.ParentFolder.ParentFolder & "\"
Next
' Delete the directory
FSO.DeleteFolder pCurrentDir,True
End If
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.