Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can i use WSH to execute all .exe files of a directory?

    i need to do some clientside work on a windowsmachine, that basivcally involves:

    - starting a script each month (--> sheduled task, no problem);
    - the script needs to create a new directory, that contains the current year as subdirectory, and the current month as subdirectory of te yeardirectory. (example k:\...\outputs\y_2004\m_01\ ) (--> with WSH, using the FSO,Create Folder)
    - the script needs to execute all executables (40 or so) that are in a specific directory (--> How ? I can loop through the directory and check the fileextension, but how do i actually run the executables?)
    - the outputfiles that are create by the executables need to be moved to the new directory. (-->with WSH, using the FSO, MoveFile)

    I am thinking to do this with WSH (VBscript) but i'm not sure if that realy is the way to go. I am also a bit unclear how i can execute the found .exe files + if and how long the script then waits until the file is executed (can take several minutes)

    Anyone done such tasks or has experience with WSH?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    *this message will self destruct in n-seconds*

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ha, thanks. That first link is exactly what i needed.

    Looks like WSH will be the way to go. (Unless someone knows a better alternative ...)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If the machine has the .NET framework loaded (and most do these days) you can write a full .NET program. Maybe not necessary but you should keep it in mind as an option.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could also use a good old-fashioned batch file to do a job like that. http://www.robvanderwoude.com/

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Roy Sinclair
    If the machine has the .NET framework loaded (and most do these days) you can write a full .NET program. Maybe not necessary but you should keep it in mind as an option.
    That could be an option, but like you said, it's kinda overkill for this rather simple task + i'm not realy planning to do much .NET work in the immediate future so i'm not realy keen on investing time in it now.
    WSH with VBscript is then kinda like the Classical ASP, where i'm quite experience with.
    Quote Originally Posted by aman
    You could also use a good old-fashioned batch file to do a job like that. http://www.robvanderwoude.com/
    Hmm.
    That was my first idea, but i don't know how to:
    - use the date (or just the current year) as name of a directory;
    - create a loop to run some commands for each .exe file in a specific directory
    and i nowhere found info on these two (i also didn't see it in the link you posted, so maybe it can't be done ...)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Quote Originally Posted by raf
    but i don't know how to:
    - use the date (or just the current year) as name of a directory;
    the next command in a cmd file gives you the year as a variable, so use md to make a forlder with this name:
    Code:
    For /f "tokens=3 delims=-" %%a in ('Date/t')  do set CURYEAR=%%a
    perhaps you have to set the "3" inhere to another number to get the right part from the string which the Date command returns

    very useful for other purposes too
    I am the luckiest man in the world

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, thanks for that.

    So this means i'd only need to be able to
    "create a loop to run some commands for each .exe file in a specific directory"

    So some sort of find that returns a collection i can loop through
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Quote Originally Posted by raf
    So this means i'd only need to be able to
    "create a loop to run some commands for each .exe file in a specific directory"

    So some sort of find that returns a collection i can loop through
    that is easy, run this command in a cmd file in the folder where the exe's are:
    Code:
    for %%a in (*.exe) do %%a
    or even from another folder:
    Code:
    for %%a in (dir thepathtoyourdir\*.exe) do %%a
    a bit more info from the date than previous post:
    Code:
    For /f "tokens=1 delims=- " %%a in ('Date/t')  do set CURDAY=%%a
    For /f "tokens=2 delims=- " %%a in ('Date/t')  do set CURDATE=%%a
    For /f "tokens=3 delims=- " %%a in ('Date/t')  do set CURMONTH=%%a
    For /f "tokens=4 delims=- " %%a in ('Date/t')  do set CURYEAR=%%a
    gives all date components (day, date, month, year) in variables, ready for use as you wish

    some explanation:
    the date/t command returns a string, with the /f combined with tokens and delim it is splitted based on the delim characters (in this case dash and space) the index number after token, says which part to take and put it in the variable
    Last edited by Roelf; 10-29-2004 at 08:25 PM.
    I am the luckiest man in the world

  • #10
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that is great. I never knew you could do that in a batchfile.
    it's actually gonna be real easy to do it like that.


    Thanks all !
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just a quick note: those more powerful BAT file capabilities are not available on Windows 9x or ME machines. They came from the Windows NT side of the house so think in terms of NT, 2K, XP and Server 2003 as the platforms where that will work. But it's cool that Roelf added them to the discussion since I wrote and sold an article about them some time around 1996 to a magazine in the UK.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #12
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Roy Sinclair
    Just a quick note: those more powerful BAT file capabilities are not available on Windows 9x or ME machines. They came from the Windows NT side of the house so think in terms of NT, 2K, XP and Server 2003 as the platforms where that will work.
    I see. That's why i never seen it (stopped writing batchfiles a while ago). The script will run on NT so i should be ok there.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •