Multi Commander Support Forum

Multi Commander => Script => Topic started by: Lukas on December 26, 2015, 23:35:11

Title: Create hard link
Post 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

Code: [Select]
@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
}
Title: Re: Create hard link
Post by: Mathias (Author) on December 28, 2015, 15:42:17
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
Code: [Select]
MC.Utils.CreateLink ASADMIN LNKSRC="$sourceFile" LNKTRG="$targetFile" LNKTYPE=1
To
Code: [Select]
MC.Utils.CreateLink ASADMIN LNKSRC="{$sourceFile}" LNKTRG="{$targetFile}" LNKTYPE=1
Title: Re: Create hard link
Post by: Lukas on December 29, 2015, 14:14:03
Mathias, thank you for quick answer.

I simplified script, however doesn't work. I tested hard link and symbolic link only.

Code: [Select]
@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!
Title: Re: Create hard link
Post by: Mathias (Author) on December 29, 2015, 14:57:24
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.
Title: Re: Create hard link
Post by: Lukas on December 30, 2015, 16:07:16
Thank you, It works.
 :)