creating a folder on each drive

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jenny

    creating a folder on each drive

    Hi, I am trying to find a VB way that would create a folder on all
    existing drives - the folder name would be the same on each drive. ie
    c:\backup, d:\backup, etc. But the folders would only be created if
    they don't already exist, and if the drive happens to be one a folder
    cannot be created on (ie a cdrom drive) it would just be skipped
    without the code generating any errors.
    your help on this would be most appreciated. jenny
  • Geoff

    #2
    Re: creating a folder on each drive

    jenn@onlink.net (jenny) wrote in message news:<3d8589ad. 0308041451.273f 7584@posting.go ogle.com>...[color=blue]
    > Hi, I am trying to find a VB way that would create a folder on all
    > existing drives - the folder name would be the same on each drive. ie
    > c:\backup, d:\backup, etc. But the folders would only be created if
    > they don't already exist, and if the drive happens to be one a folder
    > cannot be created on (ie a cdrom drive) it would just be skipped
    > without the code generating any errors.
    > your help on this would be most appreciated. jenny[/color]

    You can use the FSO, the only drawback is (apart from having to
    reference it)
    it can be optionaly switched off on a users machine.

    I would avoid using the FSO with the following.

    Private Declare Function GetLogicalDrive s Lib "kernel32" () As Long
    Use it to Create a Bitwise loop to give you the drives

    Private Declare Function GetDriveType Lib "kernel32" Alias
    "GetDriveTy peA" (ByVal nDrive As String) As Long
    Use to rid unwanted drives CD's etc

    VB's DIR to see if folders exist & MKDIR to create them.

    You can also use instr mid etc in the loop
    if you want to get fancy to create one time multiple folders
    e.g. Create/All/These/Folders/in/one/go

    Comment

    • Rick Rothstein

      #3
      Re: creating a folder on each drive

      > > Hi, I am trying to find a VB way that would create a folder on all[color=blue][color=green]
      > > existing drives - the folder name would be the same on each drive. ie
      > > c:\backup, d:\backup, etc. But the folders would only be created if
      > > they don't already exist, and if the drive happens to be one a folder
      > > cannot be created on (ie a cdrom drive) it would just be skipped
      > > without the code generating any errors.
      > > your help on this would be most appreciated. jenny[/color]
      >
      > You can use the FSO, the only drawback is (apart from having to
      > reference it)
      > it can be optionaly switched off on a users machine.
      >
      > I would avoid using the FSO with the following.
      >
      > Private Declare Function GetLogicalDrive s Lib "kernel32" () As Long
      > Use it to Create a Bitwise loop to give you the drives
      >
      > Private Declare Function GetDriveType Lib "kernel32" Alias
      > "GetDriveTy peA" (ByVal nDrive As String) As Long
      > Use to rid unwanted drives CD's etc
      >
      > VB's DIR to see if folders exist & MKDIR to create them.[/color]

      What about making the code even simpler?

      Dim X As Integer
      On Error Resume Next
      For X = Asc("c") To Asc("z")
      MkDir Chr$(X) & ":\backup"
      Next

      Rick - MVP


      Comment

      • jenny

        #4
        Re: creating a folder on each drive

        "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message news:<K32dnXQbK v6-7rKiXTWJig@comc ast.com>...[color=blue][color=green][color=darkred]
        > > > Hi, I am trying to find a VB way that would create a folder on all
        > > > existing drives - the folder name would be the same on each drive. ie
        > > > c:\backup, d:\backup, etc. But the folders would only be created if
        > > > they don't already exist, and if the drive happens to be one a folder
        > > > cannot be created on (ie a cdrom drive) it would just be skipped
        > > > without the code generating any errors.
        > > > your help on this would be most appreciated. jenny[/color]
        > >
        > > You can use the FSO, the only drawback is (apart from having to
        > > reference it)
        > > it can be optionaly switched off on a users machine.
        > >
        > > I would avoid using the FSO with the following.
        > >
        > > Private Declare Function GetLogicalDrive s Lib "kernel32" () As Long
        > > Use it to Create a Bitwise loop to give you the drives
        > >
        > > Private Declare Function GetDriveType Lib "kernel32" Alias
        > > "GetDriveTy peA" (ByVal nDrive As String) As Long
        > > Use to rid unwanted drives CD's etc
        > >
        > > VB's DIR to see if folders exist & MKDIR to create them.[/color]
        >
        > What about making the code even simpler?
        >
        > Dim X As Integer
        > On Error Resume Next
        > For X = Asc("c") To Asc("z")
        > MkDir Chr$(X) & ":\backup"
        > Next
        >
        > Rick - MVP[/color]


        Thanks a bunch! - that was good -never knew it could be so simple
        Your code looks similar to some vbs in a file I have which I would
        love to be able to convert to VB. Seeing your code makes it look like
        it may be possible. This vbs code I have is a study demo to show
        moving a prefixed and suffixed folder to another folder and at the
        same time renaming it without the prefix suffix:

        Dim WshShell, fso, fn, drv, dst, src
        set WshShell = WScript.CreateO bject("WScript. Shell")
        Set fso = CreateObject("S cripting.FileSy stemObject")
        On Error Resume Next
        fn=InputBox("En ter folder name from. ","Folder Move")
        If Not Trim(fn) = "" then
        For drv = Asc("C") to Asc("Z")
        src=Chr(drv)+": \backup\ab"+fn+ "12"
        If fso.FolderExist s(src) Then
        dst = Chr(drv)+":\wor k\"+fn
        fso.MoveFolder src, dst
        End If
        Next
        End If

        I don't really like it in vbs because it always brings up a Norton Av
        alert even though it is innocent vbs. Anyway, it can be made the same
        in VB?

        thanks again for the help!

        jenny

        Comment

        • Rick Rothstein

          #5
          Re: creating a folder on each drive

          > > What about making the code even simpler?[color=blue][color=green]
          > >
          > > Dim X As Integer
          > > On Error Resume Next
          > > For X = Asc("c") To Asc("z")
          > > MkDir Chr$(X) & ":\backup"
          > > Next
          > >
          > > Rick - MVP[/color]
          >
          > Thanks a bunch! - that was good -never knew it could be so simple[/color]

          I should point out one potential problem with the code I posted. I'm no
          longer on a network to test this, but I would guess if you have any attached
          network drives, and if you have write access to them, then I believe the
          above routine would create a directory out on the network drive too. (Again,
          I can't test this, but I believe it to be so.) If you have that situation,
          then you will probably need to use GetDriveType to check if any drive letter
          not producting an error is a network drive or not and skip over it if it is.

          [color=blue]
          > Your code looks similar to some vbs in a file I have which I would
          > love to be able to convert to VB. Seeing your code makes it look like
          > it may be possible. This vbs code I have is a study demo to show
          > moving a prefixed and suffixed folder to another folder and at the
          > same time renaming it without the prefix suffix:
          >
          > Dim WshShell, fso, fn, drv, dst, src
          > set WshShell = WScript.CreateO bject("WScript. Shell")
          > Set fso = CreateObject("S cripting.FileSy stemObject")
          > On Error Resume Next
          > fn=InputBox("En ter folder name from. ","Folder Move")
          > If Not Trim(fn) = "" then
          > For drv = Asc("C") to Asc("Z")
          > src=Chr(drv)+": \backup\ab"+fn+ "12"
          > If fso.FolderExist s(src) Then
          > dst = Chr(drv)+":\wor k\"+fn
          > fso.MoveFolder src, dst
          > End If
          > Next
          > End If
          >
          > I don't really like it in vbs because it always brings up a Norton Av
          > alert even though it is innocent vbs. Anyway, it can be made the same
          > in VB?[/color]

          I would avoid using FSO in VB projects like the plague (you can Google the
          newsgroups to find out why; this subject has been beaten to death in many
          previous newsgroup posts). VB has a built-in Name...As statement that can
          move a file around. Consider this (off the top of my head) code sample:

          Path = "d:\SomeDirecto ry\backup\"
          NewPath = "d:\SomeDirecto ry\work\"
          Prefix = "ab"
          FileName = "RICK"
          Suffix = "12"
          FileType = ".txt"
          Name Path & Prefix & FileName & Suffix & _
          FileType As NewPath & FileName & FileType

          Rick - MVP


          Comment

          • jenny

            #6
            Re: creating a folder on each drive

            Hi, I got it solved now with the code Rick gave but thanks for the
            suggestion.
            However, I looked at the Reference list and I cannot find anything
            listed as FileSystemObjec t. I'm using VB6.

            jenn
            "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message news:<cNDXa.793 4$mZ6.4920@nwrd ny02.gnilink.ne t>...[color=blue]
            > Hi Jenny,
            >
            > I suggest you reference the FileSystemObjec t "Project menu", then
            > "References "
            >
            > It has everything you need to do what you're asking for. and it's worked
            > quite well for me....create yourself a variable As FileSystemObjec t. and
            > look at all the methods and properties available to you. You'll see it has
            > it all :-).
            >
            > --
            > Stéphane Richard
            > Senior Software and Technology Supervisor
            > http://www.totalweb-inc.com
            > For all your hosting and related needs
            > "jenny" <jenn@onlink.ne t> wrote in message
            > news:3d8589ad.0 308041451.273f7 584@posting.goo gle.com...[color=green]
            > > Hi, I am trying to find a VB way that would create a folder on all
            > > existing drives - the folder name would be the same on each drive. ie
            > > c:\backup, d:\backup, etc. But the folders would only be created if
            > > they don't already exist, and if the drive happens to be one a folder
            > > cannot be created on (ie a cdrom drive) it would just be skipped
            > > without the code generating any errors.
            > > your help on this would be most appreciated. jenny[/color][/color]

            Comment

            • jenny

              #7
              Re: creating a folder on each drive

              "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message news:<-7edndaku5igRrKi U-KYvA@comcast.co m>...[color=blue][color=green][color=darkred]
              > > > What about making the code even simpler?
              > > >
              > > > Dim X As Integer
              > > > On Error Resume Next
              > > > For X = Asc("c") To Asc("z")
              > > > MkDir Chr$(X) & ":\backup"
              > > > Next
              > > >
              > > > Rick - MVP[/color]
              > >
              > > Thanks a bunch! - that was good -never knew it could be so simple[/color]
              >
              > I should point out one potential problem with the code I posted. I'm no
              > longer on a network to test this, but I would guess if you have any attached
              > network drives, and if you have write access to them, then I believe the
              > above routine would create a directory out on the network drive too. (Again,
              > I can't test this, but I believe it to be so.) If you have that situation,
              > then you will probably need to use GetDriveType to check if any drive letter
              > not producting an error is a network drive or not and skip over it if it is.
              >
              >[color=green]
              > > Your code looks similar to some vbs in a file I have which I would
              > > love to be able to convert to VB. Seeing your code makes it look like
              > > it may be possible. This vbs code I have is a study demo to show
              > > moving a prefixed and suffixed folder to another folder and at the
              > > same time renaming it without the prefix suffix:
              > >
              > > Dim WshShell, fso, fn, drv, dst, src
              > > set WshShell = WScript.CreateO bject("WScript. Shell")
              > > Set fso = CreateObject("S cripting.FileSy stemObject")
              > > On Error Resume Next
              > > fn=InputBox("En ter folder name from. ","Folder Move")
              > > If Not Trim(fn) = "" then
              > > For drv = Asc("C") to Asc("Z")
              > > src=Chr(drv)+": \backup\ab"+fn+ "12"
              > > If fso.FolderExist s(src) Then
              > > dst = Chr(drv)+":\wor k\"+fn
              > > fso.MoveFolder src, dst
              > > End If
              > > Next
              > > End If
              > >
              > > I don't really like it in vbs because it always brings up a Norton Av
              > > alert even though it is innocent vbs. Anyway, it can be made the same
              > > in VB?[/color]
              >
              > I would avoid using FSO in VB projects like the plague (you can Google the
              > newsgroups to find out why; this subject has been beaten to death in many
              > previous newsgroup posts). VB has a built-in Name...As statement that can
              > move a file around. Consider this (off the top of my head) code sample:
              >
              > Path = "d:\SomeDirecto ry\backup\"
              > NewPath = "d:\SomeDirecto ry\work\"
              > Prefix = "ab"
              > FileName = "RICK"
              > Suffix = "12"
              > FileType = ".txt"
              > Name Path & Prefix & FileName & Suffix & _
              > FileType As NewPath & FileName & FileType
              >
              > Rick - MVP[/color]


              Well almost there now with your impressive top of the head code - only
              problem is it the drive letter has to be specified for the backup
              folder (in the vbs original, the backup folder is found on no matter
              what drive it is on)
              Anyway, with drive letter, this is what I came up with so far:

              FolderName = InputBox("Enter Folder Name")
              Path = "d\backup\"
              NewPath = "d:\work\"
              Prefix = "ab"
              Suffix = "12"
              Name Path & Prefix & FolderName & Suffix & _
              FileType As NewPath & FolderName & FileType

              See any errors there? It seems to work just fine with the drive letter
              specified but how would I make it like the vbs one so that the backup
              folder would be found on whatever drive it is on? And the vbs also
              has "On Error Resume Next"

              ie
              On Error Resume Next
              fn=InputBox("En ter folder name from. ","Folder Move")
              For drv = Asc("C") to Asc("Z")
              src=Chr(drv)+": \backup\ab"+fn+ "12"
              If fso.FolderExist s(src) Then
              dst = Chr(drv)+":\wor k\"+fn
              fso.MoveFolder src, dst

              Thanks so much - I have learned something new. I always learn best
              from examples.
              And also thanks for the warning about the network drives - I'll have
              to look into that more. Got no idea how to use GetDriveType at this
              time.

              cheers!
              jenny

              Comment

              • jenny

                #8
                Re: creating a folder on each drive

                Great Rick! - that worked and creating the folder if not exist
                eliminates the need to create a folder on each drive! (my original
                post) but one thing I can't get now is message boxes to confirm
                Success or Error. I tried different ways with no success: ie:

                FolderName = InputBox("Enter Folder Name")
                Path = ":\backup\"
                NewPath = ":\work\"
                Prefix = "ab"
                Suffix = "12"
                On Error Resume Next
                For X = Asc("c") To Asc("z")
                MkDir Chr$(X) & ":\Restored "
                Name Chr$(X) & Path & Prefix & FolderName & _
                Suffix & FileType As _
                Chr$(X) & NewPath & _
                FolderName & FileType
                MsgBox "Success"
                End
                Next
                MsgBox "Error"
                End Sub

                Obviously I'm missing something - in the above I assumed that "On
                Error Resume Next" means that if there's an error - ie folder doesn't
                exist - the code would be skipped to after Next but i guess not.

                Re - the cheesy Input box - It's all I know now(I have the Idiots
                Guide to VB on order lol) plus the code is just a workaround to what
                I really think it should be able to do and that is to move any folder
                back to it's original location
                What I have now is a simple Browse for Folder dialogue where you
                select a folder, click Ok, and it gets moved to to the folder Backup
                on the ssame drive. But there is no opposite code to restore one of
                those moved folders back to their original location. Ideally, when a
                folder name is entered in the Input box, that folder would be moved
                back to where it came from. But that is such a stumper, that I am
                using this learning workaround code of just making the folder move
                outside the backup folder to another folder. And that is why I used a
                prefix suffix - so it would be easier to identify the folder to move
                (the prefix -suffix is automatically added when the folder is
                originally moved)
                The closest answer I got to solving such a problem was vague -
                something about creating a log file holding the original paths and
                then using the same move code to move any folder back to where it was.
                Do you have a clue to how to do that and would it work?
                If this is something you think you can figure and would be willing to
                try, I can post the move code. But regardless, you've been a great
                help already.
                thank you again


                jenny

                "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message news:<zY6cnQES2 Yl09q2iXTWJkw@c omcast.com>...[color=blue][color=green]
                > > Well almost there now with your impressive top of the head code - only
                > > problem is it the drive letter has to be specified for the backup
                > > folder (in the vbs original, the backup folder is found on no matter
                > > what drive it is on)
                > > Anyway, with drive letter, this is what I came up with so far:
                > >
                > > FolderName = InputBox("Enter Folder Name")
                > > Path = "d\backup\"
                > > NewPath = "d:\work\"
                > > Prefix = "ab"
                > > Suffix = "12"
                > > Name Path & Prefix & FolderName & Suffix & _
                > > FileType As NewPath & FolderName & FileType
                > >
                > > See any errors there?[/color]
                >
                > You're missing the colon in the assignment to the Path variable
                >
                >[color=green]
                > > It seems to work just fine with the drive letter
                > > specified but how would I make it like the vbs one so that the backup
                > > folder would be found on whatever drive it is on? And the vbs also
                > > has "On Error Resume Next"
                > >
                > > ie
                > > On Error Resume Next
                > > fn=InputBox("En ter folder name from. ","Folder Move")
                > > For drv = Asc("C") to Asc("Z")
                > > src=Chr(drv)+": \backup\ab"+fn+ "12"
                > > If fso.FolderExist s(src) Then
                > > dst = Chr(drv)+":\wor k\"+fn
                > > fso.MoveFolder src, dst[/color]
                >
                > At this point, I'm not sure what you have and what you don't have. Here's
                > some code that I think does what you want... it assumes the backup directory
                > already exists, it creates the work directory if it doesn't exist (even if
                > there is no backup directory on the drive), and it moves the file meeting
                > the filename "shape" from the backup directory to the work directory.
                >
                > FolderName = InputBox("Enter Folder Name")
                > Path = ":\backup\"
                > NewPath = ":\work\"
                > FileType = ".txt"
                > Prefix = "ab"
                > Suffix = "12"
                > On Error Resume Next
                > For X = Asc("c") To Asc("z")
                > MkDir Chr$(X) & ":\work"
                > Name Chr$(X) & Path & Prefix & FolderName & _
                > Suffix & FileType As _
                > Chr$(X) & NewPath & _
                > FolderName & FileType
                > Next
                >
                > A quick comment... I used the InputBox function because you did in your
                > sample; however, in a real-life project, I wouldn't (it looks too cheesy for
                > my tastes). Instead, I would add a new form to the project to serve as an
                > input dialog box, I would design it to look/work nicer than the InputBox
                > function using a larger, nicer font, some error handling code and so on. It
                > would have a Label for the message, a TextBox to accept input and probably
                > an icon of some sort.
                >
                >[color=green]
                > > Thanks so much[/color]
                >
                > You're welcome.
                >
                >[color=green]
                > > I have learned something new.[/color]
                >
                > Great!
                >
                >[color=green]
                > > And also thanks for the warning about the network drives - I'll have
                > > to look into that more. Got no idea how to use GetDriveType at this
                > > time.[/color]
                >
                > Let us know if this is a problem and some one here will try and help out.
                >
                >
                > Rick - MVP[/color]

                Comment

                • Rick Rothstein

                  #9
                  Re: creating a folder on each drive

                  Success or Error of what? We know there were errors for each drive that
                  didn't exist? There would also be errors if the Work directory already
                  exists. There are errors all over the place, hence the use of the

                  On Error Resume Next

                  statement. I'm guessing there would even be an error if one of the backup
                  files was opened and in use (it wouldn't be moved). The point is, we aren't
                  tracking each error... there would be too many of them.

                  Rick


                  "jenny" <jenn@onlink.ne t> wrote in message
                  news:3d8589ad.0 308060400.42c81 8f5@posting.goo gle.com...[color=blue]
                  > Great Rick! - that worked and creating the folder if not exist
                  > eliminates the need to create a folder on each drive! (my original
                  > post) but one thing I can't get now is message boxes to confirm
                  > Success or Error. I tried different ways with no success: ie:
                  >
                  > FolderName = InputBox("Enter Folder Name")
                  > Path = ":\backup\"
                  > NewPath = ":\work\"
                  > Prefix = "ab"
                  > Suffix = "12"
                  > On Error Resume Next
                  > For X = Asc("c") To Asc("z")
                  > MkDir Chr$(X) & ":\Restored "
                  > Name Chr$(X) & Path & Prefix & FolderName & _
                  > Suffix & FileType As _
                  > Chr$(X) & NewPath & _
                  > FolderName & FileType
                  > MsgBox "Success"
                  > End
                  > Next
                  > MsgBox "Error"
                  > End Sub
                  >
                  > Obviously I'm missing something - in the above I assumed that "On
                  > Error Resume Next" means that if there's an error - ie folder doesn't
                  > exist - the code would be skipped to after Next but i guess not.
                  >
                  > Re - the cheesy Input box - It's all I know now(I have the Idiots
                  > Guide to VB on order lol) plus the code is just a workaround to what
                  > I really think it should be able to do and that is to move any folder
                  > back to it's original location
                  > What I have now is a simple Browse for Folder dialogue where you
                  > select a folder, click Ok, and it gets moved to to the folder Backup
                  > on the ssame drive. But there is no opposite code to restore one of
                  > those moved folders back to their original location. Ideally, when a
                  > folder name is entered in the Input box, that folder would be moved
                  > back to where it came from. But that is such a stumper, that I am
                  > using this learning workaround code of just making the folder move
                  > outside the backup folder to another folder. And that is why I used a
                  > prefix suffix - so it would be easier to identify the folder to move
                  > (the prefix -suffix is automatically added when the folder is
                  > originally moved)
                  > The closest answer I got to solving such a problem was vague -
                  > something about creating a log file holding the original paths and
                  > then using the same move code to move any folder back to where it was.
                  > Do you have a clue to how to do that and would it work?
                  > If this is something you think you can figure and would be willing to
                  > try, I can post the move code. But regardless, you've been a great
                  > help already.
                  > thank you again
                  >
                  >
                  > jenny
                  >
                  > "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message[/color]
                  news:<zY6cnQES2 Yl09q2iXTWJkw@c omcast.com>...[color=blue][color=green][color=darkred]
                  > > > Well almost there now with your impressive top of the head code - only
                  > > > problem is it the drive letter has to be specified for the backup
                  > > > folder (in the vbs original, the backup folder is found on no matter
                  > > > what drive it is on)
                  > > > Anyway, with drive letter, this is what I came up with so far:
                  > > >
                  > > > FolderName = InputBox("Enter Folder Name")
                  > > > Path = "d\backup\"
                  > > > NewPath = "d:\work\"
                  > > > Prefix = "ab"
                  > > > Suffix = "12"
                  > > > Name Path & Prefix & FolderName & Suffix & _
                  > > > FileType As NewPath & FolderName & FileType
                  > > >
                  > > > See any errors there?[/color]
                  > >
                  > > You're missing the colon in the assignment to the Path variable
                  > >
                  > >[color=darkred]
                  > > > It seems to work just fine with the drive letter
                  > > > specified but how would I make it like the vbs one so that the backup
                  > > > folder would be found on whatever drive it is on? And the vbs also
                  > > > has "On Error Resume Next"
                  > > >
                  > > > ie
                  > > > On Error Resume Next
                  > > > fn=InputBox("En ter folder name from. ","Folder Move")
                  > > > For drv = Asc("C") to Asc("Z")
                  > > > src=Chr(drv)+": \backup\ab"+fn+ "12"
                  > > > If fso.FolderExist s(src) Then
                  > > > dst = Chr(drv)+":\wor k\"+fn
                  > > > fso.MoveFolder src, dst[/color]
                  > >
                  > > At this point, I'm not sure what you have and what you don't have.[/color][/color]
                  Here's[color=blue][color=green]
                  > > some code that I think does what you want... it assumes the backup[/color][/color]
                  directory[color=blue][color=green]
                  > > already exists, it creates the work directory if it doesn't exist (even[/color][/color]
                  if[color=blue][color=green]
                  > > there is no backup directory on the drive), and it moves the file[/color][/color]
                  meeting[color=blue][color=green]
                  > > the filename "shape" from the backup directory to the work directory.
                  > >
                  > > FolderName = InputBox("Enter Folder Name")
                  > > Path = ":\backup\"
                  > > NewPath = ":\work\"
                  > > FileType = ".txt"
                  > > Prefix = "ab"
                  > > Suffix = "12"
                  > > On Error Resume Next
                  > > For X = Asc("c") To Asc("z")
                  > > MkDir Chr$(X) & ":\work"
                  > > Name Chr$(X) & Path & Prefix & FolderName & _
                  > > Suffix & FileType As _
                  > > Chr$(X) & NewPath & _
                  > > FolderName & FileType
                  > > Next
                  > >
                  > > A quick comment... I used the InputBox function because you did in your
                  > > sample; however, in a real-life project, I wouldn't (it looks too cheesy[/color][/color]
                  for[color=blue][color=green]
                  > > my tastes). Instead, I would add a new form to the project to serve as[/color][/color]
                  an[color=blue][color=green]
                  > > input dialog box, I would design it to look/work nicer than the InputBox
                  > > function using a larger, nicer font, some error handling code and so on.[/color][/color]
                  It[color=blue][color=green]
                  > > would have a Label for the message, a TextBox to accept input and[/color][/color]
                  probably[color=blue][color=green]
                  > > an icon of some sort.
                  > >
                  > >[color=darkred]
                  > > > Thanks so much[/color]
                  > >
                  > > You're welcome.
                  > >
                  > >[color=darkred]
                  > > > I have learned something new.[/color]
                  > >
                  > > Great!
                  > >
                  > >[color=darkred]
                  > > > And also thanks for the warning about the network drives - I'll have
                  > > > to look into that more. Got no idea how to use GetDriveType at this
                  > > > time.[/color]
                  > >
                  > > Let us know if this is a problem and some one here will try and help[/color][/color]
                  out.[color=blue][color=green]
                  > >
                  > >
                  > > Rick - MVP[/color][/color]


                  Comment

                  • jenny

                    #10
                    Re: creating a folder on each drive

                    Sorry, I meant success or error in entering a valid folder name like
                    in the vbs code I had - I was able to add a msgbox
                    confirming success that the folder name entered existed and if not it
                    would
                    go to the error message.
                    ie
                    <snip>
                    On Error Resume Next
                    fn=InputBox("En ter folder name")
                    If Not Trim(fn) = "" then
                    For drv = Asc("C") to Asc("Z")
                    src=Chr(drv)+": \recycled\recyc lebin\abc"+fn+" 123"
                    If fso.FolderExist s(src) Then
                    dst = Chr(drv)+":\res tored\"+fn
                    fso.MoveFolder src, dst
                    msgbox "Success"
                    End If
                    Next
                    msgbox "Error - try again"
                    End If

                    And if nothing was entered in the box, nothing would happen.
                    So it worked perfectly but I just didn't like it in vbs
                    Would this be more complicated to do in VB?

                    jenny




                    "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message news:<yLacndwNR 9KHm6yiXTWJiw@c omcast.com>...[color=blue]
                    > Success or Error of what? We know there were errors for each drive that
                    > didn't exist? There would also be errors if the Work directory already
                    > exists. There are errors all over the place, hence the use of the
                    >
                    > On Error Resume Next
                    >
                    > statement. I'm guessing there would even be an error if one of the backup
                    > files was opened and in use (it wouldn't be moved). The point is, we aren't
                    > tracking each error... there would be too many of them.
                    >
                    > Rick
                    >
                    >
                    > "jenny" <jenn@onlink.ne t> wrote in message
                    > news:3d8589ad.0 308060400.42c81 8f5@posting.goo gle.com...[color=green]
                    > > Great Rick! - that worked and creating the folder if not exist
                    > > eliminates the need to create a folder on each drive! (my original
                    > > post) but one thing I can't get now is message boxes to confirm
                    > > Success or Error. I tried different ways with no success: ie:
                    > >
                    > > FolderName = InputBox("Enter Folder Name")
                    > > Path = ":\backup\"
                    > > NewPath = ":\work\"
                    > > Prefix = "ab"
                    > > Suffix = "12"
                    > > On Error Resume Next
                    > > For X = Asc("c") To Asc("z")
                    > > MkDir Chr$(X) & ":\Restored "
                    > > Name Chr$(X) & Path & Prefix & FolderName & _
                    > > Suffix & FileType As _
                    > > Chr$(X) & NewPath & _
                    > > FolderName & FileType
                    > > MsgBox "Success"
                    > > End
                    > > Next
                    > > MsgBox "Error"
                    > > End Sub
                    > >
                    > > Obviously I'm missing something - in the above I assumed that "On
                    > > Error Resume Next" means that if there's an error - ie folder doesn't
                    > > exist - the code would be skipped to after Next but i guess not.
                    > >
                    > > Re - the cheesy Input box - It's all I know now(I have the Idiots
                    > > Guide to VB on order lol) plus the code is just a workaround to what
                    > > I really think it should be able to do and that is to move any folder
                    > > back to it's original location
                    > > What I have now is a simple Browse for Folder dialogue where you
                    > > select a folder, click Ok, and it gets moved to to the folder Backup
                    > > on the ssame drive. But there is no opposite code to restore one of
                    > > those moved folders back to their original location. Ideally, when a
                    > > folder name is entered in the Input box, that folder would be moved
                    > > back to where it came from. But that is such a stumper, that I am
                    > > using this learning workaround code of just making the folder move
                    > > outside the backup folder to another folder. And that is why I used a
                    > > prefix suffix - so it would be easier to identify the folder to move
                    > > (the prefix -suffix is automatically added when the folder is
                    > > originally moved)
                    > > The closest answer I got to solving such a problem was vague -
                    > > something about creating a log file holding the original paths and
                    > > then using the same move code to move any folder back to where it was.
                    > > Do you have a clue to how to do that and would it work?
                    > > If this is something you think you can figure and would be willing to
                    > > try, I can post the move code. But regardless, you've been a great
                    > > help already.
                    > > thank you again
                    > >
                    > >
                    > > jenny
                    > >
                    > > "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message[/color]
                    > news:<zY6cnQES2 Yl09q2iXTWJkw@c omcast.com>...[color=green][color=darkred]
                    > > > > Well almost there now with your impressive top of the head code - only
                    > > > > problem is it the drive letter has to be specified for the backup
                    > > > > folder (in the vbs original, the backup folder is found on no matter
                    > > > > what drive it is on)
                    > > > > Anyway, with drive letter, this is what I came up with so far:
                    > > > >
                    > > > > FolderName = InputBox("Enter Folder Name")
                    > > > > Path = "d\backup\"
                    > > > > NewPath = "d:\work\"
                    > > > > Prefix = "ab"
                    > > > > Suffix = "12"
                    > > > > Name Path & Prefix & FolderName & Suffix & _
                    > > > > FileType As NewPath & FolderName & FileType
                    > > > >
                    > > > > See any errors there?
                    > > >
                    > > > You're missing the colon in the assignment to the Path variable
                    > > >
                    > > >
                    > > > > It seems to work just fine with the drive letter
                    > > > > specified but how would I make it like the vbs one so that the backup
                    > > > > folder would be found on whatever drive it is on? And the vbs also
                    > > > > has "On Error Resume Next"
                    > > > >
                    > > > > ie
                    > > > > On Error Resume Next
                    > > > > fn=InputBox("En ter folder name from. ","Folder Move")
                    > > > > For drv = Asc("C") to Asc("Z")
                    > > > > src=Chr(drv)+": \backup\ab"+fn+ "12"
                    > > > > If fso.FolderExist s(src) Then
                    > > > > dst = Chr(drv)+":\wor k\"+fn
                    > > > > fso.MoveFolder src, dst
                    > > >
                    > > > At this point, I'm not sure what you have and what you don't have.[/color][/color]
                    > Here's[color=green][color=darkred]
                    > > > some code that I think does what you want... it assumes the backup[/color][/color]
                    > directory[color=green][color=darkred]
                    > > > already exists, it creates the work directory if it doesn't exist (even[/color][/color]
                    > if[color=green][color=darkred]
                    > > > there is no backup directory on the drive), and it moves the file[/color][/color]
                    > meeting[color=green][color=darkred]
                    > > > the filename "shape" from the backup directory to the work directory.
                    > > >
                    > > > FolderName = InputBox("Enter Folder Name")
                    > > > Path = ":\backup\"
                    > > > NewPath = ":\work\"
                    > > > FileType = ".txt"
                    > > > Prefix = "ab"
                    > > > Suffix = "12"
                    > > > On Error Resume Next
                    > > > For X = Asc("c") To Asc("z")
                    > > > MkDir Chr$(X) & ":\work"
                    > > > Name Chr$(X) & Path & Prefix & FolderName & _
                    > > > Suffix & FileType As _
                    > > > Chr$(X) & NewPath & _
                    > > > FolderName & FileType
                    > > > Next
                    > > >
                    > > > A quick comment... I used the InputBox function because you did in your
                    > > > sample; however, in a real-life project, I wouldn't (it looks too cheesy[/color][/color]
                    > for[color=green][color=darkred]
                    > > > my tastes). Instead, I would add a new form to the project to serve as[/color][/color]
                    > an[color=green][color=darkred]
                    > > > input dialog box, I would design it to look/work nicer than the InputBox
                    > > > function using a larger, nicer font, some error handling code and so on.[/color][/color]
                    > It[color=green][color=darkred]
                    > > > would have a Label for the message, a TextBox to accept input and[/color][/color]
                    > probably[color=green][color=darkred]
                    > > > an icon of some sort.
                    > > >
                    > > >
                    > > > > Thanks so much
                    > > >
                    > > > You're welcome.
                    > > >
                    > > >
                    > > > > I have learned something new.
                    > > >
                    > > > Great!
                    > > >
                    > > >
                    > > > > And also thanks for the warning about the network drives - I'll have
                    > > > > to look into that more. Got no idea how to use GetDriveType at this
                    > > > > time.
                    > > >
                    > > > Let us know if this is a problem and some one here will try and help[/color][/color]
                    > out.[color=green][color=darkred]
                    > > >
                    > > >
                    > > > Rick - MVP[/color][/color][/color]

                    Comment

                    • Rick Rothstein

                      #11
                      Re: creating a folder on each drive

                      > Sorry, I meant success or error in entering a valid folder name like[color=blue]
                      > in the vbs code I had - I was able to add a msgbox
                      > confirming success that the folder name entered existed and if not it
                      > would
                      > go to the error message.
                      > ie
                      > <snip>
                      > On Error Resume Next
                      > fn=InputBox("En ter folder name")
                      > If Not Trim(fn) = "" then
                      > For drv = Asc("C") to Asc("Z")
                      > src=Chr(drv)+": \recycled\recyc lebin\abc"+fn+" 123"
                      > If fso.FolderExist s(src) Then
                      > dst = Chr(drv)+":\res tored\"+fn
                      > fso.MoveFolder src, dst
                      > msgbox "Success"
                      > End If
                      > Next
                      > msgbox "Error - try again"
                      > End If[/color]

                      I think you are after something like the following (change to my last posted
                      code):

                      FolderName = InputBox("Enter Folder Name")
                      If Len(Trim$(Folde rName)) Then
                      Path = ":\backup\"
                      NewPath = ":\work\"
                      FileType = ".txt"
                      Prefix = "ab"
                      Suffix = "12"
                      On Error Resume Next
                      For X = Asc("c") To Asc("z")
                      MkDir Chr$(X) & ":\work"
                      Name Chr$(X) & Path & Prefix & FolderName & _
                      Suffix & FileType As _
                      Chr$(X) & NewPath & _
                      FolderName & FileType
                      Next
                      MsgBox "Success!", vbExclamation, "Valid Entry"
                      Else
                      MsgBox "You didn't enter anything!", _
                      vbCritical, "Blank Entry"
                      End If

                      Note that the If-Then statement is testing for a non-entry. The Trim$
                      function was used to make sure the user didn't accidentally hit the space
                      bar one or more times. While I could have made the test this way

                      If Trim$(FolderNam e) = "" Then

                      the method I used (using the Len function) is, in fact, a faster testing
                      method. Since VB evaluates logical operators as being either 0, which is
                      identically what False is, or not 0 (that is, any number but zero), which is
                      what VB considers to be True. Since the Len("") = 0, then if the
                      Len(Trim$(Folde rName)) is not zero, VB will consider it as True (which is
                      why I don't perform the redundant test of >0).

                      Rick - MVP


                      Comment

                      • J French

                        #12
                        Re: creating a folder on each drive

                        On 7 Aug 2003 02:14:00 -0700, CrackpotUK@hotm ail.com (Geoff) wrote:
                        [color=blue]
                        >You can check with: Dir(Path & FolderName,vbDi rectory)
                        >It will return the folders name if it exists, if not it will return a blank string.
                        >[/color]
                        Best NOT use Dir()

                        ' ---
                        Function FileExists(Fle$ ) As Boolean
                        Dim Q%
                        On Error Resume Next
                        Q = GetAttr(Fle$)
                        If Err = 0 Then
                        If (Q And vbDirectory) = 0 Then
                        FileExists = True
                        End If
                        End If
                        Err.Clear
                        End Function

                        ' ---
                        Function DirExists(ADir$ ) As Boolean
                        Dim Q%
                        On Error Resume Next
                        Q = GetAttr(ADir$)
                        If Err = 0 Then
                        If (Q And vbDirectory) = vbDirectory Then
                        DirExists = True
                        End If
                        End If
                        Err.Clear
                        End Function


                        '
                        ############### ############### ############### ############### #############
                        '
                        ' C:\DEV\USLIB\US LIB.BAS --> X:\DEV\USLIB
                        '
                        Function ExtractFilePath $(Fle$)

                        Dim L9%

                        For L9 = Len(Fle$) To 1 Step -1
                        If InStr(":\", Mid$(Fle$, L9, 1)) Then
                        If Mid$(Fle$, L9, 1) = "\" Then
                        ExtractFilePath $ = Left$(Fle$, L9 - 1)
                        End If
                        If Mid$(Fle$, L9, 1) = ":" Then
                        ExtractFilePath $ = Left$(Fle$, L9)
                        End If
                        L9 = 1
                        End If
                        Next

                        End Function


                        Sub MakeDir(FileSpe c$, Erm$)
                        Dim S$

                        Erm$ = ""
                        If InStr(FileSpec$ , "\") Then
                        S$ = ExtractFilePath (FileSpec$)
                        Call MakeDir(S$, Erm$)
                        If Len(Erm$) = 0 Then
                        If DirExists(FileS pec$) = False Then
                        On Error Resume Next
                        MkDir FileSpec$
                        If Err Then Erm$ = "Error Making " + FileSpec$
                        On Error GoTo 0
                        End If
                        End If
                        End If
                        End Sub

                        Comment

                        • Ben Hall

                          #13
                          Re: creating a folder on each drive

                          On 6 Aug 2003 05:00:06 -0700, jenn@onlink.net (jenny) wrote:
                          [color=blue]
                          >Great Rick! - that worked and creating the folder if not exist
                          >eliminates the need to create a folder on each drive! (my original
                          >post) but one thing I can't get now is message boxes to confirm
                          >Success or Error. I tried different ways with no success: ie:
                          >
                          >FolderName = InputBox("Enter Folder Name")
                          >Path = ":\backup\"
                          > NewPath = ":\work\"
                          > Prefix = "ab"
                          > Suffix = "12"
                          > On Error Resume Next
                          > For X = Asc("c") To Asc("z")
                          > MkDir Chr$(X) & ":\Restored "
                          >Name Chr$(X) & Path & Prefix & FolderName & _
                          > Suffix & FileType As _
                          > Chr$(X) & NewPath & _
                          > FolderName & FileType
                          >MsgBox "Success"
                          >End
                          >Next
                          > MsgBox "Error"
                          >End Sub
                          >
                          >Obviously I'm missing something - in the above I assumed that "On
                          >Error Resume Next" means that if there's an error - ie folder doesn't
                          >exist - the code would be skipped to after Next but i guess not.[/color]

                          "On Error Resume Next" will skip to the next _line_ if an error is
                          encountered. It doesn't skip to the "Next" statement.

                          If you want to skip to after "Next" try the following

                          On Error Goto AfterNext
                          For X = Asc(...

                          Next
                          AfterNext: 'Note the trailing colon


                          Comment

                          • jenny

                            #14
                            Re: creating a folder on each drive

                            Thanks to all - I got it working now so cancel does nothing, right
                            folder name works, and wrong folder name doesn't.
                            Something else I can't figure though but i'll make that a new post.

                            thanks again
                            jenn

                            Ben Hall <benhall_0@yaho o.com.au> wrote in message news:<4vh4jv4eq 1b98ce3vs6kqvb7 1e6i7bb2d5@4ax. com>...[color=blue]
                            > On 6 Aug 2003 05:00:06 -0700, jenn@onlink.net (jenny) wrote:
                            > "On Error Resume Next" will skip to the next _line_ if an error is
                            > encountered. It doesn't skip to the "Next" statement.
                            >
                            > If you want to skip to after "Next" try the following
                            >
                            > On Error Goto AfterNext
                            > For X = Asc(...
                            >
                            > Next
                            > AfterNext: 'Note the trailing colon[/color]

                            Comment

                            Working...