cancel
Showing results for 
Search instead for 
Did you mean: 

Delete files using Wildcard not working

sarya
Frequent Contributor

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 3

RE: Delete files using Wildcard not working

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.


Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sarya
Frequent Contributor

RE: Delete files using Wildcard not working

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

RE: Delete files using Wildcard not working


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.

Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors