Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #4  
Antiguo 10-03-2008
fide fide is offline
Miembro
 
Registrado: oct 2006
Posts: 331
Poder: 18
fide Va por buen camino
Aqui esta el codigo para los que no tengan acceso a la pagina

Código Delphi [-]
procedure SplitFile(FileName : TFileName; FilesByteSize : Integer) ;
// FileName == file to split into several smaller files
// FilesByteSize == the size of files in bytes
var
   fs, ss: TFileStream;
   cnt : integer;
   SplitName: String;
begin
   fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite) ;
   try
     for cnt := 1 to Trunc(fs.Size / FilesByteSize) + 1 do
     begin
       SplitName := ChangeFileExt(FileName, Format('%s%d', ['._',cnt])) ;
       ss := TFileStream.Create(SplitName, fmCreate or fmShareExclusive) ;
       try
         if fs.Size - fs.Position < FilesByteSize then
           FilesByteSize := fs.Size - fs.Position;
         ss.CopyFrom(fs, FilesByteSize) ;
       finally
         ss.Free;
       end;
     end;
   finally
     fs.Free;
   end;
end;

Note: a 3 KB file 'myfile.ext' will be split into 'myfile._1', 'myfile._2','myfile._3' if FilesByteSize parameter equals 1024 (1 KB).

procedure MergeFiles(FirstSplitFileName, OutFileName : TFileName) ;
// FirstSplitFileName == the name of the first piece of the split file
// OutFileName == the name of the resulting merged file
var
   fs, ss: TFileStream;
   cnt: integer;
begin
   cnt := 1;
   fs := TFileStream.Create(OutFileName, fmCreate or fmShareExclusive) ;
   try
     while FileExists(FirstSplitFileName) do
     begin
       ss := TFileStream.Create(FirstSplitFileName, fmOpenRead or fmShareDenyWrite) ;
       try
         fs.CopyFrom(ss, 0) ;
       finally
         ss.Free;
       end;
       Inc(cnt) ;
       FirstSplitFileName := ChangeFileExt(FirstSplitFileName, Format('%s%d', ['._',cnt])) ;
     end;
   finally
     fs.Free;
   end;
end;

Uso:

Para trozear
SplitFile('c:\UnaImagen.bmp', 1024) ; //picar en archivos de 1 KB.

Para empatar
MergeFiles('C:\UnaImagen._1','C:\UnaImagenEmpatada.bmp') ;
~~~~~~~~~~~~~~~~~~~~~~~~~
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Programa a trozos angelp4492 Varios 6 21-12-2007 01:06:19
Me gustaría conseguir trozos de código Delphi o Snippets kbaby Varios 9 06-12-2007 17:51:13
TreeView, no se ve nodo seleccionado al picar sobre otro componente. Mannu C++ Builder 1 26-11-2007 11:09:17
Obtener un fichero adjunto a un nodo de un fichero XML muntasil Internet 0 18-07-2006 12:57:57
Manejar Trozos de BMP Deiv Gráficos 13 03-07-2006 14:32:54


La franja horaria es GMT +2. Ahora son las 23:43:10.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi