Error in CreateFolder()?

A

anjelone

Hi.

When I use CreateFolder() to create a folder with a space at the end,
it creates the folder successfully, but still errors out with a "Path
not Found" error.

For example:
<%
Dim strCurrentPath

strCurrentPath = "c:\test folder \

If Not oFO.FolderExists(strCurrentPath) Then
oFO.CreateFolder(strCurrentPath) 'Errors on this line.
End If
%>

After the folder is created, it cannot be deleted or renamed
immediately. I think there still must be some process attached. The
error when trying to delete it is: "Cannot delete file: Cannot read
from the source file or disk."

I need to be able to leave the space in for now.

Any ideas on why this occurs?

Thanks!
 
A

anjelone

Just as a follow on, I can get around this by adding "on error" around
the createFolder(), but I'd rather get to the bottom of the error.

Here is an example of something I would do:

<%
Dim strCurrentPath
Dim strErrNum, strErrMessage

strCurrentPath = "c:\test folder \

If Not oFO.FolderExists(strCurrentPath) Then
On Error Resume Next
oFO.CreateFolder(strCurrentPath)
If Not oFO.FolderExists(strCurrentPath) Then
strErrNum = Err.number
strErrMessage = Err.Description
End If
On Error GoTo 0
If Len(strErrMessage) > 0 Then
Err.Raise strErrNum, "CreateFolder(), strErrMessage
End If
End If
%>
 
A

anjelone

After some investigation, it appears that if you leave off the trailing
"\" on the path, the folder gets created successfully with no error,
and the trailing space gets stripped off.

Unfortunately, with FileExists() if you are looking for "c:\test
\folder\test.txt" it won't strip and it won't match.

On a brigher note (slightly) this is taken care of in asp.net with all
trailing spaces removed on exists() and createfolder() with or without
the final "\".
 
A

anjelone

We use user input project names to create folders and then reference
those project names to read from those folders. This is a legacy aspect
of the system that will definitely change, but it is so integrated at
this point that it needs to stay for the time being.

I'm hoping it will be converted to a better system in the next 2
months, but the show must go on until then.

Anyway, it is interesting to see the inconsistencies and I can't be the
first to be bitten by it...
 
S

Slim

I still don't understand

Why cant you just use Trim(folderName) to get rid of the space?
 
A

anjelone

When beginning development, you are correct. Just use Trim or something
similar.

*Code written w/o vars for ease.
So I:
CreateFolder(TRIM("c:\test "))
Then I want to put another folder in that first one from a different
section of the site at a different time:
CreateFolder(TRIM("c:\test \test2 "))

Ooops!
I trimmed the first CreateFolder so now when creating the second I have
to trim both...
CreateFolder(TRIM("c:\test ") + TRIM("\test2 "))

And what happens when I use FileExists or FolderExists? Same
thing....Trim's on everything.

In my case I would have to add that in approximately 200 files of code,
multiple times in some of them.
For a set of code used in 16 seperate production sites, that is a lot
of changing and a whole lot of testing.
Not to mention that file uploading, downloading and manipulation are
integral to our product so if something went wrong with that it would
be a major issue.

Again, "I'm hoping it will be converted to a better system in the next
2 months, but the show must go on until then."

Plus, I'm not condoning this "trailing space" practice in any way, mind
you, it is simply the code I'm dealing with. You must understand the
position of walking into old badly developed code and having to deal
until you can correct it...
 
S

Slim

anjelone said:
When beginning development, you are correct. Just use Trim or something
similar.

*Code written w/o vars for ease.
So I:
CreateFolder(TRIM("c:\test "))
Then I want to put another folder in that first one from a different
section of the site at a different time:
CreateFolder(TRIM("c:\test \test2 "))

Ooops!
I trimmed the first CreateFolder so now when creating the second I have
to trim both...
CreateFolder(TRIM("c:\test ") + TRIM("\test2 "))

And what happens when I use FileExists or FolderExists? Same
thing....Trim's on everything.

In my case I would have to add that in approximately 200 files of code,
multiple times in some of them.
For a set of code used in 16 seperate production sites, that is a lot
of changing and a whole lot of testing.

where are the stored?
lop though them

using the 1 line of code including trim?
 
A

anjelone

Folder names are project names, task names, contract names, review
names, location names and report names that users input. All files
associated with all those things go into the folder named for that
thing.
 
S

Slim

anjelone said:
Folder names are project names, task names, contract names, review
names, location names and report names that users input. All files
associated with all those things go into the folder named for that
thing.

I'm mean in a programming sense, you must have them in a database or a array
or something,

there for you only have to use Trim once and loop though your collection
 
A

anjelone

The users still have the ability in a bunch of places to hand enter the
names so that it all gets messed up again.
And we pull from other datasources where there also have been trailing
spaces.
Its quite a mess really.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top