• Post Reply Bookmark Topic Watch Topic
  • New Topic

Delete file from linux/unix that has non-printable characters  RSS feed

 
Beth Evans
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this seems simple enough, but for some reason it is stumping me. I am simply trying to delete all files from a directory. My problem is that when a filename has an unprintable character it does not delete the file since it converts it to a ? . When i do an ls -b is see the the octal code is \333 . Is there a way to configure Java to keep the octal information when doing a File.list()? How can I remove these files via Java?

any help appreciated
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File.list() already returns an array of Strings. Java Strings use Unicode, so they should be able to handle any character thrown at them. Octal 333 is just an accented O anyway, so really not that exotic. However, if it's really not working, you could try File.listFiles() instead. That gives you an array of Files, which you should be able to delete without the name.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Javaranch.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!