programing

VB에 폴더가 없는 경우 폴더를 만들려면 어떻게 해야 합니까?

lastcode 2023. 5. 12. 22:19
반응형

VB에 폴더가 없는 경우 폴더를 만들려면 어떻게 해야 합니까?

저는 제 서버에서 파일 세트를 쉽게 가져와서 실제로 인터넷에 접속하지 않고도 Windows가 새로 설치된 새 PC에 모두 저장할 수 있도록 작은 다운로드 애플리케이션을 직접 작성했습니다.안타깝게도 저장할 폴더를 만드는 데 문제가 있고 어떻게 해야 할지 잘 모르겠습니다.

내 프로그램이 앱을 다운로드하기를 원합니다.program files\any name here\

그래서 기본적으로 저는 폴더가 있는지 확인하고, 없으면 폴더를 생성하는 기능이 필요합니다.

If Not System.IO.Directory.Exists(YourPath) Then
    System.IO.Directory.CreateDirectory(YourPath)
End If

시스템에서.IO, 디렉터리라는 클래스가 있습니다.다음을 수행합니다.

If Not Directory.Exists(path) Then
    Directory.CreateDirectory(path)
End If

그러면 디렉터리가 해당 위치에 있는지 확인합니다.

시스템을 사용해 보십시오.IO.디렉토리정보 클래스.

MSDN의 샘플:

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        ' Specify the directories you want to manipulate.
        Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir")
        Try
            ' Determine whether the directory exists.
            If di.Exists Then
                ' Indicate that it already exists.
                Console.WriteLine("That path exists already.")
                Return
            End If

            ' Try to create the directory.
            di.Create()
            Console.WriteLine("The directory was created successfully.")

            ' Delete the directory.
            di.Delete()
            Console.WriteLine("The directory was deleted successfully.")

        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class

질문이 명시되지 않았기 때문에.NET, VBScript 또는 VB6에서 작동해야 합니다.

Dim objFSO, strFolder
strFolder = "C:\Temp"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strFolder) Then
   objFSO.CreateFolder strFolder
End If

사용해 보십시오.Directory.Exists(TheFolderName)그리고.Directory.CreateDirectory(TheFolderName)

(필요할 수도 있습니다.Imports System.IO)

VB.NET? 시스템.IO.디렉토리.존재(문자열 경로)

디렉터리.CreateDirectory()가 이 작업을 수행해야 합니다.http://msdn.microsoft.com/en-us/library/system.io.directory.createdirectory(VS.71).aspx

또한 Vista에서는 관리자로 실행하지 않는 한 C:에 직접 쓸 수 없습니다. 따라서 C:(어쨌든 따르는 것이 좋은 방법이라고 생각합니다.) 많은 사람들이 C:에 쓰레기를 버리는 것은 믿을 수 없을 정도입니다.

도움이 되길 바랍니다.

(시스템을 가져옵니다.IO)

디렉터리가 아닌 경우.존재하는 경우(경로)디렉터리.디렉터리 만들기(경로)끝이 나다
If Not Directory.Exists(somePath) then
    Directory.CreateDirectory(somePath)
End If

파일 시스템 개체 또는 FSO를 사용해 보십시오.이 개체에 속한 메서드는 폴더가 있는지 확인하고 새 폴더를 만드는 데 사용할 수 있습니다.

사용자가 폴더 이름을 지정하고 원하는 위치에 배치할 수 있는 대화 상자를 만드는 프로세스는 무엇인지 알 수 있습니다.

건배.

이렇게 하면 됩니다.

        Dim sPath As String = "Folder path here"
    If (My.Computer.FileSystem.DirectoryExists(sPath) = False) Then
        My.Computer.FileSystem.CreateDirectory(sPath + "/<Folder name>")
    Else
        'Something else happens, because the folder exists
    End If

폴더 경로를 String(sPath)으로 선언하여 여러 번 사용하면 쉽게 변경할 수 있을 뿐만 아니라 프로그램 자체를 통해 변경할 수도 있습니다.

도움이 되길 바랍니다!

-nfall2009

언급URL : https://stackoverflow.com/questions/85996/how-do-i-create-a-folder-in-vb-if-it-doesnt-exist

반응형