 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
k3ph
Joined: 21 Jul 2006 Posts: 123
|
Posted: Tue May 20, 2008 5:30 am Post subject: CreateDriveShortcut |
|
|
version: 0.02
| Code: | CreateDriveShortcut(setDrive)
{
; strip any ":" or "\" even its okay
StringReplace, setDrive, setDrive, \, , All
StringReplace, setDrive, setDrive, :, , All
; strip any "|" or "/" input by mistake
StringReplace, setDrive, setDrive, |, , All
StringReplace, setDrive, setDrive, /, , All
; add ":\" after stripping
Drive := % setDrive . ":\"
; getting driver information
DriveGet, DriveName, Label, %Drive%
DriveGet, DriveStatus, status, %Drive%
DriveGet, DriveType, type, %Drive%
; uncomment the line below for debugging
;MsgBox % "setDrive=" . setDrive . "`n" . "Drive=" . drive . "`n" . "DriveName=" . DriveName . "`n" . "DriveStatus=" . DriveStatus . "`n" . "DriveType=" . DriveType
; conditions
if (DriveStatus = "NotReady") {
msgbox drive "%drive%" is not ready
return
}
if (DriveStatus = "Invalid") {
msgbox drive "%drive%" is unaccessible
return
}
if (DriveName == "") {
DriveName = (%setDrive%)
}
FileCreateShortcut, %Drive%, %A_Desktop%\%DriveName%.lnk ; creates on desktop
}
; example (note: quotes are required)
CreateDriveShortcut("d") ; or CreateDriveShortcut("d:") or CreateDriveShortcut("d:\")
|
woli has suggested me @ irc channel a script for "auto creating shortcuts for removable media" like other operating systems' automount do have (eg: mac, linux etc).
So I've wrote this function as a draft.
Last edited by k3ph on Tue May 20, 2008 10:30 pm; edited 2 times in total |
|
| Back to top |
|
 |
keybored
Joined: 18 Jun 2006 Posts: 90 Location: Phoenix, AZ
|
Posted: Tue May 20, 2008 3:33 pm Post subject: |
|
|
| k3ph I ran it as is, but my D doesn't have a label so it was just an icon. Perhaps for drives with no label it should use the drive letter. |
|
| Back to top |
|
 |
k3ph
Joined: 21 Jul 2006 Posts: 123
|
Posted: Tue May 20, 2008 5:57 pm Post subject: |
|
|
| keybored wrote: | | k3ph I ran it as is, but my D doesn't have a label so it was just an icon. Perhaps for drives with no label it should use the drive letter. |
thanks for the info. the code was checked and fixed |
|
| Back to top |
|
 |
keybored
Joined: 18 Jun 2006 Posts: 90 Location: Phoenix, AZ
|
Posted: Thu May 22, 2008 7:52 am Post subject: |
|
|
The fix works.
I thought the extra code to handle drive names was a bit much, but it will come in handy if your drive letter is stored as a variable. Thanks for the update. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|