Batch file to mklink directory to multiple folders?

fluffyxkitty

Distinguished
May 26, 2011
8
0
18,510
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?
 
Solution


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...

rusabus

Distinguished
May 19, 2007
191
0
18,760


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:

[cpp]
@echo off
for /f %%i in (input.txt) do (
mklink /j "%%i" "C:\test"
)
pause
[/cpp]

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
 
Solution