VBScript to move file with wildcard, if it exists

前端 未结 3 1541
感情败类
感情败类 2021-01-14 18:34

I am attempting to create a script that checks for the existence of archived eventlog files and, if any files exist, moves them to another folder. Running this script does n

3条回答
  •  时光取名叫无心
    2021-01-14 19:23

    You can replicate a wild card search by using a combination of instr() and right(), or just multiple instr().

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = "d:\eventlogs\"
    
    Set objFolder = objFSO.GetFolder(objStartFolder)
    
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
       if instr(objFile.Name,"Archive") <> 0 AND instr(objFile.Name,".evtx") <> 0 then
           objFSO.MoveFile objFile.Name, "archive\" + objFile.Name
       end if
    Next
    

提交回复
热议问题