Path names with spaces.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Path names with spaces.

 
0
  #1
Mar 31st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1,000
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 149
JamesCherrill JamesCherrill is offline Offline
Veteran Poster

Re: Path names with spaces.

 
0
  #2
Mar 31st, 2009
Enclose the name in double quotes?
ls -s "dir 1/fileName" dir2/NewfileName
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Path names with spaces.

 
0
  #3
Apr 1st, 2009
Many thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Path names with spaces.

 
0
  #4
Apr 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Path names with spaces.

 
0
  #5
Apr 2nd, 2009
Oh, I also tried it in single quotes but with the same result.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1,000
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 149
JamesCherrill JamesCherrill is offline Offline
Veteran Poster

Re: Path names with spaces.

 
0
  #6
Apr 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC