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
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.
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"
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? 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With