Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a symbolic link using a batch script in windows?

I am currently using the following script to copy all files with a certain prefix to a target directory:

for /f "delims==" %%k in ('dir "d:\Search Path\File Prefix*.*" /s /b') do copy "%%k" "d:\Target Directory\"

This works fine but I would like to instead create a symlink to the files incase of any file changes. Please can someone advise how I could do this?

Many Thanks

like image 796
user3405604 Avatar asked Mar 11 '14 10:03

user3405604


People also ask

How to create a symbolic link to a file in Windows?

The syntax for creating a symbolic link to a files is as follows. For example, to create a symbolic link from user’s Desktop folder to “C:\Program Files (x86)\Microsoft Office Communicator\communicator.exe”, the command is In the above command communicatorLink.exe is the name of the symbolic link.

How to create a symbolic link to a directory in PowerShell?

Tutorial Powershell - Creating a symbolic link As an Administrator, start an elevated Powershell command-line. Create a symbolic link to a directory. New-Item -ItemType SymbolicLink -Path "C:LINK" -Target "C:SOURCE"

How do I create a symlink in command prompt?

Create Symbolic Links Using Command Prompt. Creating symlinks in Windows is pretty easy with mklink command. To start, press “Win + X,” and then select the option “Command Prompt (Admin)” to open the Command Prompt with admin rights. Once the command prompt has been opened, use the below command format to create a symlink for a file.

What are symbolic links in Linux?

What Are Symbolic Links? Symbolic links are basically advanced shortcuts. Create a symbolic link to an individual file or folder, and that link will appear to be the same as the file or folder to Windows—even though it’s just a link pointing at the file or folder. For example, let’s say you have a program that needs its files at C:Program.


1 Answers

You utilise the mklink command:

for /f "delims==" %%k in ('dir "d:\Search Path\File Prefix*.*" /s /b') do (
mklink "d:\Target Directory\" "%%~k"
)

And that should solve your problem. mklink /? for more info.

Mona.

like image 98
Monacraft Avatar answered Oct 09 '22 15:10

Monacraft