Sign in with
Sign up | Sign in
Your question
Solved

Batch file to mklink directory to multiple folders?

Tags:
Last response: in Windows 7
Share
September 17, 2012 4:29:14 AM

Hello!

I'm interested in creating a batch file that will mklink the same directory to multiple exit directories, but it's tedious to type out the separate folder names. Is there a way to reference a list of names for the folders instead?

For example:

The tedious method-
mklink /j "B:\apple" "C:\test"
mklink /j "B:\orange" "C:\test"
mklink /j "B:\banana" "C:\test"

Is there a way to simplify this down to something like:

mklink /j "B:\foldername" "C:\test"

Then foldername will automatically be replaced by possible folder names from a list?

Best solution

September 17, 2012 4:45:28 AM

fluffyxkitty said:
Hello!

I'm interested in creating a batch file that will mklink the same directory to multiple exit directories, but it's tedious to type out the separate folder names. Is there a way to reference a list of names for the folders instead?

For example:

The tedious method-
mklink /j "B:\apple" "C:\test"
mklink /j "B:\orange" "C:\test"
mklink /j "B:\banana" "C:\test"

Is there a way to simplify this down to something like:

mklink /j "B:\foldername" "C:\test"

Then foldername will automatically be replaced by possible folder names from a list?


You should really look at the "for" command in batch files. The for command can read input from a file or read the output from other commands and act on that output. As an example, you could use the following to read data from a text file called "input.txt" and run your command on the data read from each line:

  1. @echo off
  2. for /f %%i in (input.txt) do (
  3. mklink /j "%%i" "C:\test"
  4. )
  5. pause


This can get much more complicated, but the above will get you started. Let me know if you run into a specific problem with the above example and I'll see if I can help. I'd suggest reading through the output of for /? several times.

--Russel
Share
September 17, 2012 5:07:03 AM

Your example was a great help and it ended up working beautifully for what I wanted, thank you!
m
0
l
September 17, 2012 5:07:03 AM

Best answer selected by fluffyxkitty.
m
0
l
!