Delete all files ...txt

Blitz3D Forums/Blitz3D Beginners Area/Delete all files ...txt

Lasasboogy(Posted 2003) [#1]
Im having trouble getting this right.
I want to delete all text files in one directory. Can you please help me out with the right command line to do this?
Thanks.


Tricky(Posted 2003) [#2]
I never tried it, but shouldn't
DeleteFile "*.txt"
do the job, or doesn't Blitz support that wildcards...

(Example above should if it works delete all files in the current dir)


Lasasboogy(Posted 2003) [#3]
Unfortunately I have tried that and it hasn't worked.
And I'm using blitzplus if that makes a difference.
Thanks


Tricky(Posted 2003) [#4]
Then I guess it can't be done in one command and that Blitz does not support Wild Cards... Just a moment, I have a piece of code I use in The Fairy Tale to empty the game's temp directory.... I don't think Blitz+ will have any trouble handling that piece of code

I have to note this code is directly copied so it contains a few Globals that only have effect in my game, but I'm sure you can work something with the documention and my code:

Function CleanUpTempFiles()
Local D% = ReadDir(TempFileDirectory$)
Local F$
Repeat
F$ = NextFile(D%)
If F$ = "" Then Exit
F$ = TempFileDirectory$ + F$
If FileType(F$)>0 Then DeleteFile F$
If FileType(F$)<>0 And FileType(F$)<>-1 And F$<>TempfileDirectory+"." And F$<>TempFileDirectory$+".." Then
   RuntimeError "Could not delete temp file "+F$+". File could be damaged or be made 'Read-Only'"
   EndIf
Forever
CloseDir D%
End Function



dynaman(Posted 2003) [#5]
You can try using the run command to run the operating system's delete command.

I probably have the syntax on the example below wrong...

run "del *.txt"


Tricky(Posted 2003) [#6]
run "del *.txt"


That command doesn't work at all...
I once tried it on a semiliar way, with the "ExecFile" command using the "COMSPEC" environ, but for strange reasons it didn't work out...


misth(Posted 2013) [#7]
I know this topic is old but... I just happened to have this problem myself and also cracked it.

I use recursion, because it makes things A LOT easier. So the function starts with empty input, and will recursively go through all folders and files you have in your starting folder - and deletes them.

It still has some glitches (some that I just noticed) so it doesn't always work... I'm trying to figure it out.

So, here's the code I'm using:



Hope this helps...someone! :)


virtlands(Posted 2013) [#8]
Hi misth,

That's an interesting variation. Have you tested it?

Adding recursion to a ".TXT search & destroy " function is a good idea.
Would be nice to also control how deep that recursion happens.

I recommend to start with an actual starting path as a parameter to the function.