emendelson Posted October 8, 2010 Share Posted October 8, 2010 I'm writing a script which will use the SUBST command to assign a drive letter to a folder on disk. Is there a convenient way to detect which drive letters are currently NOT in use on the current system, so that I can choose one of those letters to use with SUBST? If so, could some generous person tell me what it is? Many thanks for any help. Link to comment Share on other sites More sharing options...
GEOSoft Posted October 8, 2010 Share Posted October 8, 2010 Here is one method but it's probably not the best. #Include<array.au3> $aDrives = DriveGetDrive("all") Local $sStr = "" For $i = 97 To 122 _ArraySearch($aDrives, Chr($i) & ":") If NOT @Error Then Continueloop $sStr &= Chr($i) & ":|" Next MsgBox(0, "Result", $sStr) Then You can do what you want with the resulting string, for example split it to get an array. $aAvailable = StringSplit(stringTrimRight($sStr, 1), "|") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
emendelson Posted October 9, 2010 Author Share Posted October 9, 2010 Here is one method but it's probably not the best.I don't know if it's the best, but it definitely gets the job done, and that's exactly what I was looking for. Thank you! Link to comment Share on other sites More sharing options...
GEOSoft Posted October 9, 2010 Share Posted October 9, 2010 (edited) Glad it helped but as an after-thought, I'm not sure that doing Subst on A: or B: is such a wise idea so I would do For $i = 99 To 122 And since C: is invariably used then it would be For $i = 100 To 122 Just food for thought. Edited October 9, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
emendelson Posted October 9, 2010 Author Share Posted October 9, 2010 (edited) That's almost exactly what I did. Thank you. It's actually possible to have a system with no drive C:. Example: Start with an empty hard disk and use a third-party utility to divide the disk into two primary partitions. Install XP on drive C, using the first primary partition; install Windows 7 on drive D, using the other partition. Then using a third-party utility, delete the XP partition, and make the Windows 7 partition the active one. (Also, optionally, expand the Windows 7 partition to fill the space made available by the removed C: partition, though this is NOT required.) Insert the Windows 7 installation DVD and repair the existing Windows 7 installation. The result is a Windows 7 system with only drive D: I had a Drive D:-only system years ago. I added XP on drive D: to a Windows 98 system on drive C:, and eventually removed the Windows 98 partition. Windows XP was happy to work on a D:-only system, but an amazing number of applications insisted on writing to drive C:, which didn't exist. So I finally gave up and started over with XP on drive C: (Modern software typically doesn't expect to see a drive C:, fortunately.) Edited October 9, 2010 by Edward Mendelson Link to comment Share on other sites More sharing options...
Danny35d Posted October 10, 2010 Share Posted October 10, 2010 Here is another method MsgBox(0, 'Free drive letter ', _GetFreeDriveLetter()) Func _GetFreeDriveLetter() For $x = 67 To 90 If DriveStatus(Chr($x) & ':\') = 'INVALID' Then Return(Chr($x) & ':') Next EndFunc meoit 1 AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
emendelson Posted October 10, 2010 Author Share Posted October 10, 2010 Very nice! Thank you! Link to comment Share on other sites More sharing options...
cengizhan Posted October 11, 2010 Share Posted October 11, 2010 I have modified your code because it didnt give correct results under windows 7. Here it is: MsgBox(0, 'Free drive letter ', _GetFreeDriveLetter()) Func _GetFreeDriveLetter() For $x = 67 To 90 If DriveStatus(Chr($x) & ':\') = 'INVALID' or Not FileExists (Chr($x) & ":\") Then Return(Chr($x) & ':') Next EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now