Creating a bunch of junctions...

Discuss and share scripts and script files...
Post Reply
Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Creating a bunch of junctions...

Post by Marco »

I know that command #271 allows that, but I'm trying to do something slightly different.

I have a folder (let's call it A) with three subfolders, and another folder (B) with a bunch of subfolders. Every subfolder has its own unique name. And I'd like to create in B three junctions, each one pointing to one of A subfolder. Each junction having the same name of the subfolder it points to, as well as the attributes.
Running the command xcopy I'm able to copy the three subfolders without their contents (actually obtaining three empty folders in B, copies of their A counterparts), and with another cli utility (sysinternal's junction) I can turn them in junctions.

The problem I'm facing is due to the filenames. My first approach (via windows batch file) suggests that I should run some sort of for loop through the three folders in A, getting for each its name, and then "constructing" the proper paths to feed as parametres in the cli's mentioned above.

I'd like to know if this is easier to accomplish via XY's script engine or MS batch file system.
And yes, I know that at first it may seem an "oversized" approach for just three folders, but that's something that would be repeated quite frequently, hence the search for an automatized way.

TIA.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Creating a bunch of junctions...

Post by highend »

I'm afraid you have to rely on the good old dos because afaik there seems to be no way to assign junction names via scripting commands (without getting a pop-up box to enter one ofc).

Edit:
As an option you could write the .bat script on the fly through xyplorer's script commands and feed the necessary names to the command line tools from there _or_ invoke sysinternal's junction directly from your xyplorer script with the correct parameters.
Last edited by highend on 25 Jan 2012 21:15, edited 1 time in total.
One of my scripts helped you out? Please donate via Paypal

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Creating a bunch of junctions...

Post by Marco »

Ok, thanks for the clarification.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Creating a bunch of junctions...

Post by Marco »

Took me some hours of documentation, but finally here it is.
As an addendum, this works out-of-the-box with Vista and 7 (linkd and robocopy are bundled), for XP you need to get linkd from the Windows Server 2003 Resource Kit Tools, while robocopy should be extracted Robocopy GUI (thus obtaining version XP026, the last one working on NT5).

Code: Select all

for /f "tokens=* delims=" %%g in ('dir "A" /a:d /b') do linkd "B\%%g" "A\%%g"
for /f "tokens=* delims=" %%g in ('dir "A" /a:d /b') do robocopy "A\%%g" "B\%%g" /lev:1 /max:1
PS: happy to know if there's room for improvement in the code above
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Creating a bunch of junctions...

Post by Marco »

Ok, a new question regarding all this. I set up two batch files for managing file restoration after system imaging, one for my workstation and one for my laptop. I use a third batch file to call the correct script programmatically, through the use of the variable %computername%.
But I found out that, via a simple if loop, I can store both scripts in one batch file and then get the correct code executed based on which machine I am.
No problems whatsoever in both cases.

The question is: is there an approach that should be preferred over the other? Maybe performance-wise, code-management-wise and/or so on.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Post Reply