Project

General

Profile

Feature #7361

Adding Pathname#touch

Added by Alexander E. Fischer over 3 years ago. Updated 22 days ago.

Status:
Rejected
Priority:
Normal
Assignee:
[ruby-core:49374]

Description

Pathname has an #mkdir method to create a directory at the path, but does not have a #touch method to create an empty file at that path.

There were numerous cases where I had to fallback to using

new_file = Pathname.new('location/for/new/file')
FileUtils.touch(new_file)

instead of simply being able to use:

new_file.touch

I would like to add this method. If you like it, let me know. I will provide a patch then.


Related issues

Related to Ruby trunk - Feature #7378: Adding Pathname#write Closed 06/02/2012

History

#1 [ruby-core:49952] Updated by Yusuke Endoh over 3 years ago

  • Assignee set to Akira Tanaka
  • Status changed from Open to Assigned
  • Target version set to next minor

#2 [ruby-core:67757] Updated by Ben Rexin over 1 year ago

Any way i can help?

#3 [ruby-core:67796] Updated by Daniel Berger over 1 year ago

I'm a little surprise there isn't an option for this in FileUtils. Something like FileUtils.touch('/location/for/new', :force => true). I'd be in favor of adding that, or an option to FileUtils.mkpath.

#4 [ruby-core:74844] Updated by Dominic Sisneros 28 days ago

Any update on this

Class Pathname

def touch(options={})
FileUtils.touch(@path, options)
end

end

Pathname('test.pdf).touch(mtime: 1.hour.ago)

"#mkpath" almost works but doesn't have the mtime option

#5 [ruby-core:74922] Updated by Akira Tanaka 22 days ago

  • Status changed from Assigned to Rejected

I don't like the method name "touch".

"touch" command has multiple features:
create empty file, update mtime.
So, the intent of touch method is ambiguous.

Also available in: Atom PDF