AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CreateDriveShortcut

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
k3ph



Joined: 21 Jul 2006
Posts: 123

PostPosted: Tue May 20, 2008 5:30 am    Post subject: CreateDriveShortcut Reply with quote

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
View user's profile Send private message
keybored



Joined: 18 Jun 2006
Posts: 90
Location: Phoenix, AZ

PostPosted: Tue May 20, 2008 3:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
k3ph



Joined: 21 Jul 2006
Posts: 123

PostPosted: Tue May 20, 2008 5:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
keybored



Joined: 18 Jun 2006
Posts: 90
Location: Phoenix, AZ

PostPosted: Thu May 22, 2008 7:52 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group