Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was browsing many threads like this but I didnt found any specific that would help, so this is my problem I have this :

echo START %USERNAME% > exec3.txt & dir c: /B /S | find ".exe" >> exec3.txt & echo STOP %username% >> exec3.txt

And I need output in this exec.txt file that username and .exe path are on same line not above and under.

I am still novice in this so please if you can help me thank you.

Edit: Ok so what I currently get from this code is this:

START remak  


Remak is username, and I need that REMAK will be on same line as path like this:

REMAK C:\05b7ba810261bb83a30acb4b8289\Setup.exe
share|improve this question
I'm not too sure what you are asking, could you provide an example of what the text file should look like? – Bob May 23 '12 at 8:26
I think he wants output something like "start username exe file stop username" on one line, possibly with &s between. a better statement of the goal would be nice. – user114037 May 23 '12 at 8:28
up vote 0 down vote accepted
::This is a comment

::Stops the console window from being spammed (and therefore speeds things up a bit)
@echo off

type NUL > exec.txt

::Loop through each line outputted by the command 'dir /b /s C:\*.exe'
::The echo command is executed once for each loop iteration
::This can take a very long time, depending on how big your C: partition is
for /f "tokens=*" %%a in ('dir /b /s C:\*.exe') do (
    echo START %USERNAME% %%a STOP %USERNAME%>>exec.txt
share|improve this answer
Just my dumb question whats %%a. – Ondrej May 23 '12 at 8:57
It's part of the for command. When run from a batch file, it's %%a. When run from the prompt directly, it's %a. The letter can be anything. Since there's the tokens=*, %%a contains the entire line from the command each iteration, including spaces. Normally it delimits, e.g. by spaces, so C:\Program Files` might have %%a = C:\Program` %%b = Files`. See for /?`, and specifically – Bob May 23 '12 at 9:01
Thank you sir! :) – Ondrej May 23 '12 at 9:03
Ok its working, solved thank you very much I just deleted one % since I dont run it from batch file :) – Ondrej May 23 '12 at 9:10
If it worked for you, please mark this answer as accepted by clicking the arrow to the left. – Bob May 23 '12 at 9:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .