943,922 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2608
  • Java RSS
Mar 31st, 2009
0

Path names with spaces.

Expand Post »
Hi.

I am writing a mac program that among other things, allows a user to create unix links to files. Now I am using the runtime.exec() method to run the ls -s command e.g.

ls -s dir1/fileName dir2/NewfileName

This works but becomes difficult if the path name to the file has a space. e.g.

ls -s dir 1/fileName dir2/NewfileName

I thought of moving the file to a central temporary directory then making the unix link then moving them back but in Java there is no real way of moving a file rather it is copying and the unix command mv is also at the mercy of paths with spaces.

Are there any suggestions to overcome this?

Many thanks
Similar Threads
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Mar 31st, 2009
0

Re: Path names with spaces.

Enclose the name in double quotes?
ls -s "dir 1/fileName" dir2/NewfileName
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008
Apr 1st, 2009
0

Re: Path names with spaces.

Many thanks.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Apr 2nd, 2009
0

Re: Path names with spaces.

Hi,

I was haste in marking as solved.

The idea of enclosing the respective paths in double quotes works when doing directly into the terminal, but from a java program using the
process.exec(command)

I have used single quotes '"' in the program to enclose the path name with the space in double quotes e.g. '"' + pathWithSpace + '"'; the result of which produces the following:

ln -s "/Users/cex12/Desktop/eclipse2/features/org.eclipse.datatools.enablement.sap.feature_1.6.1.v200809191145-440_kE77c7QAQEIQQ/epl-v10.html" "/Users/cex12/Desktop/Test Folder/work"  which works perfectly directly in the terminal but not so when used in java via the process.exec(command);

Any further help or suggestions would be most welcome.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Apr 2nd, 2009
0

Re: Path names with spaces.

Oh, I also tried it in single quotes but with the same result.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Apr 2nd, 2009
0

Re: Path names with spaces.

To get double quotes in a Java String, use the escape character /, ie
"This is called /"Fred/"" -> This is called "Fred".
Single quotes in Java define a char value, so won't be what you need.
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: damned variable vs. instantiated Object
Next Thread in Java Forum Timeline: coding help please!!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC