将批处理翻译成脚本(Windows)

时间:2015-03-30 03:59:59

标签: windows batch-file vbscript

完全不熟悉脚本,试图将一段批处理脚本翻译成脚本。

评论批次部件。我试图将目录中单独的所有文件移到一个目录中,删除空目录。

任何帮助将不胜感激。

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

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