I am trying to list all the information in a text file related to the files in a directory. I used the statement below to do this:
file.info(list.files(path="C:\\temp\\dat\\work",pattern="\\.T$))
The output I got was-
size isdir mode mtime ctime atime exe
17517.T NA NA <NA> <NA> <NA> <NA> <NA>
17530.T NA NA <NA> <NA> <NA> <NA> <NA>
17565.T NA NA <NA> <NA> <NA> <NA> <NA>
All I want is to get all the information in a text file in the format below-
Date modified Time modified size file name
10/08/2015 02:39 AM 122055 17517.T
10/08/2015 02:39 AM 122662 17530.T
10/01/2015 08:37 PM 76613 17565.T
You need to tell list.files
to return full paths. Without it I can duplicate your behaviour:
> file.info(list.files(path="/home/rowlings/bin",pattern=".sh$"))
size isdir mode mtime ctime atime uid gid uname grname
backupStatus.sh NA NA <NA> <NA> <NA> <NA> NA NA <NA> <NA>
checkFetchmail.sh NA NA <NA> <NA> <NA> <NA> NA NA <NA> <NA>
postgresBackup.sh NA NA <NA> <NA> <NA> <NA> NA NA <NA> <NA>
postgresBackup2.sh NA NA <NA> <NA> <NA> <NA> NA NA <NA> <NA>
roxbuild.sh NA NA <NA> <NA> <NA> <NA> NA NA <NA> <NA>
What happens is that list.files
returns just the file name, so then file.info
is looking in the working directory, not finding the files, and returning NA
everywhere.
With full.names=TRUE
then list.files
returns the full path, so file.info
can find the files and report back okay:
> file.info(list.files(path="/home/rowlings/bin",pattern=".sh$", full.names=TRUE))
size isdir mode mtime
/home/rowlings/bin/backupStatus.sh 1333 FALSE 755 2013-06-03 14:24:47
/home/rowlings/bin/checkFetchmail.sh 427 FALSE 755 2009-01-17 22:18:40
/home/rowlings/bin/postgresBackup.sh 98 FALSE 755 2008-09-11 16:27:55
/home/rowlings/bin/postgresBackup2.sh 206 FALSE 755 2009-09-09 16:27:10
/home/rowlings/bin/roxbuild.sh 850 FALSE 755 2011-03-08 10:11:06
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With