Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have a list in a txt like this

AAA 1234561
BBB12 66698732
CCCCC 5878471
DD131 262554158

and and I have a Directory like the below


I want to create a txt file with a give name lets call it id.txt which contains the respective code for its folder

So the DirectoryA/AAA/id.txt contains 1234561
DirectoryA/BBB12/id.txt contains 66698732 and so on. 

I tried to extract the line with /p but it copies the whole line not just the ID.

share|improve this question
up vote 4 down vote accepted
for /f "tokens=1-2" %%A in (x.txt) do echo %%B > DirectoryA\%%A\id.txt


You can get a lot of useful information by typing FOR /? into a Command Prompt.  In particular,

FOR /F  ["options"]  %variable IN  (file-set)  DOcommand[command-parameters]

reads the file or files specified between the parentheses (the file-set) and parses each line out into tokens.  tokens=1-2 is the options string to say that you want the first and second words on each line.  %%A specifies that %%A is the variable that the first word will be read into; implicitly/automatically the second word goes into %%B.  Then the echo command gets executed with %%A and %%B set to the two words from the file.

Note: If you were typing this command directly into the Command Prompt, you would use %A and %B, but you have to use double percent signs when you do the same thing in a script (batch file).

share|improve this answer
Its working great can you please explain to me the tokens=1-2 and the whole thinking behind this command? thanks in advance – Sonamor Aug 16 '13 at 23:57
I hope I could rep you up Scott, thanks for the exlanation – Sonamor Aug 17 '13 at 0:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.