 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
ailis Ens


Registrado: 12 Nov 2002Mensajes: 48
|
Publicado: Mie 10 Dic, 2003 12:39 pm Asunto: no intentar abrir un fichero que no esiste |
|
|
Hola a tod@s, ¿como puedo evitar el error, si el programa intenta abrir un fichero que no existe???
Un saludo y gracias,
Ailis |
|
| Volver arriba |
|
 |
ikis Master


Registrado: 28 Dic 2002Mensajes: 703Ubicación: Madrid, España
|
Publicado: Mie 10 Dic, 2003 12:55 pm Asunto: |
|
|
| Código: | if (FileExists(archivo))
{
//abrir archivo
} |
|
|
| Volver arriba |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Jue 11 Dic, 2003 1:07 am Asunto: |
|
|
Esto fue Sacado de la ayuda de builder espero te sirva, es igual al anterior, pero con un cuadro de dialogo, si el archivo existe, se genera un respaldo (*.bak)
| Código: |
The following example uses a button, a string grid, and a Save dialog box on a form. When the button is clicked, the user is prompted for a filename. When the user clicks OK, the contents of the string grid are written to the specified file. Additional information is also written to the file so that it can be read easily with the FileRead function.
#include <dir.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char szFileName[MAXFILE+4];
int iFileHandle;
int iLength;
if (SaveDialog1->Execute())
{
if (FileExists(SaveDialog1->FileName))
{
fnsplit(SaveDialog1->FileName.c_str(), 0, 0, szFileName, 0);
strcat(szFileName, ".BAK");
RenameFile(SaveDialog1->FileName, szFileName);
}
iFileHandle = FileCreate(SaveDialog1->FileName);
// Write out the number of rows and columns in the grid.
FileWrite(iFileHandle, (char*)&(StringGrid1->ColCount), sizeof(StringGrid1->ColCount));
FileWrite(iFileHandle, (char*)&(StringGrid1->RowCount), sizeof(StringGrid1->RowCount));
for (int x=0;x<StringGrid1->ColCount;x++)
{
for (int y=0;y<StringGrid1->RowCount;y++)
{
// Write out the length of each string, followed by the string itself.
iLength = StringGrid1->Cells[x][y].Length();
FileWrite(iFileHandle, (char*)&iLength, sizeof
(iLength));
FileWrite(iFileHandle, StringGrid1->Cells[x][y].c_str(), StringGrid1->Cells[x][y].Length());
}
}
FileClose(iFileHandle);
}
} |
Espero te sirva... _________________
 |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|