 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
swansnow Guest
|
Posted: Thu Sep 15, 2005 6:50 pm Post subject: "Access denied" on file copy |
|
|
I'm trying to copy a file from one folder to another on a machine that
is located on the internal network. Both folders are on that machine. I
can map a network drive to that machine, and manually copy files, but
when my program gets an "access denied" error (error code 5) when I try
to copy using the CopyFile function.
I can read from that machine, and I can create a folder with
ForceDirectories.
Does anybody have any ideas on the problem here? What settings might
need to be checked on the network machine? The general user settings
have no restrictions for all users. What permission does a Delphi
program run with?
The network machine is running Windows 2000 Server. My machine is
running Windows 2000.
Thanks in advance...
-Corinna
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Thu Sep 15, 2005 7:33 pm Post subject: Re: "Access denied" on file copy |
|
|
swansnow wrote:
| Quote: | I'm trying to copy a file from one folder to another on a machine that
is located on the internal network. Both folders are on that machine. I
can map a network drive to that machine, and manually copy files, but
when my program gets an "access denied" error (error code 5) when I try
to copy using the CopyFile function.
|
Is your path correct? What does the format of your path look like?
| Quote: | What permission does a Delphi program run with?
|
The same permission as the user.
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
swansnow Guest
|
Posted: Thu Sep 15, 2005 7:44 pm Post subject: Re: "Access denied" on file copy |
|
|
| Quote: | Is your path correct? What does the format of your path look like?
|
(btw, I'm using Google, sorry if the formatting is strange)
I have this problem elsewhere in my program, too, so I think it has
something to do with the network or the remote machine, because when I
try to access local folders to do the copying there is no problem.
connDataDir is a connection object, so getConnectionPath returns
something like J:appdataDirsample and newDir ends up being
something like J:appdataDirnewFolder I've verified this by looking
at the value of the variables at runtime.
ForceDirectories succeeds, but CopyFile doesn't. The file being copied
is not being used, so it isn't locked.
The CopyFile is trying to copy the file sample.add from the sample
folder to the newFolder folder.
===
path := leftStr(connDataDir.getConnectionPath, LastDelimiter('',
connDataDir.getConnectionPath));
newDir := path + edFolder.Text;
forceDirectories(newDir);
{Copy data dictionary files into new folder}
error := false;
path := connTmp.GetConnectionPath;
if not CopyFile(PChar(path + 'sample.add'), PChar(newDir), False)
then
ShowMessage('File not copied, error code = '+
IntToStr(GetLastError));
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Thu Sep 15, 2005 8:06 pm Post subject: Re: "Access denied" on file copy |
|
|
swansnow wrote:
| Quote: | path := leftStr(connDataDir.getConnectionPath, LastDelimiter('',
connDataDir.getConnectionPath));
newDir := path + edFolder.Text;
forceDirectories(newDir);
{Copy data dictionary files into new folder}
error := false;
path := connTmp.GetConnectionPath;
if not CopyFile(PChar(path + 'sample.add'), PChar(newDir), False)
|
Odd, the last line assumes that Path has no trailing backslash. The code
that sets newDir assumes that Path has a trailing backslash. Which is
it? I think that this is what is causing the problem.
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Fri Sep 16, 2005 8:06 am Post subject: Re: "Access denied" on file copy |
|
|
On 15 Sep 2005 12:44:43 -0700, "swansnow"
<schultz (AT) harlingen (DOT) isd.tenet.edu> wrote:
<snip>
| Quote: |
The CopyFile is trying to copy the file sample.add from the sample
folder to the newFolder folder.
===
path := leftStr(connDataDir.getConnectionPath, LastDelimiter('',
connDataDir.getConnectionPath));
newDir := path + edFolder.Text;
forceDirectories(newDir);
{Copy data dictionary files into new folder}
error := false;
path := connTmp.GetConnectionPath;
if not CopyFile(PChar(path + 'sample.add'), PChar(newDir), False)
then
ShowMessage('File not copied, error code = '+
IntToStr(GetLastError));
|
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
Note: the second parameter is a full File Name
- not just a Path or Directory
|
|
| Back to top |
|
 |
alanglloyd@aol.com Guest
|
Posted: Fri Sep 16, 2005 10:53 am Post subject: Re: "Access denied" on file copy |
|
|
The final backslash problem is always with us. I deal with it using two
techniques ...
1 Variable names for values which should have a trailing backslash are
????Path, while those which should not have a trailing backslash are
????Dir.
2 Have two functions ...
function EnsureNoBackslash(ADir : string) : string;
var
i : integer;
begin
i := Length(ADir);
while (ADir[i] = '') do
Dec(i);
Result := Copy(ADir, i);
end;
function EnsureBackslash(APath : string) : string;
begin
Result := EnsureNoBackslash(APath) + '';
end;
.... and use them appropriately.
Alan Lloyd
|
|
| Back to top |
|
 |
swansnow Guest
|
Posted: Fri Sep 16, 2005 4:49 pm Post subject: Re: "Access denied" on file copy |
|
|
| Quote: | Odd, the last line assumes that Path has no trailing >backslash. The code
that sets newDir assumes that Path has a trailing >backslash.
|
GetConnectionPath does not end in a slash. So the first statement
using leftStr leaves path with a slash, because LastDelimiter gives you
the index of the character, and so leftStr includes that character --
so I can append the folder name to it. The second use of path, in
CopyFile, is appropriate because it doesn't have a slash.
I verified that in the debugger, so that can't be the problem.
However, J French suggested that I need to use the filename, not just
the path. That's probably the problem. I'll try that.
Thanks!
-Corinna
|
|
| Back to top |
|
 |
swansnow Guest
|
Posted: Fri Sep 16, 2005 4:52 pm Post subject: Re: "Access denied" on file copy |
|
|
| Quote: | However, J French suggested that I need to use the >filename, not just
the path.
|
Yep, that was it. Boy, do I feel dumb! Thank you for keeping me from
pulling out my hair chasing down gremlins...
-Corinna
|
|
| Back to top |
|
 |
Jamie Guest
|
Posted: Sat Sep 17, 2005 4:04 am Post subject: Re: "Access denied" on file copy |
|
|
swansnow wrote:
| Quote: | I'm trying to copy a file from one folder to another on a machine that
is located on the internal network. Both folders are on that machine. I
can map a network drive to that machine, and manually copy files, but
when my program gets an "access denied" error (error code 5) when I try
to copy using the CopyFile function.
I can read from that machine, and I can create a folder with
ForceDirectories.
Does anybody have any ideas on the problem here? What settings might
need to be checked on the network machine? The general user settings
have no restrictions for all users. What permission does a Delphi
program run with?
The network machine is running Windows 2000 Server. My machine is
running Windows 2000.
Thanks in advance...
-Corinna
if your using unc naming then i think you need to use the double "\" |
after the name for the root path of the file name.
--
Real Programmers Do things like this.
http://webpages.charter.net/jamie_5
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Sat Sep 17, 2005 9:29 am Post subject: Re: "Access denied" on file copy |
|
|
On 16 Sep 2005 09:52:29 -0700, "swansnow"
<schultz (AT) harlingen (DOT) isd.tenet.edu> wrote:
| Quote: | However, J French suggested that I need to use the >filename, not just
the path.
Yep, that was it. Boy, do I feel dumb! Thank you for keeping me from
pulling out my hair chasing down gremlins...
|
That is the problem with the APIs
- one really needs to peer at them to determine what the parameters
are supposed to be
I always check the Win32 Programmer's Reference Help File first, then
if I've any doubt I cheat and look at an excellent VB API Guide (which
contains small runnable examples)
- it is quite funny checking C and VB resources to pin down parameters
for a Delphi App
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|