Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Accessing directories in Linux

Programming


Tags
cp, solved

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-14-2016
pinbot pinbot is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 2 December 2016, 10:59 PM EST
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Accessing directories in Linux

I'm new to Linux and trying to port
a c++ program from windows.

what I'm trying to do is copy a file to a directory off
the root of the drive

First off the program is located and running from


Code:
Drive:\Base\Web\Today\Program.exe

And trying to copy to:

Code:
Drive:\Base\cpics


windows version looks like this:


Code:
sprintf(cbuf,"copy %s \\Base\\cpics\\%s",ccc,newpic);
    system(cbuf);




Linux version:

Code:
sprintf(cbuf,"cp %s //Base//cpics//%s",ccc,newpic);
    system(cbuf);

Which of course doesn't work, hence the cry for helpLinux

help?



Moderator's Comments:
Accessing directories in Linux Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-14-2016 at 02:17 AM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 11-14-2016
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 May 2017, 1:34 AM EDT
Location: Aachen, Germany
Posts: 10,830
Thanks: 272
Thanked 3,324 Times in 3,061 Posts
WHAT doesn't work? Any error messages? Odd behaviour? Is the source file correctly located/found (in the current working directory)?
The Following User Says Thank You to RudiC For This Useful Post:
rbatte1 (11-23-2016)
Sponsored Links
    #3  
Old Unix and Linux 11-14-2016
jlliagre jlliagre is offline Forum Advisor  
ɹǝsn sıɹɐlos
 
Join Date: Dec 2007
Last Activity: 29 May 2017, 9:47 PM EDT
Location: Outside Paris
Posts: 4,852
Thanks: 18
Thanked 625 Times in 546 Posts
Quote:
Originally Posted by pinbot View Post

Linux version:

Code:
sprintf(cbuf,"cp %s //Base//cpics//%s",ccc,newpic);
    system(cbuf);

Which of course doesn't work, hence the cry for helpLinux
Why "of course"?

By the way, although I don't think this is the issue, you shouldn't double the directory separators:


Code:
    sprintf(cbuf,"cp %s /Base/cpics/%s",ccc,newpic);
    system(cbuf);

    #4  
Old Unix and Linux 11-14-2016
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 29 May 2017, 6:58 PM EDT
Location: Saskatchewan
Posts: 22,189
Thanks: 1,093
Thanked 4,175 Times in 3,862 Posts
You're very, very close - close enough that I wonder if this is permissions issues rather than program ones... Or, perhaps, parts of the program we didn't see, preventing it from working.

By the way, if this is the sort of C++ program that's line after line of system(), it'd probably be more easily "ported" to shell script.
Sponsored Links
    #5  
Old Unix and Linux 11-14-2016
pinbot pinbot is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 2 December 2016, 10:59 PM EST
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
I think I understand the problem now

what windows sees as D:\Base\cpics

linux sees /media/mint/Storage/Base/cpics

And writing

Code:
sprintf(cbuf,"cp %s //media//mint//Storage//Base//cpics//%s",ccc,newpic);

isn't an option for portability reasons, as I need to copy to the same drive that the program is run from and these mount points could change.



Moderator's Comments:
Accessing directories in Linux Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-15-2016 at 06:29 AM.. Reason: Added CODE tags.
Sponsored Links
    #6  
Old Unix and Linux 11-15-2016
pinbot pinbot is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 2 December 2016, 10:59 PM EST
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688
You're very, very close - close enough that I wonder if this is permissions issues rather than program ones... Or, perhaps, parts of the program we didn't see, preventing it from working.
You were correct btw, the way it was originally written was trying to access linux root directory.

Quote:
Originally Posted by jlliagre
By the way, although I don't think this is the issue, you shouldn't double the directory separators:
Interesting, strangely it works both ways.

Quote:
Originally Posted by RudiC
WHAT doesn't work? Any error messages? Odd behaviour? Is the source file correctly located/found (in the current working directory)?
No errors everything compiles fine, just can't get it to move up
the directory tree 2 levels.

seems the best I can do is cp file ../ and move up one directory. I may have to rearrange my directory structure to get this to work in linux. Thanks for all your suggestions

Last edited by rbatte1; 11-16-2016 at 08:30 AM.. Reason: Added ICODE tags
Sponsored Links
    #7  
Old Unix and Linux 11-16-2016
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 May 2017, 1:34 AM EDT
Location: Aachen, Germany
Posts: 10,830
Thanks: 272
Thanked 3,324 Times in 3,061 Posts
You certainly won't need to modify the directory structure as any *nix system is very versatile in and capable of moving files around.
Maybe your approach would benefit from slight adaptions, e.g. as proposed by Corona668?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing multiple directories in loop rohit_shinez Shell Programming and Scripting 5 09-08-2014 06:58 AM
Accessing linux via telnet Krrishv IP Networking 4 12-23-2006 01:21 AM
Accessing UNIX Data over LINUX xohaib UNIX for Dummies Questions & Answers 2 03-25-2006 03:21 PM
Accessing FTP on Linux Breen Linux 4 07-01-2004 10:32 AM
Problem accessing network using Linux natter IP Networking 3 04-30-2003 02:18 PM



All times are GMT -4. The time now is 05:16 AM.