Raised This Month: $32 Target: $400
 8% 

Solved Delete file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 08-20-2021 , 10:32   Delete file
Reply With Quote #1

Hi
I wrote a plugin that saves text files in the config folder
For example
Code:
2021/08/20/18.txt
2021/08/20/19.txt
2021/08/20/20.txt
That means another file is added every hour
I want to know how to delete the file of previous hours
Code:
2021/08/20/%s.txt
So that the current clock file is not deleted and only the previous clocks are deleted
Also check that there is no file left in the past history
I hope I have given a clear explanation
__________________

Last edited by amirwolf; 08-21-2021 at 00:45.
amirwolf is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-20-2021 , 12:12   Re: Delete file
Reply With Quote #2

http://www.amxmodx.org/api/file/delete_file
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 08-20-2021 , 12:20   Re: Delete file
Reply With Quote #3

Yes, I know this, but I can not figure out how to check the date and time
__________________
amirwolf is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-20-2021 , 13:08   Re: Delete file
Reply With Quote #4

How about when you create a new one, delete the old?

When creating 2021/08/20/20, delete 2021/08/20/19

Or use a single file and over-write. Why do you need the filename dated?
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-20-2021 , 13:13   Re: Delete file
Reply With Quote #5

show what you've done !
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 08-20-2021 , 13:21   Re: Delete file
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
How about when you create a new one, delete the old?

When creating 2021/08/20/20, delete 2021/08/20/19

Or use a single file and over-write. Why do you need the filename dated?
Yes I could use a file But I prefer to delete the information of the previous hour and create a new file
__________________
amirwolf is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 08-20-2021 , 13:25   Re: Delete file
Reply With Quote #7

The temporary solution may be to delete the folder
__________________
amirwolf is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-20-2021 , 17:17   Re: Delete file
Reply With Quote #8

This will delete all files in the configs/TestFolder/ directory, except the one named '2021082020.txt'

Though, I recommend explaining your use case, as there's likely a better solution.

PHP Code:
//Usage:
DeleteFolderContents"2021082020.txt" "TestFolder" );

DeleteFolderContents( const szExcludeFile[] , const szConfigsSubFolder[] ) 
{
    new 
szDir64 ] , iDir iLen szFile32 ] , szFullFile96 ] , iDeleted;
    
    
formatexszDir[ ( iLen get_configsdirszDir charsmaxszDir ) ) ) ] , charsmaxszDir ) - iLen "/%s/" szConfigsSubFolder );
    
    if ( ( 
iDir open_dirszDir szFile charsmaxszFile ) ) ) )
    {    
        do
        {
            if ( ( 
szFile] != '.' && szFile] != '.' ) && !equaliszFile szExcludeFile ) ) 
            {
                
formatexszFullFile charsmaxszFullFile ) , "%s%s" szDir szFile );
                
delete_fileszFullFile );
                
iDeleted++;
            }
        }
        while ( 
next_fileiDir szFile charsmaxszFile ) ) )
        
close_diriDir );
    }
    else
    {
        
set_fail_state"Directory not found: %s" szDir );
    }
    
    return 
iDeleted;

__________________

Last edited by Bugsy; 08-21-2021 at 19:14.
Bugsy is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 08-20-2021 , 23:26   Re: Delete file
Reply With Quote #9

That's exactly what I wanted
It works now
Thank you
__________________
amirwolf is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 11:28   Re: Delete file
Reply With Quote #10

I updated it slightly to make it easier to use.
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode