RESPUESTA A LA PREGUNTA 10652 - POWER BUILDER ¿ Como copiar un archivo ? Primero declara la sig. funcion externa: FUNCTION Boolean CopyFileA(String lpExistingFileName, String lpNewFileName, & Boolean bFailIfExists) Library "kernal32" Agrega el sig. Script: boolean lb_Success string ls_FromFile, ls_ToFile ls_FromFile = "C:\temp\origen.txt" ls_ToFile = "C:\otro_dir\destino.txt" o el mismo nombre de archivo lb_Success = CopyFileA(ls_FromFile, ls_ToFile, False) IF not lb_Success THEN // function call failed END IF - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Mover Archivo Este truco consiste simplemente en mover el nombre de un fichero a otro nombre. FUNCTION BOOLEAN MoveFileA(STRING oldfile, STRING newfile) LIBRARY "Kernel32.dll" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Determinar en que directorio se ejecuta mi aplicación Primero, hay que declarar la siguiente función externa: Function uLong GetModuleFileName(Int hinstModule, Ref String lpszPath, uLong cchPath) Library "kernel32.dll" Entonces añade el siguiente script. Date cuenta que pasando un nulo indica la aplicación actual (es decir, la tuya). Puedes especificar otro EXE en ejecución para obtener su directorio (como por ejemplo, word.exe). Integer li_RC String la_AppPath, ls_Null ls_AppPath = space(256) SetNull (ls_Null) li_RC = GetModuleFileName(ls_Null, ls_AppPath, 256) If (li_RC = 0) Then ls_AppPath = "" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Obtener el tamaño del disco y el espacio libre en clusters Es fácil convertirlo luego a bytes. // ls_drive = "C:\" // GetDiskFreeSpace(ls_drive, ll_SectorsPerCluster, ll_bytesPerSector, ll_FreeClusters, ll_TotalClusters) // ll_BytesPerCluster = ll_BytesPerSector * ll_SectorsPerCluster // ll_TotalDiskBytes = ll_BytesPerCluster + ll_TotalClusters // ll_FreeDiskBytes = ll_BytesPerCluster + ll_FreeClusters Function Boolean GetDiskFreeSpaceA(String lpRootPathName, Ref Long lpSectorsPerCluster, Ref Long lpBytesPerCluster, Ref Long lpNumberOfFreeClusters, Ref Long lpTotalNumberOfClusters) library "Kernel32.dll" Alias For "GetDiskFreeSpace" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Obtener el tipo de unidad de disco Usa la tabla de códigos de debajo: Bit Decimal Descripción 2 2 Disco Removible (p.e. un disquete) 3 4 Disco Fijo (p.e. un disco duro) 4 8 Remoto / Unidad de Red 5 16 Unidad de CD Rom 6 32 Disco RAM (Localización en memoria para actuar como un disco) // Función: Mod (Integer(lul_RC / li_decimal_value), 2) > 0 // ls_drive = "C:\" // lul_RC = GetDriveTypeA(ls_drive) // Normalmente retorna 4, o disco fijo. // If (Mod (Integer(lul_RC /4), 2) > 0) Then MessageBox("Hola!", "Esto es un disco duro") Function uLong GetDriveTypeA(String lpRootName) library "Kernel32.dll" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Crear un nuevo directorio Esta API requiere que antes definas una estructura y definas sus atributos. Define la estructura como sigue: Type os_SecAttr from structure Unsigned Long Length String Description Boolean Inherit end Type Define los atributos como sigue: lstr_Security.Length = 7 SetNull(ls_Security.Description) ls_Security.Inherit = False Function Boolean CreateDirectoryA(Ref String lpPathName, Ref os_SecAttrib lpSecurityAttributes) library "Kernel32.dll" Alias for "CreateDirectory" // Devuelve el directorio actual en lpBuffer // ls_dir = space(260) // GetCurrentDirectory(ls_dir, 260) Function uLong GetCurrentDirectoryA(uLong nBufferLength, Ref String lpBuffer) library "Kernel32.dll" Alias for "GetCurrentDirectory" // Coloca el directorio actual // ls_dir = "C:\Windows" // SetCurrentDirectory(ls_dir) Function Boolean SetCurrentDirectoryA(Ref String lpPathName, uLong uSize) library "Kernel32.dll" Alias for "SetCurrentDirectory" // Devuelve el directorio de Windows (normalmente c:\windows) en lpBuffer // ls_dir = 260 // GetWindowsDirectory(ls_dir, 260) Function uLong GetWindowsDirectoryA(Ref String lpBuffer, uLong uSize) library "Kernel32.dll" Alias for "GetWindowsDirectory" // Borra el directorio especificado // ls_dir = "C:\Windows" // RemoveDirectory(ls_dir) Function Boolean RemoveDirectoryA(Ref String lpPathName) library "Kernel32.dll" Alias for "RemoveDirectory" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Obtener el numero serie del disco duro Declare la Local external function FUNCTION long VolSerialNum (string lpRootPathName, string pVolumeNameBuffer, long nVolumeNameSize, REF long lpVolumeSerialNumber, long lpMaximumComponentLength, long lpFileSystemFlags, string lpFileSystemNameBuffer, long nFileSystemNameSize) LIBRARY "kernel32.dll" ALIAS FOR "GetVolumeInformationA" //Inicia codigo para obtener el numero de serie del disco duro y validar la terminal String cad1,cad2,unidad,raz_ter,raz_usu,cla_usu Long numSerie,longitud,flag unidad = "C:\" numSerie = 0 VolSerialNum(unidad, cad1, 256, numSerie, longitud, flag, cad2, 256) sle_numero.text = string(numSerie) Adolfo Chairez achairez@lajat.com.mx