Need to create shortcuts from multiple exe on different subfolders
#1
Posted 17 March 2012 - 08:20 PM
utility tool to create shortcuts from multiple exe on different subfolders within one main folder?
#2
Posted 17 March 2012 - 08:28 PM
Post an example of the directory structure AND detail where the shortcuts should go.Does anyone know of a
utility tool to create shortcuts from multiple exe on different subfolders within one main folder?
Wonko
#3
Posted 17 March 2012 - 11:25 PM
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
Posted 18 March 2012 - 11:38 AM
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
Wonko
- Brito likes this
#5
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
Wonko
Great Wonko!!!
It does work!
edborg
#6
Posted 18 March 2012 - 02:21 PM
(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
Posted 18 March 2012 - 03:30 PM
Actually EFFECTIVELY OT.Apparently OT, but requiring similar creativity.
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 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
Wonko
#8
Posted 18 March 2012 - 08:18 PM
Your script and the copy command allow copying without overwriting, but I was looking for a feature in Explorer (drag&drop).If you want to do it in batch, it may be very loosely related:
...........
Change as it suits you.
Surprisingly the copy command is more powerful than Explorer:
http://ask-leo.com/c...ingle_step.html
This program does add a command to the context menu, but does not allow changing name...This may just do what you want to do (or completely fail to):
http://jstanley.ping...com/pscopy.html
Thanks for the hints, anyway,
edborg
#9
Posted 18 March 2012 - 09:01 PM
#10
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
Wonko
Doesnt seem to create the shortcuts. I ran the bat file.
#12
Posted 19 March 2012 - 09:10 AM
Ran HOW EXACTLY?Doesnt seem to create the shortcuts. I ran the bat file.
This:
means:If it's OK, remove the second ECHO to let the command actually execute
- 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
Wonko
#13
Posted 19 March 2012 - 02:17 PM
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 Ifcalled with e.g.
cscript //nologo shortcut.vbs "%USERPROFILE%SendToMetapad.lnk" "%SystemRoot%metapad.exe" "" "" "" 1 0
- Brito likes this
#14
Posted 19 March 2012 - 09:02 PM
Can't tell about the newest version. But it used to work fine in XPSP1 and XPSP2.On the other hand, CopyHandler (thanks for the hint doesn't work in XP, it freezes Explorer (tested on two PCs).
But like i said, you'll need a tool similar to 'copy handler'. There used to be at least 5 or 6.
#15
Posted 23 March 2012 - 08:50 AM
Ran HOW EXACTLY?
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
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.
#16
Posted 23 March 2012 - 10:03 AM
You are running Vista ?
The one used is not seemeingly compatible with Vista
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.cmdThis is NOT:
create shortcut.cmdThis 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.
Wonko
#17
Posted 23 March 2012 - 10:43 AM
No crystal ball needed! I simply gathered it from the images attached to TheHive's post.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 ?
The one used is not seemeingly compatible with Vista
http://www.optimumx.com/downloads.html
Wonko
However, compatibility is not a problem, I later even used it in Seven.
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".
edborg
#18
Posted 23 March 2012 - 07:39 PM
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. Kinda defeats the need.
#19
Posted 23 March 2012 - 07:53 PM
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>
Wonko
#20
Posted 23 March 2012 - 08:44 PM
Double clicking the cmd also works. As they say cool beans
#21
Posted 23 March 2012 - 08:46 PM
Maybe not. If their are subfolder with exe's then the subfolders will have the same name.
Not sure.
#22
Posted 24 March 2012 - 09:35 AM
It can be done of course.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.
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"?
Wonko
#23
Posted 24 March 2012 - 10:53 AM
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
Posted 24 March 2012 - 03:01 PM
Try this: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.
@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.
Wonko
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users