Hello,
I need to read some data from some older files and put that info. into
simple ASCII text files. But, I want those new text files to have the
same time stamp as the original files that the data came from. Is there
any way to do that?
Hello,
I need to read some data from some older files and put that info. into
simple ASCII text files. But, I want those new text files to have the
same time stamp as the original files that the data came from. Is there
any way to do that?
Thanks,
Peter
harp: ~> ri FileUtils.touch
-------------------------------------------------------- FileUtils#touch
touch(list, options = {})
Options: noop verbose
Updates modification time (mtime) and access time (atime) of
file(s) in +list+. Files are created if they don't exist.
FileUtils.touch 'timestamp'
FileUtils.touch Dir.glob('*.c'); system 'make'
Peter
file(s) in +list+. Files are created if they don’t exist.
FileUtils.touch 'timestamp'
FileUtils.touch Dir.glob('*.c'); system 'make'
-a
be kind whenever possible… it is always possible.
the dalai lama
Unless there’s a way to specify to FileUtils.touch the value of the
timestamp, you can use the touch command (if you’re on a sufficiently
unix-like platform):
touch -r oldfile newfile
…which sets the times on ‘newfile’ to be the same as the -r
(eference) file ‘oldfile’
Hello,
I need to read some data from some older files and put that info. into
simple ASCII text files. But, I want those new text files to have the
same time stamp as the original files that the data came from. Is there
any way to do that?
Thanks,
Peter
harp: ~> ri FileUtils.touch
-------------------------------------------------------- FileUtils#touch
touch(list, options = {})
Options: noop verbose
Updates modification time (mtime) and access time (atime) of
file(s) in +list+. Files are created if they don't exist.
FileUtils.touch 'timestamp'
FileUtils.touch Dir.glob('*.c'); system 'make'
-a
Thanks. ri verbage is rarely clear to me. These sample lines definitely
seem to be referring to Unix stuff. “make” means nothing in Windows.
where I am. Thanks, anyway.
On Wed, Mar 07, 2007 at 12:34:51AM +0900, Peter B. wrote:
Peter
FileUtils.touch ‘timestamp’
FileUtils.touch Dir.glob(’*.c’); system ‘make’
-a
Thanks. ri verbage is rarely clear to me. These sample lines definitely
seem to be referring to Unix stuff.
Not really. The first creates an empty file called ‘timestamp’; the
second
updates the timestamps of all files *.c in the current directory, and
then
runs ‘make’ (which could be a DOS command)
“make” means nothing in Windows.
where I am. Thanks, anyway.
Use the source
Find fileutils.rb on your system (on mine it’s
/usr/lib/ruby/1.8/fileutils.rb but it’ll be different under Windows)
Scan down to “def touch”. You’ll see it’s a simple function which just
calls
Unless there’s a way to specify to FileUtils.touch the value of the
timestamp, you can use the touch command (if you’re on a sufficiently
unix-like platform):
touch -r oldfile newfile
…which sets the times on ‘newfile’ to be the same as the -r
(eference) file ‘oldfile’
Nope, I’m on Windows. Having a “touch” like that would certainly be
nice, and simple. I’m going to keep playing with the FileUtils.touch to
see what I can do. Thanks.
On Wed, Mar 07, 2007 at 12:34:51AM +0900, Peter B. wrote:
Peter
FileUtils.touch ‘timestamp’
FileUtils.touch Dir.glob(’*.c’); system ‘make’
-a
Thanks. ri verbage is rarely clear to me. These sample lines definitely
seem to be referring to Unix stuff.
Not really. The first creates an empty file called ‘timestamp’; the
second
updates the timestamps of all files *.c in the current directory, and
then
runs ‘make’ (which could be a DOS command)
“make” means nothing in Windows.
where I am. Thanks, anyway.
Use the source
Find fileutils.rb on your system (on mine it’s
/usr/lib/ruby/1.8/fileutils.rb but it’ll be different under Windows)
Scan down to “def touch”. You’ll see it’s a simple function which just
calls
Thanks, Brian! Well, no, “make” is meaningless in DOS or Windows,
believe me. But, I did look into the fileutils.rb file and I do indeed
see what you point out. I’d never have thought to look into one of these
files. Amazing to me. So, I’ve tried this and it still doesn’t work:
it is set to Time.now, but you want to do something like:
newfile = “#{oldfile}.txt”
File.open(oldfile) do |o|
File.open(newfile, ‘w’) do |n|
# while line = o.gets
# n << fixup(line)
# end
end
end
t = File.mtime(oldfile)
File.utime(t,t, newfile)
Of course the inner loop is whatever you need it to be. The key here
is to just do the part of FileUtils.touch that you need which is the
call to File.utime on the new file. Since you just had to create it
(and fill it with something), you don’t have to create it (the rescue
clause in touch).
(I hadn’t run across the File.utime before, but I should’ve expected
that from Perl’s influence.)
it is set to Time.now, but you want to do something like:
newfile = “#{oldfile}.txt”
File.open(oldfile) do |o|
File.open(newfile, ‘w’) do |n|
# while line = o.gets
# n << fixup(line)
# end
end
end
t = File.mtime(oldfile)
File.utime(t,t, newfile)
Of course the inner loop is whatever you need it to be. The key here
is to just do the part of FileUtils.touch that you need which is the
call to File.utime on the new file. Since you just had to create it
(and fill it with something), you don’t have to create it (the rescue
clause in touch).
(I hadn’t run across the File.utime before, but I should’ve expected
that from Perl’s influence.)
Thank you all, gentlemen.
These lines are the ones that made it shine for me, Rob:
t = File.mtime(oldfile)
File,utime(t,t,newfile)
because that’s exactly what I need to do. I need to grab the time stamp
for my postscript files and then assign those times to my simple text
files derived from those .ps files.
Thanks. ri verbage is rarely clear to me. These sample lines
FileUtils.touch(“file1”, “file2”)
What does “t” stand for above?
The “t” is the accesstime and modified time you want to set the file to.
The FileUtils.touch sets the time on the specified file(s) to the
current time (and creates the file if it doesn’t exist). This works for
me as expected on Windows.
File.utime will set the time to any artibary time value. Assuming
testfile.txt already exists the following works for me on Windows.
a = Time.now - (246060*3) # To get the time three days ago
File.utime(a,a,“testfile.txt”) # To set the accessed and modified time
for the file to three days ago