且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VBScript 移动具有特定扩展名的文件

更新时间:2022-06-03 22:29:45

一些注意事项:

Sub listfolders(startfolder)
Dim fs 
Dim fl1 
Dim fl2 

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set fl1 = fs.GetFolder(startfolder)

    For Each fl2 In fl1.SubFolders
        Debug.Print fl2.Path

        ''process the files
        ProcessFiles fl2.Path 

        'Recursion: lists folders for each subfolder
        listfolders fl2.Path
    Next
End Sub

''Code copied from question
Sub ProcessFiles(sPath)
    ' Scan each file in the folder
    For Each sFile In oFSO.GetFolder(sPath).Files
        ' check if the file name contains TV Show Parameters
        If InStr(1, sFile.Name, "hdtv", 1) OR InStr(1, sFile.Name, "s0", 1) <> 0 Then
            ' TV Show Detected - Move File
            objLog.WriteLine Now() & " - " _
                  & sFile.Name & " Detected as TV Show - Moving to " & sTV
            oFSO.MoveFile sTorrents & sFile.Name, sTV & sFile.Name
        ' Move all other Files to Movies Directory
        Else 
            objLog.WriteLine Now() & " - " _
            & sFile.Name & " Detected as Movie - Moving to " & sMovie
            oFSO.MoveFile sTorrents & sFile.Name, sMovie & sFile.Name
        End If
    Next
End Sub