📎 AI Summary:
The thread discusses an issue where a script running in Command Prompt stops when an external drive becomes unavailable. The original poster seeks a method, preferably in PowerShell, to have a script that waits for the drive to become available again without stopping completely. Respondents suggest using PowerShell's `Test-Path` and looping constructs, with one clarifying that commands need to be run within the PowerShell environment for proper functionality; the original poster confirms difficulty in running PowerShell commands from a standard command prompt.

eager2learn

Extraordinary Member
Member details
Joined
Mar 27, 2017
Messages
9
Thread Author #1
A Windows system use an external drive N:.
A programs that use the external drive give sometimes an error message like "Directory N:\datastore is not available".

To test the continuous availability I write the next batch script.

:loop
@TimE /t >> N:\datastore\test_times.txt
@sleep 30
@goto loop

During the night this script stops in cmd.exe with the message: "The system cannot open the device or file specified".
It is intended that this script continues as soon as the disk is available again.
Is it possible to make such a batch script (maybe in powershell) that don't stop, but continues as soon as the disk is available again?
 

Solution
In Powershell it would just be
Code:
While(-not(Test-Path N:\))
{
    Start-Sleep -Seconds 30
}
# Continue the rest of the script when drive N: is available

Neemobeer

Windows Forum Team
Staff member
Member details
Joined
Jul 4, 2015
Messages
8,995
In Powershell it would just be
Code:
While(-not(Test-Path N:\))
{
    Start-Sleep -Seconds 30
}
# Continue the rest of the script when drive N: is available
 
Solution

eager2learn

Extraordinary Member
Member details
Joined
Mar 27, 2017
Messages
9
Thread Author #3
I know cmd.exe and I know Linux bash very well, but Powershell is new for me.
I get in Powershell the next error message
'while' is not recognozed as an internal or external command, operable program or batch file.
and the same error message for "{"