PYTHON Copy a shortcut even if it already exists

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
skoizer
Messages: 54
Registration: June 19, 2018 - 4:45 PM

March 28, 2019 - 08:47

Good morning,
In an Open Office package, I need to copy shortcuts to the desktop for all users here: C:\Users\Public\Desktop\Software\

Code: Select all

    if os.path.isfile('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OpenOffice 4.1.5\OpenOffice Calc.lnk'):
        remove_file('C:\Users\Public\Desktop\Logiciels\OpenOffice Calc.lnk')
        shutil.move('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OpenOffice 4.1.5\OpenOffice Calc.lnk','C:\Users\Public\Desktop\Logiciels')
        print('OpenOffice Calc.lnk deplace')
If the file already exists, it displays an error message.

To replace this long line of code, is there a simpler way in Python?
Copy even if the file already exists. I haven't found any help on search engines or the forum


Installed WAPT version (1.5.1.26)
- Server OS (Linux) and version (CentOS 7 - )
- Operating system of the administration/package creation machine (Windows 7 / 10)
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

May 6, 2019 - 12:11

Perhaps try this:

Code: Select all

shutil.move('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OpenOffice 4.1.5\OpenOffice Calc.lnk','C:\Users\Public\Desktop\Logiciels\OpenOffice Calc.lnk'
Alternatively, I also create shortcuts to all my software on "C:\users\Public\Desktop\Software\" but I prefer to recreate them rather than copy them, for example:

Code: Select all

         if iswin64():
            prog_dir = programfiles64
        else:
            prog_dir = programfiles32

        if not isdir(makepath(common_desktop(),'Logiciels','Bureautique')):
            mkdirs(makepath(common_desktop(),'Logiciels','Bureautique'))
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice.lnk'),target=r'%s\LibreOffice 5\program\soffice.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\soffice.exe' %prog_dir)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Base.lnk'),target=r'%s\LibreOffice 5\program\sbase.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\sbase.exe' %prog_dir)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Calc.lnk'),target=r'%s\LibreOffice 5\program\scalc.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\scalc.exe' %prog_dir)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Draw.lnk'),target=r'%s\LibreOffice 5\program\sdraw.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\sdraw.exe' %prog_dir)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Impress.lnk'),target=r'%s\LibreOffice 5\program\simpress.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\simpress.exe' %programfiles)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Math.lnk'),target=r'%s\LibreOffice 5\program\smath.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\smath.exe' %prog_dir)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Writer.lnk'),target=r'%s\LibreOffice 5\program\swriter.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\swriter.exe' %prog_dir)
        create_shortcut(makepath(common_desktop(),'Logiciels','Bureautique','LibreOffice Web.lnk'),target=r'%s\LibreOffice 5\program\sweb.exe' %prog_dir, wDir=r'%s\LibreOffice 5\program\\' %prog_dir,icon=r'%s\LibreOffice 5\program\sweb.exe' %prog_dir)
        remove_desktop_shortcut('LibreOffice')
Locked