Multi Commander Support Forum
Multi Commander => Script => Topic started by: Lukas on December 26, 2015, 23:35:11
-
Hello,
I try to create a hard link to a file using script, but it doesn't do anythink. Can someone look at where I am wrong, please?
Thank you
Lukas
@var $selectedPaths = GetSourceSelectedPaths();
@var $targetPath = GetTargetPath();
//LogDumpArray($selectedPaths);
//LogDump($targetPath);
@var $sourcePathParts = StrSplit(PathGetPathPart($selectedPaths[0]), "\\");
@var $targetPathParts = StrSplit($targetPath, "\\");
//LogDumpArray( $sourcePathParts );
//LogDumpArray( $targetPathParts );
@var $counts = arrayCount($sourcePathParts);
@var $countt = arrayCount($targetPathParts);
@var $count = $countt;
if ($counts < $countt)
{
$count = $counts;
}
@var $i;
for( $i = 0; $i < $count; $i++ )
{
@var $cmp = StrIsEqualNoCase($sourcePathParts[$i], $targetPathParts[$i]);
if ($cmp == 0)
{
break;
}
}
@var $diffInx = $i;
@var $sourcePathRel = ".";
if ($i == 0)
{
$sourcePathRel = $sourcePath;
}
else
{
for( $i = $diffInx; $i < $counts; $i++ )
{
$sourcePathRel += "\\" + $sourcePathParts[$i];
}
$sourcePathRel = StrTrimLeft($sourcePathRel, ".\\");
}
@var $targetPathRel = ".";
if ($i == 0)
{
$targetPathRel = $targePath;
}
else
{
for( $i = $diffInx; $i < $countt; $i++ )
{
$targetPathRel += "\\" + $targetPathParts[$i];
}
$targetPathRel = StrTrimLeft($targetPathRel, ".\\");
}
//LogDump($sourcePathRel);
//LogDump($targetPathRel);
$count = arrayCount($selectedPaths);
for( $i = 0; $i < $count; $i++ )
{
@var $file = PathGetNamePart($selectedPaths[$i]);
@var $sourceFile = $sourcePathRel ^ $file;
@var $targetFile = $targetPathRel ^ $file;
//LogDump($sourceFile);
//LogDump($targetFile);
MC.Utils.CreateLink ASADMIN LNKSRC="$sourceFile" LNKTRG="$targetFile" LNKTYPE=1
}
-
I have not testet your script..
But in the MultiScript code you are calling CustomCommand functions.
CustomCommand are another type of simple scripts that MultiScript can call. When CustomCommand does not know about MultiScript type of parameters and stuff.
So when sending MultiScript paramters to a CustomCommand, this parameters must be encapsulated with { } so they are evaluated before the CustomCommand is called.
Try change
MC.Utils.CreateLink ASADMIN LNKSRC="$sourceFile" LNKTRG="$targetFile" LNKTYPE=1
To
MC.Utils.CreateLink ASADMIN LNKSRC="{$sourceFile}" LNKTRG="{$targetFile}" LNKTYPE=1
-
Mathias, thank you for quick answer.
I simplified script, however doesn't work. I tested hard link and symbolic link only.
@var $selectedPaths = GetSourceSelectedPaths();
@var $targetPath = GetTargetPath();
//LogDumpArray($selectedPaths);
//LogDump($targetPath);
@var $i;
@var $count = arrayCount($selectedPaths);
for( $i = 0; $i < $count; $i++ )
{
@var $file = PathGetNamePart($selectedPaths[$i]);
@var $sourceFile = $selectedPaths[$i];
@var $targetFile = $targetPath ^ $file;
LogDump($sourceFile);
LogDump($targetFile);
MC.Utils.CreateLink ASADMIN LNKSRC="{$sourceFile}" LNKTRG="{$targetFile}" LNKTYPE=1
}
But never mind, workaround is to write filenames into txt and after run batch.
Happy new year!
-
Ah You are mixing source and target
LNKSRC is the Link source (the link to create)
LNKTRG is the target of the Link (the existing file.. where the link should point to)
Also for Hardlinks the link and the target of the link must be on the same filesystem partition.
-
Thank you, It works.
:)