Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

help with windows vbscript code

  • 27-04-2004 12:56PM
    #1
    Closed Accounts Posts: 333 ✭✭


    I have written a small script that copies a file (or number of files) from a folder to two different locations and then deletes the original. The problem is that it works fine when I hardcode in the actual filename, but it will not work when I try to use a wildcard filename (e.g. "*.pdf"). I need to use the wildcard because at runtime, I will not know the filename because they are randomly generated. Any ideas??

    ' VBScript.
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")

    ' make sure the files exist before copying them
    if FSO.FileExists("*.pdf") then
    FSO.CopyFile "*.pdf", "FolderA"
    FSO.CopyFile "*.pdf", "FolderB"
    end if

    ' make sure the files exist before deleting them
    if FSO.FileExists("*.pdf") then
    FSO.DeleteFile "*.pdf"
    end if

    ' destroy object
    set FSO = nothing


    If I substitute an actual filename (e.g. "Sample1.pdf") for ("*.pdf") in the above code, it works fine.


Comments

  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    its doesn't work because you are looking for a file called
    *.pdf
    you need to have some way to search the directory structure checking if the file is pdf and then what you need to


  • Closed Accounts Posts: 333 ✭✭McGintyMcGoo


    Cant believe I have been so stupid!
    I wrote a 3 line batch file and set that to run in scheduler!

    Thanks anyway!


Advertisement