Solved sort exe's in a folder by oldest and execute each one by one

Dell Inspiron 11z notebook - customizabl...
March 17, 2014 at 06:26:05
Specs: Windows XP
I am creating a batch script to sort all the exe's in a network drive folder by oldest first and then execute them in that order. All the exe's all have the RPS prefix.

When I tried this in an actual prompt, it works without issue but it does work in a script, instead, it only excutes the most recent one.

Here's what I have if anyone can help.

for /f "delims=" %%a in (' " dir /od /b RPS*.exe" ') // this is assuming i am already in the right dir
do set oldest=%%a"
%%a // this line is what I am using to execute the oldest exe first.

For some reason, it doesn't work.

Any help or pointers will be greatly appreciated.




See More: sort exes in a folder by oldest and execute each one by one

Report •


✔ Best Answer
March 17, 2014 at 08:08:12
To avoid the message File not Found code the following

for /F "delims=" %%a in ('dir /od /a-d /b RPS*.exe') do start "" /W "%%a"


message



#1
March 17, 2014 at 06:49:20
for /F "delims=" %%a in ('dir /od /b RPS*.exe') do %%a

message edited by IVO


Report •

#2
March 17, 2014 at 07:50:20
This works. However I get a File Not Found after the output. The output looks like this

RPS1.exe
RPS2.exe
RPS3.exe
File Not Found

Thanks by the way. Is there anyway to pause between before executing the next exe. i.e. the for loop goes through, and the first RP1.exe gets execute, then the next one shouldn't start until the RP1.exe is done executing.?

message edited by xirsteon


Report •

#3
March 17, 2014 at 07:59:16

for /F "delims=" %%a in ('dir /od /b RPS*.exe') do start "" /W "%%a"

message edited by IVO


Report •

Related Solutions

#4
March 17, 2014 at 08:08:12
✔ Best Answer
To avoid the message File not Found code the following

for /F "delims=" %%a in ('dir /od /a-d /b RPS*.exe') do start "" /W "%%a"


message


Report •

#5
March 17, 2014 at 08:39:52
This works. Only thing is, each file gets execute twice in the following order:

RPS1.exe
RPS2.exe
RPS3.exe

RPS1.exe
RPS2.exe
RPS3.exe

I am not so sure why it's each file is executing twice. Do you know?

Thanks again IVO.

Update: I decided to echo out the output of the for look and I see why each file is running twice.

Here's what I did:

for F "delims=" %%a in ('dir P: /od /a-d /b RPS*.exe') do echo %%a

and the output is as follows:

C:\> echo.RPS1.exe
RPS1.exe

C:\> echo.RPS2.exe
RPS2.exe

C:\> echo.RPS3.exe
RPS3.exe

The 2nd line is in each output is the duplicate and that is probably why it's execute each exe twice. have you any idea how to get it to only execute once for each exe?


message edited by xirsteon


Report •

#6
March 17, 2014 at 08:47:43
Did you code *exactly* the one line statement I posted in #4 or is there anything else in your script?

Report •

#7
March 17, 2014 at 08:58:38
Here's all I have in the script


@echo off

REM -- Prepare the Command Processor

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set rps_update_path="path_to rps"

net use P: !rps_update_path!

for F "delims=" %%a in ('dir P: /od /a-d /b RPS*.exe') do echo %%a // without your modifications that uses start "" /w %%a

net use P: \delete

@echo.done


Note: If I just do dir /od /a-d /b rps*.exe from P: ,

it shows only:
RPS1.exe
RPS2.exe
RPS3.exe

And this is precisely what the output should be when executed from within the forloop.

message edited by xirsteon


Report •

#8
March 17, 2014 at 09:32:33
Ok I think I got it to work using same modification you made earlier. I use the line below:

for /f "delims=" %%a in ('dir /od /a-d /b RPS*') do echo. running %%a now & %%a

I simply just hit cancel on when each exe came up and i used task mgr to note which one to make sure it corresponds to what stdout "echo. running %%a" and it is same.

Thanks IVO. I really appreciate your help.


Report •


Ask Question