wxCopyFile when dir dont exist.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

wxCopyFile when dir dont exist.

Post by dkaip »

Hello. If i have wxCopyFile(source, dest) and dir of destination file don’t exist, wxCopyFile can make destination dir automatically?
Thank you.
Jim
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxCopyFile when dir dont exist.

Post by Manolo »

Better use wxFileName https://docs.wxwidgets.org/trunk/classwx_file_name.html
Check first if the dir exists: wxFileName::DirExists(), and create it if not: wxFileName::Mkdir(...)
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxCopyFile when dir dont exist.

Post by dkaip »

Yes this is the way. But dirName is like dri1/dir2/dir3 ... and as i see wxMkdir dont make subdirs...
Only if dirName is only one dir name.
Thank you
Jim

Code: Select all

    wxFileName xx(dest);
    wxString dirName =xx.GetPath();
    if (!wxDirExists(dirName))
        wxMkdir(dirName);
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCopyFile when dir dont exist.

Post by PB »

Did you try what Manolo suggested, i.e. calling wxFileName::Mkdir() with flags containing wxPATH_MKDIR_FULL?
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxCopyFile when dir dont exist.

Post by dkaip »

My program runs in /home/a/myfolder/ and i want to make the dir...
dirName=/home/a/video/home/a/Desktop/folder/to/
but wxMkdir(dirName,wxPATH_MKDIR_FULL) don’t makes it.
What i have wrong?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCopyFile when dir dont exist.

Post by PB »

I guess I am missing the joke here?
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxCopyFile when dir dont exist.

Post by dkaip »

What is the joke?
I don’t understand, really.
I am try to make a clone of a file in other place, relative to existing dir(/home/a/video).
The file is at /home/a/Desktop/folder/to/.
All that for non destructive process.
I is really important to construct the new directory and then copy the file.
The program's dir is at other place.
Thank you.
Jim.
Last edited by dkaip on Thu Sep 27, 2018 7:19 am, edited 3 times in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxCopyFile when dir dont exist.

Post by doublemax »

Add a wxLogMessage( dirName ) to check that it actually contains what you expect.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCopyFile when dir dont exist.

Post by PB »

dkaip wrote:What is the joke? I don’t understand, really.
Two people suggested that you should try wxFileName::Mkdir() instead of ::wxMkdir(). Additionally, you have been provided a direct link to the documentation of the said method as well as the value you should use for its flag parameter.

Yet, you still kept talking about ::wxMkdir() so I assumed this was some kind of an elaborate joke I am not on...

On MSW, wxFileName::Mkdir() works as expected, i.e.,

Code: Select all

wxFileName("C:\\a\\b\\c\\d\\").Mkdir(wxS_DIR_DEFAULT,  wxPATH_MKDIR_FULL);
creates all the directories.

If it does not work like that on Linux (assuming there are no permissions issues), you should have said so (and report it as a bug).
Last edited by PB on Thu Sep 27, 2018 7:22 am, edited 1 time in total.
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxCopyFile when dir dont exist.

Post by dkaip »

Ok my wrong, i am new to wxWidgets. I will make as you say.
So i make it and nothing happens(there are no permissions issues).
Maybe because some directories have Unicode characters?
Trying wxMessageBox(dirName); take
/home/a/Βίντεο/home/a/Επιφάνεια εργασίας
There is some problem maybe with Unicode..
But even the code bellow, to convert to Unicode nothing...

Code: Select all

    wxString dirName =xx.GetPath();

    dirName=wxString(dirName.mbc_str(),wxConvUTF8);

    wxMessageBox(dirName);

    if (!wxDirExists(dirName))
        if( wxFileName::Mkdir(dirName,wxPATH_MKDIR_FULL))wxMessageBox(dest);
Even if all characters of dirName are ASCII...

/home/a/home/a/myfolder

Thank you
Jim.
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxCopyFile when dir dont exist.

Post by dkaip »

Ok it works as PB make.
The method is wxFileName(("/home/a/home/a/myfolder/")).Mkdir(wxS_DIR_DEFAULT,wxPATH_MKDIR_FULL);
If / don’t exist at first then puts home/a/home/a/myfolder in current dir.
If / don’t exist at last the myfolder dir dont make it.

Thank you.
Jim.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxCopyFile when dir dont exist.

Post by doublemax »

Code: Select all

wxFileName::Mkdir(dirName,wxPATH_MKDIR_FULL)
Check the order of parameters.

Should be:

Code: Select all

wxFileName::Mkdir( dirName, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL )
Use the source, Luke!
Post Reply