Raised This Month: $ Target: $400
 0% 

[Feature Request] file_copy


  
 
 
Thread Tools Display Modes
Author Message
johnjg75
Veteran Member
Join Date: Mar 2004
Location: Delaware
Old 05-28-2005 , 23:39   [Feature Request] file_copy
#1

Hey, this is just a suggestion to add to the core. I would like a file_copy function like
Code:
file_copy(source,destination)
I really would appreciate it. Thanks.
__________________
johnjg75 is offline
Send a message via AIM to johnjg75 Send a message via MSN to johnjg75 Send a message via Yahoo to johnjg75
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-29-2005 , 08:38  
#2

You could write a stock using a buffered read_file / write_file (or however they were called)
__________________
hello, i am pm
PM is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 05-29-2005 , 09:08  
#3

Yes or even fread/fwrite (the c style things)
Look in file.inc

Edit, here is something:

Code:
stock bool:file_copy(SOURCE[], TARGET[], error[], const ERRORLEN, const bool:REPLACE_TARGET = false) {     if (!file_exists(SOURCE)) {         format(error, ERRORLEN, "File copy error: Source ^"%s^" doesn't exist!", SOURCE)         return false     }     if (!REPLACE_TARGET && file_exists(TARGET)) {         format(error, ERRORLEN, "File copy error: Target ^"%s^" exists!", TARGET)         return false     }     new source = fopen(SOURCE, "rb")     if (!source) {         format(error, ERRORLEN, "File copy error: Opening source ^"%s^" failed!", SOURCE)         return false     }     new target = fopen(TARGET, "wb")     if (!target) {         format(error, ERRORLEN, "File copy error: Opening target ^"%s^" failed!", TARGET)         fclose(source)         return false     }     for (new buffer, eof = feof(source); !eof; !eof && fputc(target, buffer)) {         buffer = fgetc(source)         eof = feof(source)     }     fclose(source)     fclose(target)     return true }

Edit: I added this to file.inc. Also fixed a problem with fopen not returning 0 when a file couldn't be opened. CVS is up to date with these changes.
Johnny got his gun is offline
johnjg75
Veteran Member
Join Date: Mar 2004
Location: Delaware
Old 05-29-2005 , 20:34  
#4

Thank you
__________________
johnjg75 is offline
Send a message via AIM to johnjg75 Send a message via MSN to johnjg75 Send a message via Yahoo to johnjg75
 



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 01:43.


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