What purpose of Pattern$ in DeleteDirectory()?

Just starting out? Need help? Post your questions and find answers here.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

What purpose of Pattern$ in DeleteDirectory()?

Post 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
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

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

Post 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.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

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

Post 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?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

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

Post by RASHAD »

Maybe

Code: Select all

path$ = "c:\deletetest"
pattern$ = "*.*"
result = DeleteDirectory(path$,pattern$)
If result <> 0
  CreateDirectory(path$)
EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

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

Post 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.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

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

Post by sec »

Thanks RASHAD and BarryG.
Post Reply