Raised This Month: $51 Target: $400
 12% 

Solved Delete file


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-21-2021 , 13:15   Re: Delete file
Reply With Quote #11

You can also use this stock it will remove old folder content depending on the passed iTimeStamp...

for example this will remove all files EXCEPT the ones that were created an hour ago...

Code:
ExterminateFolderContent("myStupidFoler/", (get_systime() - (60 * 60)));


PHP Code:
stock ExterminateFolderContent(const szFolder[]="myStupidFoler/"iTimeStamp=0)
{
    if(
iTimeStamp <= 0iTimeStamp get_systime();

    new 
iDirszFile32 ] , szFullFile128 ], iDeleted;

    if ( ( 
iDir open_dirszFolder szFile charsmaxszFile ) ) ) )
    {
        do
        {
            
formatexszFullFile charsmaxszFullFile ) , "%s%s" szFolder szFile );
            if ( 
GetFileTime(szFullFileFileTime_Created) < iTimeStamp 
            {
                if( 
delete_fileszFullFile ) == )
                   
iDeleted++;
            }
        }
        while ( 
next_fileiDir szFile charsmaxszFile ) ) )

        
        
close_diriDir );
        return 
iDeleted;
    }
    else
    {
        
log_errorAMX_ERR_NOTFOUND"Directory's not found: %s" szFolder );
        return -
1;
    }

    return 
0;

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-21-2021 at 15:34.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 15:21   Re: Delete file
Reply With Quote #12

Good idea.. do you know what GetFileTime() returns when '.' and '..' is the filename? Does it return 0, -1, or error?

It's a function..its only a stock if you define it as a stock, typically used in include files, to avoid compiling it into the binary if it's not used in plugin code.
__________________

Last edited by Bugsy; 08-21-2021 at 15:30.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-21-2021 , 15:33   Re: Delete file
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
Good idea.. do you know what GetFileTime() returns when '.' and '..' is the filename? Does it return 0, -1, or error?
i didn't really test it, but i am assuming it returns 0 or below on failure, on success it will return the timestamp depending on the second given argument...

Quote:
Originally Posted by Bugsy View Post
It's a function..its only a stock if you define it as a stock, typically used in include files, to avoid compiling it into the binary if it's not used in plugin code.
yeah i know it would be better if it was within the includes...
__________________
@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
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 15:44   Re: Delete file
Reply With Quote #14

The windows library has the below, so it would be skipped. I recommend testing it before handing it off to the OP.

Code:
Return value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.
__________________

Last edited by Bugsy; 08-21-2021 at 15:45.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-21-2021 , 16:24   Re: Delete file
Reply With Quote #15

this seems to be an old topic

https://forums.alliedmods.net/showpo...7&postcount=14
__________________
@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
Reply



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 08:51.


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