Subject Re: deleting files in a remote directory
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Fri, 10 Aug 2018 12:34:57 +0530
Newsgroups dbase.getting-started

On 10/08/2018 05:54, Charlie wrote:
> Hi Ken.. Does this mean there is no way to delete files from a directory unless you know the file names?
>
> Ken Mayer Wrote:
>
>> On 8/9/2018 2:46 PM, Charlie wrote:
>>> I am trying this:
>>>
>>> new File().delete("c:\dbasewin\pictures-temp\*.jpg")
>>>
>>> This works if I name a particular filer.  But it does not work this way.  I want to delete all .jpg files in the directory.
>>
>> delete() works on an individual file, as you've discovered.
>>
>> Create an array of file names (take a look at a.dir() in the online
>> help), and then loop through the array ...
>>
>> Ken
>>
>>
>> --
>> *Ken Mayer*
>> Ken's dBASE Page: http://www.goldenstag.net/dbase
>> The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
>> dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
>> dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
>

Please find below a code from help file of dir()
This will help you in getting the names of all the files in the remote
directory.
I have done a simple copy and paste for your reference. You will have to
modify it to suit your requirements

#define ARRAY_DIR_NAME 1
#define ARRAY_DIR_SIZE 2
#define ARRAY_DIR_DATE 3
#define ARRAY_DIR_TIME 4
#define ARRAY_DIR_ATTR 5
aFiles = new Array() // Array will be resized as needed
nFiles = aFiles.dir("\*.*", "HS") // Include Hidden and System files
for nFile = 1 to nFiles
    ? aFiles[ nFile, ARRAY_DIR_NAME ]
    ?? aFiles[ nFile, ARRAY_DIR_ATTR ] at 25
endfor


For me the following alteration works very well
You may have to add the paths to file names.
    aFiles = new Array() // Array will be resized as needed
    nFiles = aFiles.dir("month_*.sql")

    if nFiles > 0
       for temp = 1 to nFILES
          delete file &aFiles[ temp, ARRAY_DIR_NAME ]
       endfor
    endif

Regards
Akshat