[delphi]Déplacer des fichiers?

Déplacer des fichiers? [delphi] - Delphi/Pascal - Programmation

Marsh Posté le 23-09-2003 à 15:32:48    

Comment faire pour déplacer tous les fichiers d'un répertoire vers un autre, puis supprimer le répertoire source?


---------------
Mes photos : http://500px.com/endemyon
Reply

Marsh Posté le 23-09-2003 à 15:32:48   

Reply

Marsh Posté le 23-09-2003 à 16:42:42    

Deja je te conseille de procurer l excellente collection de code appellée D:Tnt url= www.d-tnt.co.uk car la reponse a ta question y est. Un exemple ?

Code :
  1. //CopyAllFiles() will copy a set of files or a directory of your choice.  
  2. // It also displays the same animation of the operation as does Windows Explorer.   
  3. //You can pass wildcards to the function.  In order to copy a directory, do not include the last  
  4. backslash. 
  5. //For example: CopyAllFiles('C:\ThisDirectory', 'C:\AnotherDirectory', False);   
  6. //The 'False' parameter tells the function to not rename files if they already exist.  
  7. // If set to 'True', the new files will have 'Copy of ...' appended to the name. }
  8. uses ShellAPI;
  9. function CopyAllFiles(sFrom, sTo: string; Protect: boolean): boolean;
  10. { Copies files or directory to another directory. }
  11. var
  12.   F: TShFileOpStruct;
  13.   ResultVal: integer;
  14.   tmp1, tmp2: string;
  15. begin
  16.   FillChar(F, SizeOf(F), #0);
  17.   Screen.Cursor := crHourGlass;
  18.   try
  19.     F.Wnd   := 0;
  20.     F.wFunc := FO_COPY;
  21.     { Add an extra null char }
  22.     tmp1    := sFrom + #0;
  23.     tmp2    := sTo + #0;
  24.     F.pFrom := PChar(tmp1);
  25.     F.pTo   := PChar(tmp2);
  26.     if Protect then
  27.       F.fFlags := FOF_RENAMEONCOLLISION or FOF_SIMPLEPROGRESS
  28.     else
  29.       F.fFlags := FOF_SIMPLEPROGRESS;
  30.     F.fAnyOperationsAborted := False;
  31.     F.hNameMappings := nil;
  32.     Resultval := ShFileOperation(F);
  33.     Result := (ResultVal = 0);
  34.   finally
  35.     Screen.Cursor := crDefault;
  36.   end;
  37. end;


 
Sachant que ta le chemin de depart il te suffit de faire un deldete et le tour est joue
 
@++
 

Reply

Marsh Posté le 23-09-2003 à 18:27:28    

Merci pour la réponse et le lien , j'ai juste remplacé FO_COPY par FO_MOVE et ça marche pile comme je le veux.


---------------
Mes photos : http://500px.com/endemyon
Reply

Marsh Posté le 23-09-2003 à 19:07:31    

[:ddr555]  
No problem pour une fois que j ai la bone reponse avant antp  :whistle:  
 [:kamool]  
 
@++

Reply

Marsh Posté le 23-09-2003 à 19:15:58    

il me semble qu,avec le move on ne peut pas déplacer un fichier d'un hd à un autre ou d'une partition à une autre...


---------------
Borland rulez: http://pages.infinit.net/borland
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed