Re: File copying



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/05/2011 11:29 AM, John Emmas wrote:

On 4 Feb 2011, at 22:57, Nader Morshed wrote:


you might want to take a look at GIO's GFileInfo API. It has a
large array of attributes to get/set, depending on the GIOModule being
used.


Thanks for the tip.  I've been experimenting with the GFileInfo API today but inadvertently, it's led me to 
something of a dead end.

Remember that apart from wanting to preserve certain file attributes, my main aim was to move some files 
into a new folder (i.e. creating a new file or overwriting an older version, then deleting the original).  
g_file_replace() seems to provide a handy interface for this type of operation, since it'll allow me to 
overwrite a pre-existing file in the destination folder or create a new one if the destination file didn't 
already exist.

g_file_replace() returns a GFileOutputStream* which (supposedly) I can use for writing new contents to the 
file.  However, I've been unable to find any examples of writing to a file using a GFileOutputStream*.  In 
fact, I can't find any read, write, flush. or, close functions that take a GFileOutputStream* as their 
input.  What am I missing here?  Am I supposed to turn my GFileOutputStream* into some other kind of stream 
(for example a GOutputStream*)?  I've found plenty of functions for using GOutputStream but am struggling 
with GFileOutputStream.  Thanks.

John

John,

Something like this

    GFile *file;
    GFileOutputStream *output;
    GDataOutputStream *data;

    file = g_file_new_for_uri(uri);
    output = g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL,
NULL);
    data = g_data_output_stream_new((GOutputStream *) output);
    if (data != NULL) {
        g_data_output_stream_put_string(data, "#EXTM3U\n", NULL, NULL);
        g_output_stream_close((GOutputStream *) data, NULL, NULL);
    }

Kevin


- -- 
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x7D0BD5D1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk1NooYACgkQ6w2kMH0L1dEcgACfaD3sGP2pKKZCRl+gC7T8Gj38
YewAmgL5Pd5UnPgarGav7Ynd7fA8pmWw
=dKXE
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]