Create Soft and Hard Symbolic Links in Windows  

Page 2 of 9 FirstFirst 1234 ... LastLast

  1. Posts : 68,937
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #10

    apb said:
    Is there a way to create a file symbolic link in an existing directory, without specifying the file name? For example,

    mklink linkdir sourcefile

    does not work, because mklink considers you are trying to make the symbolic link called "linkdir" and linkdir already exists, and what is more it is a directory.

    It would be nice if the above syntax created a file symlink called "sourcefile" in the directory "linkdir". How to do that?


    (Note that I need to do this not once, but dozens of times for a whole list of files, so entering the filename manually is not an option.)

    It would be analogous to the command

    copy sourcefile linkdir

    Thanks.

    --peter
    Hello Peter,

    I'm afraid symbolic links can only be created for folders (aka: directories).

    If you wanted to create a symbolic link with a "-path link" that already exists, you could temporarily rename the existing folder so you can use the command to create the new link. Afterwards, move everything from the existing folder into the new linked folder, and delete the old existing folder.
      My Computers


  2. apb
    Posts : 94
    win 7 64bit
       #11

    I think you might be misunderstanding what I want, plus I don't really understand what you are saying.

    mklink symlink sourcefile

    as I understand it, does create a file-symlink called 'symlink', so I don't get what you mean.

    Also,

    mklink -D symlinkdir sourcedir

    creates a dir symlink.

    What I want to do is create file-symlinks in an existing other directory, to have the same name as the source files, analogously to

    copy sourcefile targetdir

    Is that what you are understanding me to mean? Because I do not understand your reply.

    Note that I am not expecting mklink to do that, since it apparently doesn't. But is there another way, other than a FOR loop?

    --peter
      My Computers


  3. Posts : 68,937
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #12

    apb said:
    I think you might be misunderstanding what I want, plus I don't really understand what you are saying.

    mklink symlink sourcefile

    as I understand it, does create a file-symlink called 'symlink', so I don't get what you mean.

    Also,

    mklink -D symlinkdir sourcedir

    creates a dir symlink.

    What I want to do is create file-symlinks in an existing other directory, to have the same name as the source files, analogously to

    copy sourcefile targetdir

    Is that what you are understanding me to mean? Because I do not understand your reply.

    Note that I am not expecting mklink to do that, since it apparently doesn't. But is there another way, other than a FOR loop?

    --peter
    I believe you are wanting to create a symbolic link for files, but that's not an available option I'm aware of other than creating a normal shortcut that points to a file like below.

    Create Shortcut to App, File, Folder, Drive, or Website in Windows 10
      My Computers


  4. apb
    Posts : 94
    win 7 64bit
       #13

    Thanks. Actually it would be sufficient if I could create such shortcuts rather than symlinks, but from a command line, since I need to do it in a bat file. As far as I can tell, there is no way to do that, either. Or is there?

    BTW, thanks for the quick responses.

    --peter
      My Computers


  5. Posts : 68,937
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #14

    apb said:
    Thanks. Actually it would be sufficient if I could create such shortcuts rather than symlinks, but from a command line, since I need to do it in a bat file. As far as I can tell, there is no way to do that, either. Or is there?

    BTW, thanks for the quick responses.

    --peter
    Hmm, there doesn't appear to be a straight forward way to create a shortcut (.lnk) via command line, but you may be able to use a PowerShell script like below if you really wanted to go the command line route.

    command line - How to create a shortcut using PowerShell - Stack Overflow
      My Computers


  6. apb
    Posts : 94
    win 7 64bit
       #15

    Thanks, but most of my powershell attempts have led to powerful frustration; seems I never have the right version nor the right package.

    I did, however, write a bat script which does the job, but there really should be a way to do it more or less atomically.

    The author of linkshellextension has just said he would add the feature to his ln.exe, in the case of symlinks that I was interested in.

    In case someone finds this thread after he has done so, wanting to do the same thing, that stuff can be found at Link Shell Extension .



    --peter
      My Computers


  7. Posts : 316
    Pro 20H2
       #16

    > "when you open a soft link to a folder, you will be redirected to the folder where the files are stored."
    > "A hard link makes it appear as though the file or folder actually exists at the location of the symbolic link"

    In what way would appearance differ in those two cases?

    >"That can make hard symbolic links more useful"
    How so?

    >"create a symbolic link (soft or hard) at C:\Program Files"
    Even if type does not matter in that example, surely there must be situations in which one type is is preferrable; and I very much want to know the practical criteria for chosing a type.
      My Computer


  8. apb
    Posts : 94
    win 7 64bit
       #17

    thename said:
    > "when you open a soft link to a folder, you will be redirected to the folder where the files are stored."
    > "A hard link makes it appear as though the file or folder actually exists at the location of the symbolic link"

    In what way would appearance differ in those two cases?

    >"That can make hard symbolic links more useful"
    How so?

    >"create a symbolic link (soft or hard) at C:\Program Files"
    Even if type does not matter in that example, surely there must be situations in which one type is is preferrable; and I very much want to know the practical criteria for chosing a type.
    Shawn's wording is a bit confusing in that section.

    Here is the difference:

    A hard link is just another name for the same file. If you delete the original filename, the hardlink will still get you to the same unaltered file.

    A symbolic link tells the file system to go look in a different place for the file. If you delete the original filename, the file is gone, and the symbolic link will point to something that no longer exists.
      My Computers


  9. Posts : 1,203
    11 Home
       #18

    apb said:
    Shawn's wording is a bit confusing in that section.

    Here is the difference:

    A hard link is just another name for the same file. If you delete the original filename, the hardlink will still get you to the same unaltered file.

    A symbolic link tells the file system to go look in a different place for the file. If you delete the original filename, the file is gone, and the symbolic link will point to something that no longer exists.
    One thing to bear in mind when dealing with the command line or using a batchfile, the del command on a junction deletes the contents of the junction's target folder. To remove only the junction, be sure to use the rd command instead.
      My Computers


  10. Posts : 316
    Pro 20H2
       #19

    apb said:
    A hard link is just another name for the same file. If you delete the original filename, the hardlink will still get you to the same unaltered file.

    A symbolic link tells the file system to go look in a different place for the file. If you delete the original filename, the file is gone, and the symbolic link will point to something that no longer exists.
    Thank you, a good distinction, I'm sure. However, I do not understand the deletion of a name.

    - - - Updated - - -

    hdmi said:
    del command on a junction deletes the contents of the junction's target folder. To remove only the junction, be sure to use the rd
    Excellent caveat.
    With regard to types of links: In my C: partition, reported by dir * /AL /s, there are dozens of junctions,
    and two symlinkD. No hard links.
      My Computer


 

Tutorial Categories

Create Soft and Hard Symbolic Links in Windows Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 23:52.
Find Us




Windows 10 Forums