Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File::Copy(path,path,bool) can't find source file

Status
Not open for further replies.

Wolfie7873

Technical User
Jan 15, 2004
94
0
0
US
Weird, works when the source file is in the root directory, but not otherwise...
 
Remember double backslashes in string literals with file path...
 
I didn't believe it either so i went back and checked and had some extra " where I didn't need them, but i'm still getting something weird. Now I get an exception that says, "The given path's format is not supported." What does that mean?
 
gladly:

private: System::Void newFileMenuitem_Click(System::Object * sender, System::EventArgs * e)
{
OpenFileDialog* fd = new OpenFileDialog();
fd->set_Filter(S"Head Coach Databases (*.mdb)|*.mdb|All files(*.*)|*.*");

fd->set_InitialDirectory(S"c:\\Program Files\\Aquajock Software\\Head Coach\\");
fd->set_Multiselect(false);
fd->set_Title(S"Create New Database...");
fd->set_CheckFileExists(false);

if (fd->ShowDialog() == DialogResult::OK)
{
try {
String* fname = fd->get_FileName(); if (File::Exists(fname))
{
MessageBox::Show(String::Concat(fname,S" already exists"),S"Error...");
newFileMenuitem_Click(sender, e);
return;
}
else
File::Copy(S"C:\\Program Files\\Aquajock Software\\Head Coach\\Bin\\hc_source.mdb",String::Concat(S"C:\\Program Files\\Aquajock Software\\Head Coach\\",fname),false);
return;
}
catch(Exception* ex){
MessageBox::Show(ex->Message);
newFileMenuitem_Click(sender, e);
return;
}
}
}
 
I think (havn't checked) but

Code:
      String* fname = fd->get_FileName();

will return the full pathname, e.g.

C:\\Program Files\\Aquajock Software\\Head Coach\\text.dat

Thus when you are trying to copy it is trying to copy from

C:\\Program Files\\Aquajock Software\\Head Coach\\Bin\\hc_source.mdb

to

C:\\Program Files\\Aquajock Software\\Head Coach\\C:\\Program Files\\Aquajock Software\\Head Coach\\text.dat


which is invalid.

Trying looking at your fname string.



Robert Cumming
 
You got that one right, thanks. Changed it to:

File::Copy(S"C:\\Program Files\\Aquajock Software\\Head Coach\\Bin\\hc_source.mdb",fname,false);

Which doesn't produce the same error, but now it tells me that the source file doesn't exist, even though I know that it does. Any more ideas of what to look for?

Thanks in advance
Eddie
 
Hmm, not sure?
Try putting "C:\\Program Files\\Aquajock Software\\Head Coach\\Bin\\hc_source.mdb" into a String variable for one?

Then you could try
Code:
  FILE* input;
  input = fopen ( text, "r" );
  if ( input ) 
    // file found
  else
    // file not found
  end if

Robert Cumming
 
Hmm, works now - seems that there was something wrong with the source file, so i recopied it to the Bin and everything is great. Thanks for your help!

Eddie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top