Hello I have some symlink files that point to relative paths, and I'd like to copy them to another directory.
When I copy-and-paste them, xyplorer is NOT copying the symlink files themselves, but the contents they point to.
Is there a way to tell xyplorer to copy the actual symlinks files and not their targets? (like the /B switch of the xcopy command)
How to copy a symlink itself, not its contents
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: How to copy a symlink itself, not its contents
How exactly did you create these symlinks?
One of my scripts helped you out? Please donate via Paypal
-
user184362
- Posts: 4
- Joined: 26 Apr 2020 16:03
Re: How to copy a symlink itself, not its contents
I had to use mklink since I need the target to be a relative path.
If I use XYplorer, then the symplink is generated using an absolute path, which is one of the things I am trying to avoid.
In any case, it should not matter how the symlink is created, I am just asking if there is a way to copy-and-paste the link itself, not its target.
Again, like the /B switch does in xcopy
If I use XYplorer, then the symplink is generated using an absolute path, which is one of the things I am trying to avoid.
In any case, it should not matter how the symlink is created, I am just asking if there is a way to copy-and-paste the link itself, not its target.
Again, like the /B switch does in xcopy
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: How to copy a symlink itself, not its contents
Afaik not possible but not 100% sure (never used this myself). Scripting it would be a solution but without knowing which commands you're executing to create the symlink and how you use xcopy...
One of my scripts helped you out? Please donate via Paypal
-
user184362
- Posts: 4
- Joined: 26 Apr 2020 16:03
Re: How to copy a symlink itself, not its contents
Ok, let's elaborate this a bit.
Suppose you are in C:\folderA
This folder contains a subfolder named "subfolder1"
Now you want to create a symlink to this "subfolder1" and name it "subfolder2"
So we open a terminal, and type:
cd C:\folderA
mklink /D subfolder2 .\subfolder1
Now we have the following files:
C:\folderA
C:\folderA\subfolder1
C:\folderA\subfolder2 --> Which points to .\subfolder1
Let's suppose I have a USB drive, and I want to make a backup of "folderA" from C: to E:
What I want is to end up with the following files:
E:\folderA
E:\folderA\subfolder1
E:\folderA\subfolder2 --> Which points to .\subfolder1
NOTE that E:\folderA\subfolder2 points to the relative path .\subfolder1 so when clicking on "subfolder2" the explorer should take me to E:\folderA\subfolder1 and NOT to C:\folderA\subfolder1
What happens right now is that E:\folderA\subfolder2 is NOT a symlink anymore, but a duplicate of the contents in the original target C:\folderA\subfolder1
Any ideas of how to achieve this through XYPlorer?
Suppose you are in C:\folderA
This folder contains a subfolder named "subfolder1"
Now you want to create a symlink to this "subfolder1" and name it "subfolder2"
So we open a terminal, and type:
cd C:\folderA
mklink /D subfolder2 .\subfolder1
Now we have the following files:
C:\folderA
C:\folderA\subfolder1
C:\folderA\subfolder2 --> Which points to .\subfolder1
Let's suppose I have a USB drive, and I want to make a backup of "folderA" from C: to E:
What I want is to end up with the following files:
E:\folderA
E:\folderA\subfolder1
E:\folderA\subfolder2 --> Which points to .\subfolder1
NOTE that E:\folderA\subfolder2 points to the relative path .\subfolder1 so when clicking on "subfolder2" the explorer should take me to E:\folderA\subfolder1 and NOT to C:\folderA\subfolder1
What happens right now is that E:\folderA\subfolder2 is NOT a symlink anymore, but a duplicate of the contents in the original target C:\folderA\subfolder1
Any ideas of how to achieve this through XYPlorer?
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: How to copy a symlink itself, not its contents
Something like this should work...
You start the script when you are IN the src folder (in XYplorers list pane) you want to copy. E.g. in C:\folderA
Then you select the destination path in the upcoming file requester. E.g.: E:\
The "folderA" subfolder (the last part of the current src folder) will be created in the destination automatically.
In other words, the copy process will now copy everything inside the current folder (C:\folderA) into
E:\folderA
I'm just using XCOPY instead of doing things in XYs language...
You start the script when you are IN the src folder (in XYplorers list pane) you want to copy. E.g. in C:\folderA
Then you select the destination path in the upcoming file requester. E.g.: E:\
The "folderA" subfolder (the last part of the current src folder) will be created in the destination automatically.
In other words, the copy process will now copy everything inside the current folder (C:\folderA) into
E:\folderA
I'm just using XCOPY instead of doing things in XYs language...
Code: Select all
$batHeader = <<<>>>
@ECHO OFF
REG QUERY "HKU\S-1-5-19" >NUL 2>NUL && GOTO :ENDUAC
SET "vbsFile=%TEMP%\~getAdmin.vbs"
IF "%1" NEQ "" (FOR /F "tokens=*" %%I IN ('ECHO %*') DO SET "param=%%~I")
ECHO Set UAC = CreateObject^("Shell.Application"^)> "%vbsFile%"
ECHO UAC.ShellExecute "cmd", "/c """"%~s0"" ""%param%""""", "", "runas", ^1>> "%vbsFile%"
CSCRIPT "%vbsFile%" //Nologo
IF EXIST "%vbsFile%" DEL /Q "%vbsFile%" >NUL 2>NUL
EXIT /B
:ENDUAC
>>>;
$srcLast = trim(gpc(<curpath>, "component", -1), ":", "R");
$dst = inputfolder(, "Select destination...");
$dst .= "\" . $srcLast;
// /S Copy folders and subfolders
// /Y Suppress prompt to confirm overwriting a file
// /B Copy the Symbolic link itself, not the target of the file
// /I If in doubt always assume the destination is a folder
$cmd = <<<>>>
XCOPY "<curpath>\*" "$dst" /S /Y /B /I
>>>;
$bat = regexreplace($batHeader . <crlf 2> . $cmd, "^[ \t]+");
$batFile = "%TEMP%\~XY_XCOPY.bat";
if (writefile($batFile, $bat, , "utf8") >= 0) {
$result = runret("""$batFile""", "%TEMP%", 65001, 2);
if ($result != 0) {
trayballoon "Error!", "XCOPY did not exit with ERRORLEVEL 0", 3, 0;
}
}
One of my scripts helped you out? Please donate via Paypal
-
user184362
- Posts: 4
- Joined: 26 Apr 2020 16:03
Re: How to copy a symlink itself, not its contents
Excellent!
That script works really well. Thanks so much for your effort. Well done.
It would be excellent if something like the xcopy /B option is added to the list of "Custom Copy" options for XYcopy.exe
This is something you may consider adding in the future.
Thanks a lot for your help.
That script works really well. Thanks so much for your effort. Well done.
It would be excellent if something like the xcopy /B option is added to the list of "Custom Copy" options for XYcopy.exe
This is something you may consider adding in the future.
Thanks a lot for your help.
-
Millzey
- Posts: 169
- Joined: 07 Oct 2011 15:10
Re: How to copy a symlink itself, not its contents
Crazy ironic. I was faced with this dilemma a few days ago needing to move a dozen or so directory symlinks to a new hard drive. Never figured out a solution except recreating all of them with mklink.
What is most troublesome is when you dont realize a directory symlink is in a folder you want to copy/move all the contents of, and it points to a large folder on another drive or destination and you end up transferring the symlink target files along also. A dialog or config option to choose if directory symlinks contents or the symlink itself is copied would be great.
BTW thanks for the solution
What is most troublesome is when you dont realize a directory symlink is in a folder you want to copy/move all the contents of, and it points to a large folder on another drive or destination and you end up transferring the symlink target files along also. A dialog or config option to choose if directory symlinks contents or the symlink itself is copied would be great.
BTW thanks for the solution
XYplorer Beta Club