Forum Discussion

sarya's avatar
sarya
Frequent Contributor
14 years ago

Delete files using Wildcard not working

Hi,



I am trying to delete file "c:\Bun272010-06-02T141405.PDF" where the portion after the letter 'T' --'141405' in the filename is the file creation time and this keeps changing whenever the file is created so it cannot be hard-coded.

I tried the codes below using wildcard but that none of them works to delete the files..

if (fs.FileExists('c:\\Bun27' + r2wdate + 'T*.pdf')) fs.DeleteFile('c:\\Bun27' + r2wdate + 'T*.pdf');


(fs.FileExists('c:\\Bun27' + r2wdate + 'T*.pdf')) fs.DeleteFile('c:\\Bun27' + r2wdate + 'T*.pdf');

if (fs.FileExists('c:\\Bun27' + r2wdate + '*.pdf')) fs.DeleteFile('c:\\Bun27' + r2wdate + '*.pdf');


if (fs.FileExists('c:\\*.pdf')) fs.DeleteFile('c:\\*.pdf');



Thanks,

Sumedha

3 Replies

  • Hi Sumedha,


    You can use the script below to delete the files:



    aqFileSystem.DeleteFile('c:\\Bun27' + r2wdate + 'T*.pdf');

    aqFileSystem.DeleteFile('c:\\Bun27' + r2wdate + 'T*.pdf');

    aqFileSystem.DeleteFile('c:\\Bun27' + r2wdate + '*.pdf');


    Please refer to the "aqFileSystem.DeleteFile" article to learn more about the aqFileSystem.DeleteFile method.

  • sarya's avatar
    sarya
    Frequent Contributor
    Hi Allen,



    Thanks for the suggestion.I saw that it works without using  'if' statement but with  'if' statement ,does not. Is there some specific reason for that. Can't we use wildcards in 'aqFileSystem.Exists' ?



    Thanks,

    Sumedha

  • Hi Sumedha,





    Wildcards are not supported in the aqFileSystem.Exists method. See the "aqFileSystem.Exists" article for details.





    You can use the aqFileSystem.FindFiles method to find the files whose names will meet the specified search pattern (you can use wildcards there) and delete them. Please refer to the "aqFileSystem.FindFiles" article fore more information.