0

I am trying to change the permissions of a file in the below given way.

File.chmod(0777,"util\logger\Sample.txt"). But the issue is the Sample.txt is in given path util/logger/Sample.txt.

The above operations is failing because unable to find the file name Sample.txt. I tried in this way Dir.chdir("\util\logger") and then im doing File.chmod(0777,"Sample.txt").

So again i need to get back to my base folder to do other operations. I felt little bad about this way of developing code.

So any help in accessing directly a file from a directory with out changing the current directory will greatly help me.

Thanks in advance, Aditya

4
  • 1
    '\util\logger' and 'util\logger' are different directories on the file system. Commented Apr 2, 2013 at 10:12
  • which operating system you are using? Commented Apr 2, 2013 at 10:28
  • Im trying out the above ways , im on windows !!! Commented Apr 2, 2013 at 10:34
  • Thanks mcfinnigan....That makes sense, i was dealing with some other file. Commented Apr 2, 2013 at 12:24

2 Answers 2

2

First of all, I don't think you can use backslash as a file separator on Unix systems. Backslash in paths is a Microsoft thing. Fortunately, Ruby has a nice way of removing file seperators from paths, so they can be calculated runtime depending on the environment.

Use File.join('path', 'to', 'file.txt')

This will return a string with the value path/to/file.txt on Unix.

Sign up to request clarification or add additional context in comments.

Comments

0

I resolved it this way ..

File.chmod(0777,"util/logger/Sample.txt") , Previously i try to enter /util/logger 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.