Page 1 of 1

What purpose of Pattern$ in DeleteDirectory()?

Posted: Tue Apr 19, 2022 3:19 am
by sec
hi
DeleteDirectory()

Syntax

Result = DeleteDirectory(Directory$, Pattern$ [, Mode])

Pattern$ A pattern for deleting files within the directory. For example: "*.*" will delete any files in the directory. "*.exe" will delete only the .exe files. By default, a null Pattern$ ("") will delete all the files.
follow the help, two commands are different?
DeleteDirectory("C:\test\","*.bat",#PB_FileSystem_Force)
DeleteDirectory("C:\test\","",#PB_FileSystem_Force)

but they delete "test" dir in both case, so what purpose of Pattern$ in DeleteDirectory()?

thanks

Re: What purpose of Pattern$ in DeleteDirectory()?

Posted: Tue Apr 19, 2022 6:02 am
by BarryG
If the directory is empty after deleting the matching files, then the directory also gets deleted (as expected).

Add another file in there that doesn't match the pattern, and only the pattern-matched files will be deleted.

Re: What purpose of Pattern$ in DeleteDirectory()?

Posted: Tue Apr 19, 2022 10:08 am
by sec
BarryG wrote: Tue Apr 19, 2022 6:02 am If the directory is empty after deleting the matching files, then the directory also gets deleted (as expected).

Add another file in there that doesn't match the pattern, and only the pattern-matched files will be deleted.
thanks, my mistake usage then.

any trick to delete all files w/o delete dir?

Re: What purpose of Pattern$ in DeleteDirectory()?

Posted: Tue Apr 19, 2022 11:58 am
by RASHAD
Maybe

Code: Select all

path$ = "c:\deletetest"
pattern$ = "*.*"
result = DeleteDirectory(path$,pattern$)
If result <> 0
  CreateDirectory(path$)
EndIf

Re: What purpose of Pattern$ in DeleteDirectory()?

Posted: Tue Apr 19, 2022 12:59 pm
by BarryG
sec wrote: Tue Apr 19, 2022 10:08 amany trick to delete all files w/o delete dir?

Code: Select all

DeleteDirectory("C:\test\","",#PB_FileSystem_Force|#PB_FileSystem_Recursive)
CreateDirectory("C:\test\")
That's how I've done it for years.

Re: What purpose of Pattern$ in DeleteDirectory()?

Posted: Wed Apr 20, 2022 12:09 am
by sec
Thanks RASHAD and BarryG.