Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete files
Message
De
31/12/2012 12:53:42
 
 
À
31/12/2012 11:32:39
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Divers
Thread ID:
01560963
Message ID:
01560977
Vues:
51
>Dear Experts
>
>I have a folder which has some folders and files
>
>I want to delete all those folders and files which were created before 24hours.
>
>I mean how to detect file created time and then delete them with time parameter.

This program which I call Getfilelist.prg, creates a cursor with every file in the given directory, and every subdirectory. Change the program to match your need. Scan the table, and delete every file which is to old.
**DO getfilelist WITH 'c:\*.*','DHS'

Procedure Getfilelist
   Lparameters lcFileSkeleton,lcAttributes,lcCursor
   If Pcount()<3 Or Vartype(lcCursor)#'C'
      lcCursor='curFiles'
   Endif 
   Do RecurseDirectories With lcFileSkeleton,lcAttributes,.F.,lcCursor
   Wait Clear
   Index On fullname Tag filename
   Index On filesize Tag filesize
   Index On filepath Tag filepath
   Go Top
*!*      Browse Nowait
Return Reccount()

****************************************
Procedure RecurseDirectories
   Lparameters lcFileSkeleton,lcAttributes,llKeepDirectory,lcCursor
   Local Array laDirectory[1,1]
   Local lnFileCount As Integer
   Local lnCounter As Integer
   Local lcCurrentPath As Varchar(200)
   If Empty(llKeepDirectory)
      llKeepDirectory = .F.
   Endif
   If !llKeepDirectory
      Create Cursor (lcCursor);
         (fullpath Varchar(200),filepath Varchar(200),filename varchar(80), ext varchar(4), filesize Integer,fullname Varchar(100),  ModiDate Date, ModiTime Char(16), FileAttr Char(6))
   Endif
   If Empty(lcFileSkeleton)
      lcFileSkeleton = '*.*'
   Endif
   If Empty(lcAttributes)
      lcAttributes = 'DHS'
   Endif
   lnFileCount = Adir(laDirectory,lcFileSkeleton,lcAttributes)
   lcCurrentPath = Justpath(lcFileSkeleton)
   Wait 'Processing: '+Alltrim(lcCurrentPath)+'..hang on!' Window Nowait
   If lnFileCount > 0
      For lnCounter = 1 To lnFileCount
         If !Empty(Strtran(laDirectory[lncounter,1],'.',''))
            If 'D' $ laDirectory[lncounter,5] && directory - need to recursively call!
               RecurseDirectories(Addbs(lcCurrentPath)+Addbs(Trim(laDirectory[lncounter,1]))+Justfname(lcFileSkeleton),lcAttributes,.T.,lcCursor)
            Else
               Insert Into (lcCursor) (fullpath, filepath,fullname,filename, ext, filesize,ModiDate,ModiTime,FileAttr);
                  Values (Addbs(lcCurrentPath) +  laDirectory[lncounter,1],lcCurrentPath,laDirectory[lncounter,1],Juststem(laDirectory[lncounter,1]),Justext(laDirectory[lncounter,1]),laDirectory[lncounter,2],laDirectory[lncounter,3],laDirectory[lncounter,4],laDirectory[lncounter,5])
            Endif
         Endif
      Endfor
   Endif && lnFileCount > 0
   Return && recursedirectories
Return && getfilelist
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform