Solved

Batch file to mklink directory to multiple folders?

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?
3 answers Last reply Best Answer
More about batch file mklink directory multiple folders
  1. Best answer
    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:

    [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
  2. Your example was a great help and it ended up working beautifully for what I wanted, thank you!
  3. Best answer selected by fluffyxkitty.
Ask a new question

Read More

Windows 7