[SOLVED] Creating symlink from script on Windows 11

Mike3DMike3D Posts: 71

I'm trying to create a symlink for a duf file using the DzFile::link method.

I've created a 'XXX' folder in Scripts folder and tried to create a symlink pointing to the g8F head split DFormer using this code :

(function(){

	var path = '%1/People/Genesis 8 Female/Developer Kit/Genesis 8 Female HeadSplit DFormer.duf'.arg(App.getDataFolderPathBase());

	var file = new DzFile(path);

	print(file.link('%1/Scripts/XXX/Genesis8Female.duf'.arg(App.getDataFolderPathBase())));

})();

The output is 'true' (successful) and I get a 'Genesis8Female.duf' file in my XXX folder.

However, this file is :

- a 'physical' one, not a symlink

- a binary one, unusable, of size 1.81 Ko (original is 135 Ko, uncompressed)

Post edited by Mike3D on

Comments

  • OmnifluxOmniflux Posts: 442

    On Windows, this creates a Shell Link. You should use the file extension .lnk for this file. See also the Qt documentation for QFile.

    Note, however, that despite the documentation for both DzFile and QFile stating that this will not overwrite an existing file but will instead return an error, this appears to not be the case. My testing shows it does overwrite the file and reports success.

  • Mike3DMike3D Posts: 71
    edited June 26

    Many thanks for your detailed answer @Omniflux yes

    I should probably rely more on QT documentation, water is always clearer at its source !

    Unfortunately I need a symlink and I will have to find an alternative for Windows users

    Post edited by Mike3D on
  • OmnifluxOmniflux Posts: 442
    edited June 23

    Creating symlinks on Windows requires elevated privileges (See this Microsoft article)

    You can do it if you are willing to click through a UAC prompt. See attached script.

    dsa
    dsa
    MakeSymLink.dsa
    1K
    Post edited by Omniflux on
  • OmnifluxOmniflux Posts: 442

    You said symlink, but would a Daz JSON Link work for what you're doing? They have the advantage of referencing the original thumbnail and metadata.

    Introduced in Daz Studio 4.9.4, they can be created via the UI, or through script - Script Sample

     

  • Mike3DMike3D Posts: 71
    edited June 26

    Many thanks for follow-up and pointing me to DazJSON Link, which is a great alternative to symlinks smiley

    Also many thanks for the script allowing to execute PowerShell commands.

    I'm not sure that this is the best way to retrieve a DzAsset from its path, but this script works perfectly for my needs :

    (function(){
    
    var assetMgr = App.getAssetMgr(); // DzAssetMgr
    
    var path = 'People/Genesis 8 Female/Developer Kit/Genesis 8 Female HeadSplit DFormer.duf'; // Source file (relative path)
    
    var assets = assetMgr.findAssetsForFile(path, false, true); // [DzAssetHandle]
    
    if (assets.length < 1)
    	return;
    
    var asset = new DzScriptHandle(assets[0]).object; // DzAsset
    var out = '%1/Scripts/XXX/Genesis8Female.duf.%3'.arg(App.getDataFolderPathBase()).arg(asset.getDSLinkExtension()); // Destination
    asset.saveDSLink(out);
    
    assetMgr.updateFolderBasedContainers(); // Refresh pane
    
    })();
    Post edited by Mike3D on
  • Mike3DMike3D Posts: 71
    edited June 26

    Argh ! Subsequent issue is that I can't execute the link (Unknown File Format) :

    var uri = new DzUri('/Scripts/XXX/Genesis8Female.duf.djl');
    
    App.getContentMgr().openUri(uri);

     

    Post edited by Mike3D on
  • OmnifluxOmniflux Posts: 442

    Probably want to use App.getContentMgr().openFile() instead.

  • Mike3DMike3D Posts: 71

    You're right, this time everything works as expected yes

    Again, many thanks for awesome support !

Sign In or Register to comment.