Get Date Modified value for a directory (folder)

Hello, folks.
I'm trying to find out a way to get "Date Modified" value for a
directory on Windows. Is it possible to get the value from Ruby?

The purpose of it is that I would like to get the newest sub directory
in a directory. If anyone knows a sleek way of accomplishing this in
Ruby, I'd appreciate it.

TIA

···

--
Posted via http://www.ruby-forum.com/.

Hi,

At Wed, 22 Aug 2007 09:54:45 +0900,
Hayato Iriumi wrote in [ruby-talk:265729]:

Hello, folks.
I'm trying to find out a way to get "Date Modified" value for a
directory on Windows. Is it possible to get the value from Ruby?

File.stat(".").mtime
File.mtime(".")

···

--
Nobu Nakada

hi

whats the dot symobl indicates.

···

--
Posted via http://www.ruby-forum.com/.

Ara, nihonjin no kata desune. Gokaitou arigatou gozaimashita.

Thank you very much for your help. I will give it a try today and let
you know how it goes.

Nobuyoshi Nakada wrote:

···

Hi,

At Wed, 22 Aug 2007 09:54:45 +0900,
Hayato Iriumi wrote in [ruby-talk:265729]:

Hello, folks.
I'm trying to find out a way to get "Date Modified" value for a
directory on Windows. Is it possible to get the value from Ruby?

File.stat(".").mtime
File.mtime(".")

--
Posted via http://www.ruby-forum.com/\.

I was trying to get modified date/time for a remote directory and the
way you showed me worked only when I mapped the drive, so it's all OK,
but I just wanted to let the community know that it doesn't seem to work
if you specify the path like...

puts File.stat('\\\\remoteMachineName\\Test\\Dir1')

When I do it, I get Errno::ENOENT: No such file or directory -

Again, when I map the network folder, it works OK.

Nobuyoshi Nakada wrote:

···

Hi,

At Wed, 22 Aug 2007 09:54:45 +0900,
Hayato Iriumi wrote in [ruby-talk:265729]:

Hello, folks.
I'm trying to find out a way to get "Date Modified" value for a
directory on Windows. Is it possible to get the value from Ruby?

File.stat(".").mtime
File.mtime(".")

--
Posted via http://www.ruby-forum.com/\.

Please quote if you reply.

hi

whats the dot symobl indicates.

C:\ruby>ls .
ChangeLog.txt man
LICENSE.txt ruby.ico
MANIFEST rubyw.ico
README.1st samples
ReleaseNotes.txt share
bin src
doc uninstall.exe
lib uninstall_ruby_gnome2.exe

C:\ruby>

C:\ruby>dir .
Volume in drive C has no label.
Volume Serial Number is B02E-688E

Directory of C:\ruby

05/06/2007 04:41 PM <DIR> .
05/06/2007 04:41 PM <DIR> ..
08/18/2007 01:31 PM <DIR> bin
03/16/2007 05:52 AM 9,906 ChangeLog.txt
05/06/2007 04:40 PM <DIR> doc
05/06/2007 04:40 PM <DIR> lib
05/03/2006 04:29 AM 4,305 LICENSE.txt
05/02/2007 04:12 PM <DIR> man
03/15/2007 12:37 PM 602,342 MANIFEST
03/15/2007 12:33 PM 1,178 README.1st
03/16/2007 05:52 AM 4,564 ReleaseNotes.txt
03/16/2007 05:41 AM 4,286 ruby.ico
03/16/2007 05:41 AM 4,286 rubyw.ico
05/06/2007 04:40 PM <DIR> samples
05/02/2007 04:12 PM <DIR> share
05/02/2007 04:15 PM <DIR> src
05/02/2007 04:16 PM 53,188 uninstall.exe
05/06/2007 04:41 PM 52,653 uninstall_ruby_gnome2.exe
               9 File(s) 736,708 bytes
               9 Dir(s) 4,687,994,880 bytes free

C:\ruby>

···

--
Phillip Gawlowski

[mailto:list-bounce@example.com] On Behalf Of Nagesh Sanana:
# whats the dot symobl indicates.

the dot represents the current/working directory/path http://en.wikipedia.org/wiki/Path_(computing)

some simple examples,

irb(main):192:0> puts `ls -la .`.grep(/\.$/)
drwxr-xr-x 12 root root 4096 Aug 7 10:30 .
drwxr-xr-x 30 root root 4096 Jul 9 09:47 ..
=> nil
irb(main):193:0> puts `pwd`
/root
=> nil
irb(main):194:0> `ls -la .` == `ls -la /root`
=> true
irb(main):195:0> `ls -la .` == `ls -la /etc`
=> false

and directories are just files (albeit special), so

irb(main):199:0> File.mtime "."
=> Tue Aug 07 10:30:53 +0800 2007
irb(main):200:0> File.mtime ".."
=> Mon Jul 09 09:47:20 +0800 2007
irb(main):201:0> File.mtime "/root"
=> Tue Aug 07 10:30:53 +0800 2007

irb(main):207:0> File.stat(".") == File.stat("/root")
=> true
irb(main):208:0> File.stat(".") == File.stat("..")
=> false
irb(main):209:0> File.stat("/root") == File.stat("..")
=> false
irb(main):210:0> File.stat("/") == File.stat("..")
=> true

kind regards -botp

OOPS, the sample code was wrong. It should be...

puts File.stat('\\\\remoteMachineName\\Test\\Dir1').mtime

It still doesn't work, however.

FYI

Hayato Iriumi wrote:

···

I was trying to get modified date/time for a remote directory and the
way you showed me worked only when I mapped the drive, so it's all OK,
but I just wanted to let the community know that it doesn't seem to work
if you specify the path like...

puts File.stat('\\\\remoteMachineName\\Test\\Dir1')

When I do it, I get Errno::ENOENT: No such file or directory -

Again, when I map the network folder, it works OK.

Nobuyoshi Nakada wrote:

Hi,

At Wed, 22 Aug 2007 09:54:45 +0900,
Hayato Iriumi wrote in [ruby-talk:265729]:

Hello, folks.
I'm trying to find out a way to get "Date Modified" value for a
directory on Windows. Is it possible to get the value from Ruby?

File.stat(".").mtime
File.mtime(".")

--
Posted via http://www.ruby-forum.com/\.

On Behalf Of Hayato Iriumi:
# I was trying to get modified date/time for a remote directory and the
# way you showed me worked only when I mapped the drive, so it's all OK,
# but I just wanted to let the community know that it doesn't
# seem to work if you specify the path like...

···

#
# puts File.stat('\\\\remoteMachineName\\Test\\Dir1')
#
# When I do it, I get Errno::ENOENT: No such file or directory -
#
# Again, when I map the network folder, it works OK.

Hi Iriumi,

it works here,

irb(main):054:0> puts `dir \\\\bg-mis-pbot\\test\\test.txt`
Volume in drive \\bg-mis-pbot\test is hd
Volume Serial Number is 7CD8-B514

Directory of \\bg-mis-pbot\test

08/23/2007 08:53 AM 0 test.txt
               1 File(s) 0 bytes
               0 Dir(s) 1,899,081,728 bytes free
=> nil
irb(main):055:0> puts File.stat("\\\\bg-mis-pbot\\test\\test.txt")
#<File::Stat:0x28d19e8>
=> nil
irb(main):056:0> p File.stat("\\\\bg-mis-pbot\\test\\test.txt")
#<File::Stat dev=0x2, ino=0, mode=0100644, nlink=1, uid=0, gid=0, rdev=0x2, size=0, blksize=nil, blocks=nil, atime=Thu Aug 23 08:53:35 +0800 2007, mtime=Thu Aug 23 08:53:35 +0800 2007, ctime=Thu Aug 23 08:53:35 +0800 2007>
=> nil
irb(main):057:0>
irb(main):058:0> puts `ver`
Microsoft Windows XP [Version 5.1.2600]
=> nil
irb(main):066:0> p File.mtime('\\\\bg-mis-pbot\\test\\test.txt')
Thu Aug 23 08:53:35 +0800 2007
=> nil

kind regards -botp

Hello,
After I read your reply, I gave it another try. It's working now! I
don't understand why it wasn't working last time, but now it's all good.
I might have had some wrong code?

Anyway, thanks for taking your time to try it out.

Peña, Botp wrote:

···

On Behalf Of Hayato Iriumi:
# I was trying to get modified date/time for a remote directory and the
# way you showed me worked only when I mapped the drive, so it's all OK,
# but I just wanted to let the community know that it doesn't
# seem to work if you specify the path like...
#
# puts File.stat('\\\\remoteMachineName\\Test\\Dir1')
#
# When I do it, I get Errno::ENOENT: No such file or directory -
#
# Again, when I map the network folder, it works OK.

Hi Iriumi,

it works here,

irb(main):054:0> puts `dir \\\\bg-mis-pbot\\test\\test.txt`
Volume in drive \\bg-mis-pbot\test is hd
Volume Serial Number is 7CD8-B514

Directory of \\bg-mis-pbot\test

08/23/2007 08:53 AM 0 test.txt
               1 File(s) 0 bytes
               0 Dir(s) 1,899,081,728 bytes free
=> nil
irb(main):055:0> puts File.stat("\\\\bg-mis-pbot\\test\\test.txt")
#<File::Stat:0x28d19e8>
=> nil
irb(main):056:0> p File.stat("\\\\bg-mis-pbot\\test\\test.txt")
#<File::Stat dev=0x2, ino=0, mode=0100644, nlink=1, uid=0, gid=0,
rdev=0x2, size=0, blksize=nil, blocks=nil, atime=Thu Aug 23 08:53:35
+0800 2007, mtime=Thu Aug 23 08:53:35 +0800 2007, ctime=Thu Aug 23
08:53:35 +0800 2007>
=> nil
irb(main):057:0>
irb(main):058:0> puts `ver`
Microsoft Windows XP [Version 5.1.2600]
=> nil
irb(main):066:0> p File.mtime('\\\\bg-mis-pbot\\test\\test.txt')
Thu Aug 23 08:53:35 +0800 2007
=> nil

kind regards -botp

--
Posted via http://www.ruby-forum.com/\.

This is a reply to myself.

When I did...

puts File.stat(rootDir + '\\' + subDir).mtime

I got an error... but when I did...

dirPath = rootDir + '\\' + subDir
puts File.stat(dirPath).mtime

It worked. Weird...

···

--
Posted via http://www.ruby-forum.com/.

Hi,

At Fri, 24 Aug 2007 02:13:08 +0900,
Hayato Iriumi wrote in [ruby-talk:265968]:

When I did...

puts File.stat(rootDir + '\\' + subDir).mtime

I got an error... but when I did...

dirPath = rootDir + '\\' + subDir
puts File.stat(dirPath).mtime

It worked. Weird...

What are the exact platform, version and patchlevel, which is
given with `ruby -v'? One-click Installer?

···

--
Nobu Nakada