473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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
Jul 17 '05 #1
13 7159
je**@onlink.net (jenny) wrote in message news:<3d**************************@posting.google. com>...
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


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 GetLogicalDrives Lib "kernel32" () As Long
Use it to Create a Bitwise loop to give you the drives

Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (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
Jul 17 '05 #2
> > 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


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 GetLogicalDrives Lib "kernel32" () As Long
Use it to Create a Bitwise loop to give you the drives

Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (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.


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
Jul 17 '05 #3
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<K3********************@comcast.com>...
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


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 GetLogicalDrives Lib "kernel32" () As Long
Use it to Create a Bitwise loop to give you the drives

Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (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.


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

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.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fn=InputBox("Enter 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.FolderExists(src) Then
dst = Chr(drv)+":\work\"+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
Jul 17 '05 #4
> > 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
Thanks a bunch! - that was good -never knew it could be so simple


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.

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.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fn=InputBox("Enter 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.FolderExists(src) Then
dst = Chr(drv)+":\work\"+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?


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:\SomeDirectory\backup\"
NewPath = "d:\SomeDirectory\work\"
Prefix = "ab"
FileName = "RICK"
Suffix = "12"
FileType = ".txt"
Name Path & Prefix & FileName & Suffix & _
FileType As NewPath & FileName & FileType

Rick - MVP
Jul 17 '05 #5
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 FileSystemObject. I'm using VB6.

jenn
"Stephane Richard" <st**************@verizon.net> wrote in message news:<cN*****************@nwrdny02.gnilink.net>...
Hi Jenny,

I suggest you reference the FileSystemObject "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 FileSystemObject. 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" <je**@onlink.net> wrote in message
news:3d**************************@posting.google.c om...
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

Jul 17 '05 #6
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<-7********************@comcast.com>...
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


Thanks a bunch! - that was good -never knew it could be so simple


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.

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.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fn=InputBox("Enter 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.FolderExists(src) Then
dst = Chr(drv)+":\work\"+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?


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:\SomeDirectory\backup\"
NewPath = "d:\SomeDirectory\work\"
Prefix = "ab"
FileName = "RICK"
Suffix = "12"
FileType = ".txt"
Name Path & Prefix & FileName & Suffix & _
FileType As NewPath & FileName & FileType

Rick - MVP

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("Enter folder name from. ","Folder Move")
For drv = Asc("C") to Asc("Z")
src=Chr(drv)+":\backup\ab"+fn+"12"
If fso.FolderExists(src) Then
dst = Chr(drv)+":\work\"+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
Jul 17 '05 #7
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" <ri************@NOSPAMcomcast.net> wrote in message news:<zY********************@comcast.com>...
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("Enter folder name from. ","Folder Move")
For drv = Asc("C") to Asc("Z")
src=Chr(drv)+":\backup\ab"+fn+"12"
If fso.FolderExists(src) Then
dst = Chr(drv)+":\work\"+fn
fso.MoveFolder src, dst


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.

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 out.
Rick - MVP

Jul 17 '05 #8
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" <je**@onlink.net> wrote in message
news:3d**************************@posting.google.c om...
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" <ri************@NOSPAMcomcast.net> wrote in message

news:<zY********************@comcast.com>...
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("Enter folder name from. ","Folder Move")
For drv = Asc("C") to Asc("Z")
src=Chr(drv)+":\backup\ab"+fn+"12"
If fso.FolderExists(src) Then
dst = Chr(drv)+":\work\"+fn
fso.MoveFolder src, dst


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.

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 out.

Rick - MVP

Jul 17 '05 #9
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("Enter folder name")
If Not Trim(fn) = "" then
For drv = Asc("C") to Asc("Z")
src=Chr(drv)+":\recycled\recyclebin\abc"+fn+"123"
If fso.FolderExists(src) Then
dst = Chr(drv)+":\restored\"+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" <ri************@NOSPAMcomcast.net> wrote in message news:<yL********************@comcast.com>...
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" <je**@onlink.net> wrote in message
news:3d**************************@posting.google.c om...
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" <ri************@NOSPAMcomcast.net> wrote in message

news:<zY********************@comcast.com>...
> 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("Enter folder name from. ","Folder Move")
> For drv = Asc("C") to Asc("Z")
> src=Chr(drv)+":\backup\ab"+fn+"12"
> If fso.FolderExists(src) Then
> dst = Chr(drv)+":\work\"+fn
> fso.MoveFolder src, dst

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.
> 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 out.

Rick - MVP

Jul 17 '05 #10
> 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("Enter folder name")
If Not Trim(fn) = "" then
For drv = Asc("C") to Asc("Z")
src=Chr(drv)+":\recycled\recyclebin\abc"+fn+"123"
If fso.FolderExists(src) Then
dst = Chr(drv)+":\restored\"+fn
fso.MoveFolder src, dst
msgbox "Success"
End If
Next
msgbox "Error - try again"
End If


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

FolderName = InputBox("Enter Folder Name")
If Len(Trim$(FolderName)) 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$(FolderName) = "" 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$(FolderName)) is not zero, VB will consider it as True (which is
why I don't perform the redundant test of >0).

Rick - MVP
Jul 17 '05 #11
On 7 Aug 2003 02:14:00 -0700, Cr********@hotmail.com (Geoff) wrote:
You can check with: Dir(Path & FolderName,vbDirectory)
It will return the folders name if it exists, if not it will return a blank string.

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\USLIB.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(FileSpec$, Erm$)
Dim S$

Erm$ = ""
If InStr(FileSpec$, "\") Then
S$ = ExtractFilePath(FileSpec$)
Call MakeDir(S$, Erm$)
If Len(Erm$) = 0 Then
If DirExists(FileSpec$) = 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

Jul 17 '05 #12
On 6 Aug 2003 05:00:06 -0700, je**@onlink.net (jenny) wrote:
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.


"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
Jul 17 '05 #13
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 <be*******@yahoo.com.au> wrote in message news:<4v********************************@4ax.com>. ..
On 6 Aug 2003 05:00:06 -0700, je**@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

Jul 17 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eran Kampf | last post by:
I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a DirectoryNotFoundException saying "Could not find a...
9
by: Maziar Aflatoun | last post by:
Hi everyone, I like to export some data from the database and allow my users to store this file to their harddrive as a .txt file. Does anyone know how I would go about doing that? (without...
2
by: flat_ross | last post by:
Hi, I am in a shop where developers are required to work off of a network share. This is so that code is backed up nightly. So I am testing running an ASP.NET Web application with a Class...
11
by: ASP.NET User | last post by:
Hi I am in a shop where developers are required to work off of a networ share. This is so that code and other documentation is backed up nightly. This is outside the realm of Visual SourceSafe...
5
by: Mitchell S. Honnert | last post by:
Is there a way, given the full path of a folder on a network, that one can programatically tell if you have Read access to that folder? I have an application where the user is able to select a...
18
by: rdemyan via AccessMonster.com | last post by:
Here's my plan for creating nightly backups of the production back-end file (the IT staff in their infinite wisdom have prevented use of Windows Scheduler and users do not have administrative...
1
by: Simon | last post by:
Dear Access friends, How can I load a string with his own folder address. The following code addressed to the system folder of MS programs.
7
by: Zeb | last post by:
Hi all I've developed a shopping cart in C# and to allow moderators to upload product images, news images and downloadable PDFs, the app creates a folder for each product. I start out with the...
0
by: =?Utf-8?B?TGlhbSBNYWM=?= | last post by:
Hi Folks, I have embeded WMI scripting within a Visual Basic application to create remote shares and set permissions, I'm now moving to vb.net environment and having trouble getting my scripting...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.