Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Move Files Based On File Name

$
0
0
Hopefully someone can assist me in trying to script the ffollowing.

I have a directory which is populated with files in the following format

EUN_XXXXXX_FULL.zip
EUN_XXXXXX_DELTA.zip

XXXXX is a number which increases with each file that is created. I need a method to move the files older than the last full to another folder, have tried to explain what I meant below.

EUN_XXXXXX_FULL.zip
EUN_XXXXXX_DELTA.zip
EUN_XXXXXX_DELTA.zip
EUN_XXXXXX_DELTA.zip
EUN_XXXXXX_FULL.zip - Deleted
EUN_XXXXXX_DELTA.zip - Deleted
EUN_XXXXXX_DELTA.zip - Deleted
EUN_XXXXXX_DELTA.zip - Deleted

So far have the following, but not sure how to search the files and delete the files after the 2nd FULL file.

Code:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\MDS'} Where " _
        & "ResultClass = CIM_DataFile")

Set objRegEx = CreateObject("VBScript.RegExp")

For Each objFile in colFiles
    objRegEx.Global = True 
    objRegEx.Pattern = "\d{6}"

    strSearchString = objFile.FileName
    Set colMatches = objRegEx.Execute(strSearchString)

    strFile = colMatches(0).Value


Next

Any suggestions?

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>