Hi,
I want to write a script that make a hardlink of files I selected to a folder for synchronization purposes.
I need to specify the separator to be a space, I tried '\ ', '\s', all doesn't work, please help me.
Here is the script:
foreach($var, <selitems>, separator= ) {
goto "! mklink /h".$var."C:\sync"
}
The reference for mklink
mklink – a command line tool included with Vista and Server 2008 and above. The most current link creation tool included with Windows. It creates Hard Links, Symbolic Links and Junction Points.
usage: mklink [[/d] | [/h] | [/j]] <NameofLink> <Target>
/d – Creates a Symbolic Link for a directory. If no flag used, creates a Symbolic Link for a file (default)
/h – Creates a Hard Link
/j – Creates a Junction Point
<NameofLink> – The name for the Symbolic Link being created
<Target> – The relative or absolute path of the target
/? – Help
Thank you very much!
How to escape a space [Solved]
How to escape a space [Solved]
Last edited by hitfq on 17 May 2014 18:17, edited 1 time in total.
-
binocular222
- Posts: 1419
- Joined: 04 Nov 2008 05:35
- Location: Win11, Win10, 100% Scaling
Re: How to escape a space
Quote itBut that script will break horribly if there're spaces inside file path of <selitems>. Use this instead:P.S: Should be posted at "Tips & Tricks, Questions & Answers"
P.S: IMO, you should use Run instead of goto. Also notice how I use 2 double-quotes around file paths (essentially, anything expect spaces will require 2 double-quotes):[/code]
Code: Select all
foreach($var, <selitems>, separator=" " ) {Code: Select all
$selitems = get("SelectedItemsPathNames", "|");
foreach($item, $selitems) {
goto "! mklink /h".$item."C:\sync";
}P.S: IMO, you should use Run instead of goto. Also notice how I use 2 double-quotes around file paths (essentially, anything expect spaces will require 2 double-quotes):
Code: Select all
[code] $selitems = get("SelectedItemsPathNames", "|");
foreach($item, $selitems) {
run "cmd /c mklink /h ""$item"" ""C:\sync"" ";
}
Last edited by binocular222 on 16 May 2014 05:45, edited 2 times in total.
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
Re: How to escape a space
binocular222, you beat me to it!
@hitfq, you shouldn't use space as separator as it will also split items that have spaces in name. Use some char that can't be used in filenames, for example |.
This code converts <selitems> to | separated list string, and then uses | in foreach.
@hitfq, you shouldn't use space as separator as it will also split items that have spaces in name. Use some char that can't be used in filenames, for example |.
This code converts <selitems> to | separated list string, and then uses | in foreach.
Code: Select all
$selitems = trim(replace(<selitems>, '" "', ' '), '"');
foreach($var, $selitems, '|') {
goto "! mklink /h".$var."C:\sync";
}Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: How to escape a space
It works!
Needs a little modification: use !! instead of ! so no popup and the parameter order meeds to be changed.
Code: Select all
$selitems = get("SelectedItemsNames", "|"); foreach($item, $selitems) { goto ("!! mklink /h "."C:\sync\".$item." ".$item);}Thank you very much!
binocular222 wrote:Quote it
P.S: IMO, you should use Run instead of goto. Also notice how I use 2 double-quotes around file paths (essentially, anything expect spaces will require 2 double-quotes):[/code]Code: Select all
[code] $selitems = get("SelectedItemsPathNames", "|"); foreach($item, $selitems) { run "cmd /c mklink /h ""$item"" ""C:\sync"" "; }
XYplorer Beta Club