Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows file and directory names with spaces 1

Status
Not open for further replies.

alan147

Technical User
Nov 15, 2002
128
GB
Good morning

I have a script that logs in to an FTP server and downloads any new files, generally this works well. Unfortunately the FTP server is on a windows box and occasionally when the files and directories are uploaded there are spaces in the names. This will mess up my script.

Does anyone know a way to read the full file / directory name so that I can download it?

Thanks

Alan
 
Use doublequotes.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I agree with PHV. However, if your download the files 'as is' to your unix box, the filenames will essentially be useless. The best plan, in my experience is to educate (or coerce) your users to use filenames with underscores in place of the spaces. Possibly difficult, but it's really necessary if you're to avoid problems with the downloaded files.

I want to be good, is that not enough?
 
Thanks guys, I am trying to educate the users but we all know how difficult that can be so I was trying to resolve it in the script. I get a list of the files and directories with ls -l then awk to separate the files from the directories then printing the 9th field for the name, this is where it falls over.

Alan
 
Why not posting your script?
I'd use ls instead of ls -l

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You could try using tr -s ' ' '_' to translate your filenames so that they have underscores rather than spaces?

I want to be good, is that not enough?
 
For example: mv "test file.txt" `ls | tr -s ' ' '_'`

I want to be good, is that not enough?
 
Thanks for your help. I don't control the FTP server so education is my best bet.

Alan
 
Good luck with that, and thanks for the star!

I want to be good, is that not enough?
 
the filenames will essentially be useless
I disagree as I've never had problem with exotic filenames.
You simply have to know the quote mechanism in your preferred shell.
 
PHV

I use ls -l to create a list of the files and directories on the FTP server. I then cat the file

cat filename.txt | awk '/^d/' | awk '{print $9}'

this gets a list of any directories, if there is a directory name with spaces in the 9th field will only contain the first word of the file name.

Alan
 
man find

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Whilst there are ways to circumvent the problem in different shells, my own approach is to batter the users over the head with piece of 2 by 4 until they are persuaded that my way of thinking is the way to go ;-)

I want to be good, is that not enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top