【问题标题】:Translating batch to script (Windows)将批处理转换为脚本 (Windows)
【发布时间】:2015-03-30 03:59:58
【问题描述】:

对脚本完全陌生,试图将一段批处理脚本翻译成脚本。

批零件有注释。我正在尝试将目录中单独的所有文件上移一个目录,删除空目录。

任何帮助将不胜感激。

这是我的代码:

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

【问题讨论】:

    标签: windows batch-file vbscript


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      相关资源
      最近更新 更多