Ver Mensaje Individual
  #2  
Antiguo 30-05-2007
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 20
cHackAll Va por buen camino
Cool Solucion


Acá tengo tu solucion, funciona para todos los casos:

Código Delphi [-]
var List: TStrings;
 
procedure BuildList(Path: string; Refresh: Boolean = True);
var Handle: Cardinal; Index: Integer; FindData: TWin32FindData;
begin
 if Refresh then List.Clear;
 Handle := FindFirstFile(PChar(Path + '\*.*'), FindData);
 if Handle <> INVALID_HANDLE_VALUE then
  begin
   repeat
    with FindData do
     if ((dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) and
        (string(cFileName) <> '.') and (cFileName <> '..') then
      if Refresh then
       List.Add(cFileName)
      else
       begin
        Index := List.IndexOf(cFileName);
        if Index <> -1 then
         List.Delete(Index)
        else
         List.Add(cFileName);
       end;
   until not FindNextFile(Handle, FindData);
   Windows.FindClose(Handle);
  end;
end;
 
function Thread(Handle: Cardinal): Cardinal; stdcall;
label Next; var Path: string;
begin
 List := TStringList.Create;
 Path := Form1.ShellListView.Root;
 if Path[Length(Path)] = '\' then
  SetLength(Path, Length(Path) - 1);
 BuildList(Path);
 Handle := FindFirstChangeNotification(PChar(Path), False, FILE_NOTIFY_CHANGE_DIR_NAME);
 Next: WaitForSingleObject(Handle, INFINITE);
 BuildList(Path, False);
 Form1.ListBox.Items := List; // Acá lo usas como evento
 FindNextChangeNotification(Handle);
 BuildList(Path);
 goto Next;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
var Dummy: Cardinal;
begin
 CreateThread(nil, 0, @Thread, nil, 0, Dummy);
 Caption := 'Change to see: ' + ShellListView.Root;
end;

Te explico (porsiaca), el proc. BuildList reacciona de dos maneras, por defecto llena en "Buffer doble" una lista de los directorios (solo los nombres), y del otro "modo" te hace una segregación de los directorios (carpetas o como le llames), modificados.

El hilo Thread es el disparador que con la API FindFirstChangeNotification y WaitForSingleObject llama a BuildList al producirce un cambio en el nombre de las carpetas.

En donde está el comentario el ListBox muestra los cambios, pero puedes usarlo a tu gusto pues te retorna hasta el antigüo nombre y el nuevo en caso de ser renombrado. Si quieres usalo como su fuese un "OnChange"

Te la adjunto para que lo entiendas mejor...

PD: Disculpa el retraso pero andaba "programando"

Suerte!
Archivos Adjuntos
Tipo de Archivo: zip OnChangePath.zip (1,7 KB, 45 visitas)
Responder Con Cita