Jump to content











Photo
- - - - -

Need to create shortcuts from multiple exe on different subfolders


  • Please log in to reply
27 replies to this topic

#1 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 17 March 2012 - 08:20 PM

Does anyone know of a
utility tool to create shortcuts from multiple exe on different subfolders within one main folder?

#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 March 2012 - 08:28 PM

Does anyone know of a
utility tool to create shortcuts from multiple exe on different subfolders within one main folder?

Post an example of the directory structure AND detail where the shortcuts should go.

:cheers:
Wonko

#3 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 17 March 2012 - 11:25 PM

Names of folder are different names

Games - main folder

Subfolders_of_Games Folder

- game1_subfolder
whatever.exe

- game2_subfolder
named-something-else.exe

- game3_subfolder
and-so-on.exe


So i need to lets say, right click Games main folder and the utility would create shortcuts from any exe in that folder or subfolders into the main root Games folder. maybe create the shortcut name from the folder its in.

#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 18 March 2012 - 11:38 AM

There are several utilities to create shortcuts from the command line, a few:
http://www.scriptlog...riptingtoolkit/
http://www.xxcopy.com/xxcopy38.htm
http://www.optimumx.com/downloads.html

Let's try with the latter one:
http://www.optimumx....ad/Shortcut.zip

This batch may do:
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=* delims=" %%A IN ('dir /b /s *.exe') DO (

ECHO %%~dpnxA

ECHO Shortcut.exe /F:"%~dp0%%~nA.lnk" /I:"%%~dpnxA",0 /R:1  /T:"%%~dpnxA" /A:C /W:"%%~dpA

)
Put the batch and shortcut.exe in the "relative root" directory (the one where you awant to create the shortcuts) and try running it.
If it's OK, remove the second ECHO to let the command actually execute

:cheers:
Wonko
  • Brito likes this

#5 edborg

edborg

    Frequent Member

  • .script developer
  • 387 posts
  •  
    Italy

Posted 18 March 2012 - 01:52 PM

There are several utilities to create shortcuts from the command line, a few:
http://www.scriptlog...riptingtoolkit/
http://www.xxcopy.com/xxcopy38.htm
http://www.optimumx.com/downloads.html

Let's try with the latter one:
http://www.optimumx....ad/Shortcut.zip

This batch may do:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=* delims=" %%A IN ('dir /b /s *.exe') DO (

ECHO %%~dpnxA

ECHO Shortcut.exe /F:"%~dp0%%~nA.lnk" /T:"%%~dpnxA" /A:C /W:"%%~dpA" /R:1 /I:"%%~dpnxA",0

)
Put the batch and shortcut.exe in the "relative root" directory (the one where you awant to create the shortcuts) and try running it.
If it's OK, remove the second ECHO to let the command actually execute

:cheers:
Wonko



Great Wonko!!! :clap:
It does work! :good:

edborg

#6 edborg

edborg

    Frequent Member

  • .script developer
  • 387 posts
  •  
    Italy

Posted 18 March 2012 - 02:21 PM

Apparently OT, but requiring similar creativity. :rolleyes:

(How) is it possible, when copying a file to another folder with Explorer, to get prompted for a name change to avoid overwriting an existing file?

Perhaps adding a sort of "paste with name" to the context menu...

edborg

#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 18 March 2012 - 03:30 PM

Apparently OT, but requiring similar creativity. :rolleyes:

Actually EFFECTIVELY OT.
If you want to do it in batch, it may be very loosely related:
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS



IF NOT EXIST "%~nx1" CALL :cp_ren "%~dpnx1" "%~nx1"&GOTO:EOF





SET Prepend1=Copia

SET Prepend2=di



IF NOT EXIST "%~dp1%Prepend1% %Prepend2% %~nx1" CALL :cp_ren "%~dpnx1" "%~dp1%Prepend1% %Prepend2% %~nx1"&GOTO:EOF





FOR /L %%A IN (2,1,10) DO (

IF NOT EXIST "%~dp1%Prepend1% (%%A) %Prepend2% %~nx1" (

CALL :cp_ren "%~dpnx1" "%Prepend1% (%%A) %Prepend2% %~nx1"

GOTO:EOF

)

)

GOTO :EOF



:cp_ren

ECHO COPY %1 %2

COPY /B %1 %2

GOTO :EOF

The above example uses the Italian prepended strings and is limited to 10 copies by the FOR /L loop.
AND it does something a little different, i.e. emulates the behaviour of Explorer when you try to copy and paste in the SAME folder.
Change as it suits you.

Surprisingly :w00t: the copy command is more powerful than Explorer:
http://ask-leo.com/c...ingle_step.html

This may just do what you want to do (or completely fail to):
http://jstanley.ping...com/pscopy.html

:cheers:
Wonko

#8 edborg

edborg

    Frequent Member

  • .script developer
  • 387 posts
  •  
    Italy

Posted 18 March 2012 - 08:18 PM

If you want to do it in batch, it may be very loosely related:
...........
Change as it suits you.

Surprisingly :w00t: the copy command is more powerful than Explorer:
http://ask-leo.com/c...ingle_step.html

Your script and the copy command allow copying without overwriting, but I was looking for a feature in Explorer (drag&drop).

This may just do what you want to do (or completely fail to):
http://jstanley.ping...com/pscopy.html

This program does add a command to the context menu, but does not allow changing name...

Thanks for the hints, anyway, :)

edborg

#9 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 18 March 2012 - 09:01 PM

For explorer you would need to find some tool like 'copy handler' which replaces the original Windows routine and which of course has the feature you want. Else i would say, look for a better file manager.

:cheers:

#10 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 19 March 2012 - 07:03 AM

There are several utilities to create shortcuts from the command line, a few:
http://www.scriptlog...riptingtoolkit/
http://www.xxcopy.com/xxcopy38.htm
http://www.optimumx.com/downloads.html

Let's try with the latter one:
http://www.optimumx....ad/Shortcut.zip

This batch may do:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=* delims=" %%A IN ('dir /b /s *.exe') DO (

ECHO %%~dpnxA

ECHO Shortcut.exe /F:"%~dp0%%~nA.lnk" /T:"%%~dpnxA" /A:C /W:"%%~dpA" /R:1 /I:"%%~dpnxA",0

)
Put the batch and shortcut.exe in the "relative root" directory (the one where you awant to create the shortcuts) and try running it.
If it's OK, remove the second ECHO to let the command actually execute

:cheers:
Wonko


Doesnt seem to create the shortcuts. I ran the bat file.
1.jpg
2.jpg

#11 edborg

edborg

    Frequent Member

  • .script developer
  • 387 posts
  •  
    Italy

Posted 19 March 2012 - 09:07 AM

Doesnt seem to create the shortcuts. I ran the bat file.
1.jpg
2.jpg

As said, it works well for me (tested in XP, not in Vista) :good:

@MedEvil

On the other hand, CopyHandler (thanks for the hint :)) doesn't work in XP, it freezes Explorer (tested on two PCs).

edborg

#12 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 19 March 2012 - 09:10 AM

Doesnt seem to create the shortcuts. I ran the bat file.

Ran HOW EXACTLY? :w00t:

This:

If it's OK, remove the second ECHO to let the command actually execute

means:
  • DO NOT double click on the batch file
  • OPEN a command prompt console and navigate to the "relative root folder" where you saved both the .cmd (please DO NOT use .bat as extension for NT batch .cmd files) and shortcut.exe
  • RUN the batch by typing it's name in the console and pressing [ENTER]
  • CHECK that the output is picking the "right" files.
  • THEN:

    If it's OK, remove the second ECHO to let the command actually execute

Comeon, TheHive :), you are not a newbie :dubbio:

:cheers:
Wonko

#13 dog

dog

    Frequent Member

  • Expert
  • 236 posts

Posted 19 March 2012 - 02:17 PM

You can also create shortcuts with vbscript:

Option Explicit

'On Error Resume Next

Dim oShell, fso, oShortCut, strLnk, strTarget, strArgs, strDesc, strDir, intWindowStyle, intIcon

set oShell = CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")

strLnk = WScript.Arguments(0)

strTarget = WScript.Arguments(1)

strArgs = WScript.Arguments(2)

strDesc = WScript.Arguments(3)

strDir = WScript.Arguments(4)

intWindowStyle = WScript.Arguments(5)

intIcon = WScript.Arguments(6)

If Not fso.FileExists(strLnk) Then

  Set oShortCut = oShell.CreateShortcut (strLnk)

  With oShortCut

    .TargetPath = strTarget

    .Arguments = strArgs

    .Description= strDesc

    .WorkingDirectory = strDir

    .WindowStyle = intWindowStyle

    .IconLocation = strTarget & "," & intIcon

'   .Hotkey=

    .Save

  End With

  wscript.echo "OK " & strLnk

Else

  wscript.echo "!! " & strLnk & " already exists"

End If

called with e.g.

cscript //nologo shortcut.vbs "%USERPROFILE%SendToMetapad.lnk" "%SystemRoot%metapad.exe" "" "" "" 1 0


  • Brito likes this

#14 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 19 March 2012 - 09:02 PM

On the other hand, CopyHandler (thanks for the hint :) doesn't work in XP, it freezes Explorer (tested on two PCs).

Can't tell about the newest version. But it used to work fine in XPSP1 and XPSP2.

But like i said, you'll need a tool similar to 'copy handler'. There used to be at least 5 or 6.

:cheers:

#15 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 23 March 2012 - 08:50 AM

Ran HOW EXACTLY? :w00t:

This:

means:

  • DO NOT double click on the batch file
  • OPEN a command prompt console and navigate to the "relative root folder" where you saved both the .cmd (please DO NOT use .bat as extension for NT batch .cmd files) and shortcut.exe
  • RUN the batch by typing it's name in the console and pressing [ENTER]
  • CHECK that the output is picking the "right" files.
  • THEN:


Comeon, TheHive :), you are not a newbie :dubbio:



You want to bet. I dont have much experience in batch files and much less using cmd extension.
Thats why at first, the bat was used. Thats untill you said to use cmd.
Still not getting anything.

1.jpg

#16 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 March 2012 - 10:03 AM

edborg provided a piece of info (though cannot say HOW he got it - he muat have a bettertuned crystal ball than I have) that you missed giving.
You are running Vista :ph34r: ?
The one used is not seemeingly compatible with Vista :ph34r:
http://www.optimumx.com/downloads.html
Can you confirm this?
Then I can re-do with another one.

Now, the FIRST thing that you should know is that [SPACE] is a DELIMITER on command line, consequently NEVER use a space in the name of a .cmd OR use double quotes around it.
This is OK:
create_shortcut.cmd
This is NOT:
create shortcut.cmd
This is OK (but foolish):
"create shortcut.cmd"
As you can see clearly, the command interpreter thinks that create is a command and since it cannot find create.bat, create.cmd or create.exe, it says that it cannot recognize the command.

The second thing is that all the batch does is to recursively find .exe's in the directory and all it's subdirectories.
To make sure that the Shrotcut.exe used works on your system, do the following:
Create a folder in ROOT of your drive (say C:\ ) named mytest (with NO spaces in it), put in it the shortcut.zip downloaded from OptimumX, and extract the shortcut.exe executable.
You will have:
C:\mytest\shortcut.exe
C:\mytest\shortcut.zip
Open a command prompt and navigate to the folder C:\mytest
Type on command line:
"C:\mytest\Shortcut.exe" /F:"myshortcut.lnk" /I:"C:\mytest\shortcut.zip",0 /R:1 /T:"C:\mytest\shortcut.zip" /A:C /W:"C:\mytest\


What happens?

The issue may be exactly that of paths with spaces in it and the parsing of double quotes.

On further tests I changed the snippet to have the program parse the string correctly, if the above manual test works for you, re-copy and paste the snippet from my previous post.

:cheers:
Wonko

#17 edborg

edborg

    Frequent Member

  • .script developer
  • 387 posts
  •  
    Italy

Posted 23 March 2012 - 10:43 AM

edborg provided a piece of info (though cannot say HOW he got it - he muat have a bettertuned crystal ball than I have) that you missed giving.
You are running Vista :ph34r: ?
The one used is not seemeingly compatible with Vista :ph34r:
http://www.optimumx.com/downloads.html

Wonko

No crystal ball needed! I simply gathered it from the images attached to TheHive's post. ;)

However, compatibility is not a problem, I later even used it in Seven. :thumbup:
Apparently Vista is not mentioned only because shortcut.exe was created before Vista/Seven/Eight/Nine/..... ;)

The space in the name was probably the ONLY cause of failure.
As a habit, NEVER use spaces in files/folders names, even if they are sometimes "tolerated". :frusty:

edborg

#18 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 23 March 2012 - 07:39 PM

As you mentioned. Taking out the Spaces on the Folders does seem to run the cmd file.
But the problem is I would have to rename all the folders with spaces and then the exe files cant have spaces in their names either.
Noticed It created shortcuts for the folder with no spaces on them and the exe that had no spaces in the name. :doh7: Kinda defeats the need.
1.jpg

#19 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 March 2012 - 07:53 PM

I NEVER TOLD you to take out the [Space] from folder names! :w00t:

I asked you to do a simple test and report.

Guess WHY I originally asked you to provide a sample of the directory structure and you provided a "fake" structure, BTW with NO spaces in names of directory or name of files?

Try the EDITED snippet (which I am posting again here):
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=* delims=" %%A IN ('dir /b /s *.exe') DO (

ECHO %%~dpnxA

Shortcut.exe /F:"%~dp0%%~nA.lnk" /I:"%%~dpnxA",0 /R:1 /T:"%%~dpnxA" /A:C /W:"%%~dpA

)


AND NOT the old one.
Here it works allright with names with spaces, both in the folder AND in the .exe filename.

C:mytest>dir
Il volume nell'unità C non ha etichetta.
Numero di serie del volume: C08C-CFD9

Directory di C:mytest

23/03/2012 20.50 <DIR> .
23/03/2012 20.50 <DIR> ..
23/03/2012 11.09 199 mklnk.cmd
23/03/2012 20.49 <DIR> my stoopidly long folder name with spaces
25/06/2011 13.18 553.353 myfirstest.exe
04/07/2005 01.11 57.344 Shortcut.exe
23/03/2012 10.35 24.241 Shortcut.zip
4 File 635.137 byte
3 Directory 171.150.639.104 byte disponibili

C:mytest>mklnk
C:mytestmyfirstest.exe

The command completed successfully.
C:mytestShortcut.exe

The command completed successfully.
C:mytestmy stoopidly long folder name with spacesmy second test with spaces.
exe

The command completed successfully.

C:mytest>dir
Il volume nell'unità C non ha etichetta.
Numero di serie del volume: C08C-CFD9

Directory di C:mytest

23/03/2012 20.50 <DIR> .
23/03/2012 20.50 <DIR> ..
23/03/2012 11.09 199 mklnk.cmd
23/03/2012 20.50 1.873 my second test with spaces.lnk
23/03/2012 20.49 <DIR> my stoopidly long folder name with spaces
25/06/2011 13.18 553.353 myfirstest.exe
23/03/2012 20.50 1.328 myfirstest.lnk
04/07/2005 01.11 57.344 Shortcut.exe
23/03/2012 20.50 1.314 Shortcut.lnk
23/03/2012 10.35 24.241 Shortcut.zip
7 File 639.652 byte
3 Directory 171.150.626.816 byte disponibili

C:mytest>


:cheers:
Wonko

#20 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 23 March 2012 - 08:44 PM

The new code seems to work well. At first posting I didnt know about how the directory structure was going to be. That is why i didnt have any samples with spaces on them. I was hoping to find a gui addon tot the right click option or something.


2.jpg
smiley_with_thumbs_up.png


Double clicking the cmd also works. As they say cool beans
jackbeans.jpg

#21 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 23 March 2012 - 08:46 PM

Any way to get the shortcut name from the Folder name
Maybe not. If their are subfolder with exe's then the subfolders will have the same name.
Not sure.

#22 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 March 2012 - 09:35 AM

Any way to get the shortcut name from the Folder name
Maybe not. If their are subfolder with exe's then the subfolders will have the same name.
Not sure.

It can be done of course.
Right now the name of the shortcut is:
"%~nA.lnk"
I.e. <name_of_the_found_exe>.lnk
Adding a small sub it is possible to add to it the folder name.
As an example, you have now "Eternal Daughter.lnk"
What do you want/need?
"Game1-Eternal Daughter.lnk"? :unsure:

:cheers:
Wonko

#23 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 24 March 2012 - 10:53 AM

Maybe the subfolder name first then the exe name as you posted.
That way if there 2 or more exe files one can know where they come from.
As you can see from the above picture in the Game2 folder there are two exe's found.

#24 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 March 2012 - 03:01 PM

Maybe the subfolder name first then the exe name as you posted.
That way if there 2 or more exe files one can know where they come from.
As you can see from the above picture in the Game2 folder there are two exe's found.

Try this:
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=* delims=" %%A IN ('dir /b /s *.exe') DO (

ECHO %%~dpnxA

CALL :Get_Folder "%%~pA"

Shortcut.exe /F:"%~d0!Folder_name!-%%~nA.lnk" /I:"%%~dpnxA",0 /R:1 /T:"%%~dpnxA" /A:C /W:"%%~dpA

)

GOTO :EOF



:Get_Folder

SET Folder_Name=

FOR /F "tokens=1,2,3,4,5 delims=" %%B IN (%1) DO (

SET Folder_Name=%%F

IF NOT DEFINED Folder_Name SET Folder_Name=%%E

IF NOT DEFINED Folder_Name SET Folder_Name=%%D

IF NOT DEFINED Folder_Name SET Folder_Name=%%C

IF NOT DEFINED Folder_Name SET Folder_Name=%%B

)

GOTO :EOF

This is limited to 5 levels below ROOT.

:cheers:
Wonko

#25 TheHive

TheHive

    Platinum Member

  • .script developer
  • 4204 posts

Posted 24 March 2012 - 07:20 PM

That works. Thanks!
1.jpg

How can you put a space in between

From
Game 1-Eternal Daughter

to
Game 1 - Eternal Daughter




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users