| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Invitado
|
Publicado: Mie 14 Abr, 2004 5:09 pm Asunto: Saber si está un archivo abierto?? |
|
|
¿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.  |
|
| Volver arriba |
|
 |
ikis Master


Registrado: 28 Dic 2002Mensajes: 703Ubicación: Madrid, España
|
Publicado: Mie 14 Abr, 2004 6:35 pm Asunto: |
|
|
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 |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Mie 14 Abr, 2004 6:42 pm Asunto: |
|
|
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 _________________
 |
|
| Volver arriba |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Mie 14 Abr, 2004 6:47 pm Asunto: |
|
|
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 _________________
 |
|
| Volver arriba |
|
 |
ikis Master


Registrado: 28 Dic 2002Mensajes: 703Ubicación: Madrid, España
|
Publicado: Mie 14 Abr, 2004 6:49 pm Asunto: |
|
|
 |
|
| Volver arriba |
|
 |
Invitado
|
Publicado: Mie 14 Abr, 2004 7:22 pm Asunto: |
|
|
Pues me lo expliquen q no me cosco???  |
|
| Volver arriba |
|
 |
ikis Master


Registrado: 28 Dic 2002Mensajes: 703Ubicación: Madrid, España
|
Publicado: Mie 14 Abr, 2004 7:59 pm Asunto: |
|
|
| que cosa no entiendeS? |
|
| Volver arriba |
|
 |
Invitado
|
Publicado: Mie 14 Abr, 2004 8:19 pm Asunto: |
|
|
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 |
|
 |
ikis Master


Registrado: 28 Dic 2002Mensajes: 703Ubicación: Madrid, España
|
Publicado: Mie 14 Abr, 2004 8:43 pm Asunto: |
|
|
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 |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Mie 14 Abr, 2004 9:25 pm Asunto: |
|
|
Bien Dicho IKIS, asi es verifica la funcion para cerrar un processo llamada KILLPROCESS de Diego.
saludos _________________
 |
|
| Volver arriba |
|
 |
|