Author Topic: Create hard link  (Read 19908 times)

Lukas

  • Junior Member
  • **
  • Posts: 14
    • View Profile
Create hard link
« 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
}

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Create hard link
« Reply #1 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

Lukas

  • Junior Member
  • **
  • Posts: 14
    • View Profile
Re: Create hard link
« Reply #2 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!
« Last Edit: December 29, 2015, 14:20:17 by Lukas »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Create hard link
« Reply #3 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.

Lukas

  • Junior Member
  • **
  • Posts: 14
    • View Profile
Re: Create hard link
« Reply #4 on: December 30, 2015, 16:07:16 »
Thank you, It works.
 :)