【解決方法】VB.NET で正しいドライブにいることを確認する方法


I have an app that keeps track of all my DVDs. 
The DVDs are also digitized so they can be played right from the app. When I go into the app, I need to be sure that I am in the same drive as the digitized movies. So far, I have been just manually changing the drive but would really like to be sure it is in the correct drive from the beginning. 
I have tried the SetCurrentDirectory() command, but it doesn’t work. I do Imports System.IO 
This is the code:

<pre><pre>Imports System.IO
Imports System.Speech.Synthesis
Imports System.Runtime.InteropServices

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'DVD_ListDataSet.DVD_List' table.          You can move, or remove it, as needed.
        Me.DVD_ListTableAdapter.Fill(Me.DVD_ListDataSet.DVD_List)

        synth.SelectVoice("Microsoft Zira Desktop")
        If Directory.GetCurrentDirectory() <> "J:\" Then
            Directory.SetCurrentDirectory("J:\")
        End If

    End Sub
VB

GetCurrentDirectory および SetCurrentDirectory コマンドは、これを行うために私が見つけることができる唯一のものです。 私は何を間違っていますか????

私が試したこと:

ドライブをチェックせずに、必要なドライブに設定しようとしました ‘

Directory.SetCurrentDirectory("J:\)"

しかし、それもうまくいきませんでした。

解決策 1

うまくいかなかったと確信していますか? ドライブは存在しますか?

システムでマップされたドライブを簡単に確認しました。

VB
Console.WriteLine($"Current: [{Directory.GetCurrentDirectory()}]")
Directory.SetCurrentDirectory(@"m:\")
Console.WriteLine($"Current: [{Directory.GetCurrentDirectory()}]")

出力は次のとおりです。

Current: [C:\CodeProject Help\ChangeDrive\ChangeDrive\bin\Debug\net7.0]
Current: [m:\]

コメント

タイトルとURLをコピーしました