Batch files: First Free Drive: Difference between revisions

m
no edit summary
(New page: {{Uc nav batch files}} These code snippets are my thoughts on automatic available drive detection; final code is destined for the mini-servers to prevent conflicts. == Batch file to dete...)
 
mNo edit summary
 
Line 1: Line 1:
{{Uc nav batch files}}
{{Uc nav batch files}}


These code snippets are my thoughts on automatic available drive detection; final code is destined for the mini-servers to prevent conflicts.
These code snippets are my thoughts on automatic available drive detection; final code is destined for the [[Mini Servers: Introduction | mini-servers]] to prevent conflicts.


== Batch file to detect first free drive letter ==
== Batch file to detect first free drive letter ==
Line 490: Line 490:
@echo off
@echo off
for %%a in (Z Y X W V U T S R Q P O N M L K J I H G F E D C) do CD %%a: 1>> nul 2>&1 & if errorlevel 1 set freedrive=%%a:
for %%a in (Z Y X W V U T S R Q P O N M L K J I H G F E D C) do CD %%a: 1>> nul 2>&1 & if errorlevel 1 set freedrive=%%a:
echo %freedrive%
pause
</pre>
The solution to this problem of auto-drive detection was always destined for a new range of [[Mini Servers: Introduction | mini-servers]] now published. To my horror discovered the above failed on XP but worked fine on Vista. The failure mode was interesting, drive letter was allocated and servers worked fine plug in a USB stick, its detected with no problem however the drive letter allocated was the same as auto-detection. Servers continued to work USB stick was not accessible. After stopping the servers USB drive letter registered and drive was accessible.
Strictly speaking not a failure from the server’s point of view just inconvenient to a user. Solution implemented on the mini-servers was to reverse drive letter detection hence first allocated if free is Z.
<pre>
@echo off
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do CD %%a: 1>> nul 2>&1 & if errorlevel 1 set freedrive=%%a:
echo %freedrive%
echo %freedrive%
pause
pause
Line 501: Line 511:


{|  
{|  
| [[Image:uc_small_logo.gif]] || [[User:Ric|Ric]]  
| [[Image:uc_small_logo.gif]] || [[User:Ric|Ric]]
|}
|}