Re: File copying

You need to call g_file_set_attributes_from_info() to apply your
changes to the file info (See: The Description section in the GFileInfo

I might also suggest filtering results on your query of
g_file_query_info and just using a loop to copy over all the attributes
listed by g_file_info_list_attributes(), it would allow you to add in
more fields more easily, rather than having to write new lines of code
for each new field that you decide to care about.

On Sun, 6 Feb 2011 17:04:26 +0000
John Emmas <johne53 tiscali co uk> wrote:

On 5 Feb 2011, at 19:18, Kevin DeKorte wrote:

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,
   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);


Thanks David and Kevin for the suggestions.  That worked fine once I
realised that I could cast from GFileOutputStream* to
GOutputStream*.  I used the built-in macros G_INPUT_STREAM(x) and
G_OUTPUT_STREAM(x) but I think they essentially do the same thing.

The only problem I'm having now is when I later come to copy the file
attributes and last modification time.  Take a look at this code and
tell me if i'm doing something wrong....

void CopyModificationtimeAndAttributes (GFileInfo* pSrcModule,
GFileInfo* pDestModule) {
GTimeVal  tvModificationTime;
gboolean  bIsHidden;

      g_return_if_fail (G_IS_FILE_INFO (pSrcModule));
      g_return_if_fail (G_IS_FILE_INFO (pDestModule));

      g_file_info_get_modification_time (pSrcModule,
&tvModificationTime); g_file_info_set_modification_time (pDestModule,
&tvModificationTime); /* Note this line for testing */
g_file_info_get_modification_time (pDestModule, &tvModificationTime);

      /* bIsHidden = g_file_info_get_is_hidden (pSrcModule); */
      /* Note this line for testing */  bIsHidden = true;
      g_file_info_set_is_hidden (pDestModule, bIsHidden);

You can see that I specifically set the copied file to be hidden (I'm
running this under Windows 7 BTW on a FAT32 partition, so no security
permissions to worry about).  Note also, that after setting the
modification time I specifically check (in my debugger) that the
destination file has the correct time, which it does.

However, if I navigate to the destination file in Windows Explorer
and inspect its properties I see that the file wasn't in fact hidden,
nor does it have the modification time I specified.  Have I missed
out a step?  For example although you can't see it in the above code
I did flush the file contents and closed it (after copying the data)
but I only unref'd the GFileInfo pointers.  I didn't carry out any
similar closing or flushing operations for the new time and
attributes.  Should I have done something to actually write the
changed details to disk?

gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

Nader Morshed <morshed nader gmail com>

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