Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

Saber si está un archivo abierto??

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: Saber si está un archivo abierto?? Responder citando

¿Como puedo saber si un documento en pdf,word,.. está abierto?

Me gustaría saber como comprobar si está abierto el archivo porque si está abierto hago una cosa y sino otra.

Un saludo y gracias de antemano. Wink
Volver arriba
Mensaje    Asunto: Responder citando

no se si te sirva, pero si intentas borrarlo o moverlo, de seguro no podras si esta abierto.

Usando en forma correcta un try .. catch podrias detectar ambas condiciones.



atte
_________________
Adrián

http://adrian.org.ar
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mensaje    Asunto: Responder citando

Tambien puedes hacerlo, al intentar abrirlo en modo agregar si te deja esta libre y si no esta habierto por otra apliacion.
este codigo esta en la ayuda de builder

Código:
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

int main(void)
{
   int handle;
   char msg[] = "Hello world";

   if ((handle = _rtl_open("TEST.$$$", O_RDWR)) == -1)
   {
      perror("Error:");
      return 1;
   }
   _rtl_write(handle, msg, strlen(msg));
   _rtl_close(handle);
   return 0;
}


las funciones pueden ser _rtl_open, que puede que te interesa
Código:

Return Value

On success:_rtl_open returns a non-negative integer (the file handle). The file pointer, which marks the current position in the file, is set to the beginning of the file.

On error, it returns -1 and sets the global variable errno to one of the following values:

EACCES   Permission denied
EINVACC   Invalid access code
EMFILE   Too many open files
ENOENT   Path or file not found

puedeser una solucion o la que dice IKIS, si lo puedes mover, o borrar
_________________
Cool
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

tambien esta esto
Código:
Header File

io.h

Category

Input/output Routines

Prototype

int access(const char *filename, int amode);

int _waccess(const wchar_t *filename, int amode);

Description

Determines accessibility of a file.

access checks the file named by filename to determine if it exists, and whether it can be read, written to, or executed.

The list of amode values is as follows:

06   Check for read and write permission
04   Check for read permission
02   Check for write permission
01   Execute (ignored)
00   Check for existence of file

All existing files have read access (amode equals 04), so 00 and 04 give the same result. Similarly, amode values of 06 and 02 are equivalent because under Win32 write access implies read access.

If filename refers to a directory, access simply determines whether the directory exists.

Return Value

If the requested access is allowed, access returns 0; otherwise, it returns a value of -1, and the global variable errno is set to one of the following values:

ENOENT   Path or file name not found
EACCES   Permission denied

y el ejemplo es este
Código:

 #include <stdio.h>
 #include <io.h>

 int file_se_puede_leer(char *filename);

 int main(void)
 {
   printf("Does NOTEXIST.FIL exist: %s\n",
          file_se_puede_leer("NOTEXISTS.FIL") ? "YES" : "NO");
   return 0;
 }

 int file_se_puede_leer(char *filename)
 {
   return (access(filename, 2) == 2);//02   Check for write permission

 }

Cambiado los valores
_________________
Cool
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

Exclamation
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mensaje    Asunto: Responder citando

Pues me lo expliquen q no me cosco??? Shocked
Volver arriba
Mensaje    Asunto: Responder citando

que cosa no entiendeS?
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mensaje    Asunto: Responder citando

Mejor como puedo cerrar un archivo q está abierto, vamos q si está abierto lo cierre y sino que no haga nada. Eso también me vale.
Grasias.
Volver arriba
Mensaje    Asunto: Responder citando

creo q no puedes hacer eso. En todo caso deberias cerrar el proceso que lo mantiene abierto, tal vez te funcione.

Fijate en la parte de Tips & Tricks el KillProcess de El Diego, un argentino anclao en Paris...


Ultima edición por ikis el Mie 14 Abr, 2004 9:35 pm, editado 1 vez
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mensaje    Asunto: Responder citando

Bien Dicho IKIS, asi es verifica la funcion para cerrar un processo llamada KILLPROCESS de Diego.

saludos
_________________
Cool
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mostrar mensajes de anteriores:   
Cambiar a:  
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


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.