Results 1 to 24 of 24

Thread: Make command button create a new folder?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Make command button create a new folder?

    Hey everyone,

    Does anybody know the code or how to make it so when a user presses a command button then it will make a new folder called "Recordings" in the app directory path?

    Thanks

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    Place this in your Command button click code...

    Code:
    If Dir(App.Path & "Recordings") = "" Then
        MkDir App.Path & "Recordings"
    End If
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Make command button create a new folder?

    Quote Originally Posted by koolsid View Post
    Place this in your Command button click code...

    Code:
    If Dir(App.Path & "Recordings") = "" Then
        MkDir App.Path & "\Recordings"
    End If
    Fixed your post!
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Make command button create a new folder?

    Based on the name of that folder, I suspect you intend to write files there... which is a very bad idea.

    For more information, see the article Where should I store the files that my program uses/creates? from our Classic VB FAQs

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    thanks for the replys guys, One quick question!

    How can i make it to create the recodings file in their my documents folder when they press the command button?

    Thanks,

  6. #6
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Make command button create a new folder?

    You could read this article.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    Quote Originally Posted by abhijit
    Fixed your post!
    Thanks Abhi... How did I miss that?

    @Jamie : What kind of recordings are these? Is it a personal application or a call recording software for common use? The reason I ask is that I am from the BPO industry and we have a common folder to store our recordings...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    Hi there, For some reasong when im clicking btnstart (command button) i get an error saying path not found? The whole idea is to make a folder in C:\ called recordings?

    This is the code i used ? Have i broke something?

    Thanks,
    Code:
    private Sub btnStart_Click()
    
    If Dir("C:\Recordings") = "" Then
        MkDir "C:\Recordings\"
    End If

  9. #9
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Make command button create a new folder?

    Quote Originally Posted by JamieWarren09 View Post
    Hi there, For some reasong when im clicking btnstart (command button) i get an error saying path not found? The whole idea is to make a folder in C:\ called recordings?

    This is the code i used ? Have i broke something?

    Thanks,
    Code:
    private Sub btnStart_Click()
    
    If Dir("C:\Recordings") = "" Then
        MkDir "C:\Recordings\"
    End If
    This code should work for you.
    Do you have write permission on the C: drive?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    No worrys guys i've fixed it thanks anyways!!

  11. #11
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Make command button create a new folder?

    Quote Originally Posted by JamieWarren09 View Post
    No worrys guys i've fixed it thanks anyways!!
    1) Please post the fix that you had to do.
    2) Don't forget to mark this thread as resolved.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    Actually i aint fixed it XD i'm gettting a path access error now, And its a audio recording software , like where you can record from your microphone e.t.c

    Thanks.

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    What path are you specifying? Show us the exact code that you are using...

    BTW Congrats on your 100 posts
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    ok right ive now made it so it creates the folder "Recordings in the app directory"

    but its still giving me an error of path/file access error. But it creates it the first time i click it, but if i click it again it will give me that error. Im using this code?

    Code:
    If Dir(App.Path & "Recordings") = "" Then
        MkDir App.Path & "\Recordings"
    End If
    im guessing cause the folders already been created and cant be made again? as the fodlers already been made? so how can i make it so if its already been made it dont try & make the folder again?

    Thanks,

  15. #15
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    Changed the code... now try it...

    Code:
    If Dir(App.Path & "\Recordings") = "" Then
        MkDir App.Path & "\Recordings"
    End If
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    Awesome!

    One more thing if you could help me with please?

    in my app ive made it so the user puts in a text box the place the want the recording (file) to save to , for example if in the text box i put C:\jamie.wav

    it saves the file in C:\ called jamie.wav

    How ever is it possible to make it so it saves in the app dirctory\recordings?

    the code ive tried is

    File = ParseFile(App.Path & "\Recordings" \ "txtFile.Text")


    butt it dont work, Basically i need it to save in the app path \ recordings \ txtfile.text

    as the user will put in what they want the file to be called so if i typed in the text boz jamie itll save in

    app directory \ recordings\ jamie.wav

    thanks

  17. #17
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    Don't ask the user to enter the complete path... Let the user enter only a filename like "jamie.wav " and then when the user clicks on save, simply, append it to the path that you have. You can throw in an extra piece of code which will check if the filename is valid or not....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    That is what i am asking help for.

    at the moment im using this code

    File = ParseFile(App.Path & "\Recordings\txtFile.Text")

    Txtfile.text is the text box,

    But at the moment thats saving a file called txtfile.text into the recordings folder. But i need it to call the file what they put in txtfile.text..

    Hope you understand what i mean.

    thanks,

  19. #19
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    Code:
    File = App.Path & "\Recordings\" & Text1.Text)
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    aweosme that works, how ever,

    with this code for creating the folder "recordings"

    If Dir(App.Path & "\Recordings") = "" Then
    MkDir App.Path & "\Recordings"
    End If

    it creates it fine, But then if i run the app and push the command button that codes in it gives me a error still cause the folders already been made!

    But if i delete the folder it works fine


    is htier away to ignore the code if the folders already been made?

    Thanks,

  21. #21
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Make command button create a new folder?

    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Make command button create a new folder?

    To be honest im not understanding anything in that thread?

    Code:
    Private Sub btnStart_Click()
        
        If Dir(App.Path & "\Recordings") = "" Then
        MkDir App.Path & "\Recordings"
        
    End If
    Is the code im using now, But i obviousily need soemthing in there to ignore creating the file if it already exists.... How will i go about that?

    Sorry its just i dont understand what to change or what to add.

    thanks

  23. #23
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Make command button create a new folder?

    Quote Originally Posted by JamieWarren09 View Post
    To be honest im not understanding anything in that thread?

    Code:
    Private Sub btnStart_Click()
        
        If Dir(App.Path & "\Recordings") = "" Then
        MkDir App.Path & "\Recordings"
        
    End If
    Is the code im using now, But i obviousily need soemthing in there to ignore creating the file if it already exists.... How will i go about that?

    Sorry its just i dont understand what to change or what to add.

    thanks
    You said file, but I think you meant folder, correct?
    Try this instead:
    Code:
    If Dir(App.Path & "\Recordings", vbDirectory or vbHidden or vbReadOnly or vbSystem) = "" Then
    Last edited by LaVolpe; Oct 29th, 2009 at 08:05 PM. Reason: forgot: Then
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Make command button create a new folder?

    Another alternative is to use the MakeSureDirectoryPathExists API.

    Sample usage:

    Code:
    Option Explicit
    
    'this will create folders a, b and c at the same time
    Private Sub Command1_Click()
        MsgBox CreateFolder("C:\a\b\c")
    End Sub

    In a module:
    Code:
    Option Explicit
    
    Public Declare Function MakeSureDirectoryPathExists Lib "IMAGEHLP.DLL" ( _
                   ByVal DirPath As String) As Long
    
    'This will create subfolders if they don't exists, much better than MkDir
    Public Function CreateFolder(ByVal NewPath As String) As Boolean
        NewPath = AddSlash(NewPath)
        'Call API
        If MakeSureDirectoryPathExists(NewPath) <> 0 Then
            'No errors, return True
            CreateFolder = True
        End If
    End Function
    
    Public Function AddSlash(ByVal strDirectory As String) As String
        If InStrRev(strDirectory, "\") <> Len(strDirectory) Then
            strDirectory = strDirectory + "\"
        End If
        AddSlash = strDirectory
    End Function
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width