• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

MAC OS X path  RSS feed

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, when I'm on a Windows machine, I write the following:

File f= new File("C:\\SomeFile.doc");

How can I write the file path at MAC OS X?

Thanks.
 
Sheriff
Posts: 67259
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends upon where the file is in the file system.

So, where is it?
 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:That greatly depends upon where the file is in the file system.

So, where is it?



On the Desktop
 
Bear Bibeault
Sheriff
Posts: 67259
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file path to a file named somefile.txt on the user's Desktop, assuming the user is named bear would be:

/Users/bear/Desktop/somefile.txt


 
Bear Bibeault
Sheriff
Posts: 67259
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And remember, this isn't Windows. Case counts!
 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:And remember, this isn't Windows. Case counts!



Thank you very much.
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that Windows is perfectly happy with forward slashes:

File f= new File("C:/SomeFile.doc");

works just fine.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is helpful thanks. I am also trying to read a file from a Mac OS X filesystem using C++.

I get the user to select the file location using the NSOpenPanel method and convert the URL to a const char inputFilename which looks something like this:

file://localhost/Users/.../DataFile.txt

But when I try to open the file with



inFile.is_open() returns an error.

Do I need to manipulate this path before using it in ifstream?
 
Bear Bibeault
Sheriff
Posts: 67259
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the "file://localhost" prefix?
 
Bill Tubbs
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I don't know. I didn't add it. That's what NSOpenPanel returned:




Thanks.
 
Bill Tubbs
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear Bibeault.

I think I've found the problem. I was using the wrong class method [fileURL absoluteString].

I should be using path. "Returns the path of a URL conforming to RFC 1808."

See http://stackoverflow.com/questions/3057086/how-to-chop-off-file-from-nsurl

Sorry to those who are not familiar with ObjectiveC.

Thanks!
 
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:Also note that Windows is perfectly happy with forward slashes:
File f= new File("C:/SomeFile.doc");



But that is because the JVM handles both backwards and forward slashes. Its a runtime thing.
 
Pat Farrell
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bill Tubbs wrote:This is helpful thanks. I am also trying to read a file from a Mac OS X filesystem using C++.



From your code samples, it looks to me as if you are using Objective C. That is a separate language, not the same as C++.

Being specific about what you are doing and which tools you are using makes it easier for us to help you.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!