DonationCoder.com Software > Finished Programs
DONE: Batch-create shortcuts from a CSV file
Josh:
Hello all,
Here is what I want to achieve. I need to create around 80-90 shortcuts. I have a CSV file that is formatted as such:
--- Code: Text ---Shortcut Title, Command
Is there a tool that can take this csv file and create shortscuts titled "Shortcut Title" and points to the "Command" executable or path?
Target:
Hello all,
Here is what I want to achieve. I need to create around 80-90 shortcuts. I have a CSV file that is formatted as such:
--- Code: Text ---Shortcut Title, Command
Is there a tool that can take this csv file and create shortscuts titled "Shortcut Title" and points to the "Command" executable or path?
-Josh (September 12, 2012, 07:26 PM)
--- End quote ---
I haven't tested this, but try this AHK script...
--- ---#singleinstance,force
fileselectfile, src, ,*.csv
if errorlevel
exitapp
loop, read, %src%
{
stringsplit,tmp_,a_loopreadline,`,
filecreateshortcut, %tmp_2%, %tmp_1%
}
exitapp
shortcuts should be created in the same directory as the script, though if you want to create them in a specific location that could be catered for as well
MilesAhead:
If "Command" is not wrapped in double quotes when containing spaces, such as a path under Program Files, I could see problems. This function might help
--- ---;returns string, wrapped in quotes when containing spaces
;updated to test if string already wrapped in double quotes
_WrapQuotes(str)
{
wqLeftChar := ""
wqRightChar := ""
if (!str) || (!InStr(str," "))
return str
StringLeft,wqLeftChar,str,1
StringRight,wqRightChar,str,1
if (wqLeftChar = """") && (wqRightChar = """")
return str
str := """" . str . """"
return str
}
Josh:
I appreciate the responses thus far! I must say that I am fairly proud that I just made this applet in powershell.
The intent behind this was to have a list of known control panel applets, and generate shortcuts to them. This is to aid mouser with a planned update to FARR and the way it calls the control panel applets.
I created a file named applets.txt, formatted it as such:
--- Code: Text ---Shortcut (LNK) Title, Path to control.exe, and the argument to call to execute the desired applet
Here is the code for powershell tested on Windows 8 and verified to work:
--- Code: Text ---# Create shortcuts to a known list of control panel applets from XP-Win8# File format for CSV is Shortcut Name, Path to control.exe (including control.exe in the path), Argument to call this control panel applet# Sample: Action Center, c:\windows\system32\control.exe, /name Microsoft.ActionCenter $filename = import-csv "c:\temp\applets.txt"foreach ($i in $filename){ $ShortcutName = $i.Name $Target = $i.Path $Argument = $i.Argument # Set the path to the shortcut LNK file $FullSPath = "$home\Desktop\Shortcuts\" + $ShortcutName + ".lnk" ### Debug code to display the shortcut file name, target file name (control.exe path) and the executing argument. # write-host "Shortcut File Name: " $FullSPath " Target File: " $Target " Argument: " $Argument # pause ### End debug code # Establish a wscript shell variable $wshshell = New-Object -ComObject WScript.Shell # Set the path to the target shortcut file (LNK) $lnk = $wshshell.CreateShortcut($FullSPath) # Set the Target path to the executable file itself (control.exe) $lnk.TargetPath = $Target # Set the argument (Control panel applet call) $lnk.Arguments = $i.Argument # Write the shortcut $lnk.save()}
Source file attached for shortcuts
MilesAhead:
Glad you got it to work. :)
Is this for W8 only? Or is it meant to be portable across Windows versions? I'm not sure about PowerShell as I could only force myself to read about it for 5 minutes. Something about the syntax turned me off. But there's probably stuff you can do with it that would be more difficult with other script types.
Navigation
[0] Message Index
[#] Next page
Go to full version