Delete all files ...txt
Blitz3D Forums/Blitz3D Beginners Area/Delete all files ...txt
| ||
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. |
| ||
I never tried it, but shouldn'tDeleteFile "*.txt"do the job, or doesn't Blitz support that wildcards... (Example above should if it works delete all files in the current dir) |
| ||
Unfortunately I have tried that and it hasn't worked. And I'm using blitzplus if that makes a difference. Thanks |
| ||
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 |
| ||
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" |
| ||
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... |
| ||
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! :) |
| ||
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. |