GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 23, 2014 6:02 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: g_file_copy Crashed
PostPosted: Wed Jun 27, 2012 8:34 pm 
Offline

Joined: Wed Jun 27, 2012 8:29 pm
Posts: 4
Hi,
I am new to this forum. I want to copy a file from one folder to another. But its not working. For test i did the following code:
Code:
      gchar *dest = "E:/";
      gchar *source = "E:/test/tes.txt";
      if(g_file_copy(source,dest,G_FILE_COPY_NONE,NULL,NULL,NULL,&error))
        printf("File_Copy\n");
      else
        printf("Failed");


But its crash no matter what i try. By the way i am working on Windows 7. Please Help.


Top
 Profile  
 
 Post subject: Re: g_file_copy Crashed
PostPosted: Wed Jun 27, 2012 9:59 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Take a look at the docs: http://developer.gnome.org/gio/stable/GFile.html#g-file-copy

The g_file_copy() function needs a GFile for both source and destination, not gchar. You can use g_file_new_for_path() to create the GFile objects from your local paths.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: Re: g_file_copy Crashed
PostPosted: Thu Jun 28, 2012 8:10 am 
Offline

Joined: Wed Jun 27, 2012 8:29 pm
Posts: 4
Thanks for the reply.Now it run successfully. But copy is not working. The updated code is:
Code:
#include <gtk/gtk.h>

int main (int argc,char *argv[])
{
   
   GError *error = NULL;
      
   GFile *source;
   GFile *dest;
   
   gtk_init (&argc, &argv);
   
   source = g_file_new_for_path("E:/test/tes.txt");
   dest    = g_file_new_for_path("E:/");

   if(g_file_copy(source,dest,G_FILE_COPY_NONE,NULL,NULL,NULL,&error))
     printf("File Copy\n");
   else
     printf("%s\n",error->message);
   
   return 0;
}

The error->message is saying "Error opening file 'E:/': Permission denied".


Top
 Profile  
 
 Post subject: Re: g_file_copy Crashed
PostPosted: Thu Jun 28, 2012 10:39 am 
Offline

Joined: Wed Jun 27, 2012 8:29 pm
Posts: 4
Got it worked. I had to provide the filename in the destination GFile structure.
Thanks for the help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group