INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

space in file mtime

space in file mtime

(OP)
Hello.
I wrote a function to sort a list:

CODE --> tcl

proc sortl {first second} {

set f1 [glob -nocomplain -directory "F:/Tcl_project/images" $first]
puts f1=$f1
set t1 [clock format [file mtime "$f1"] -format %H%M%S]
set f2 [glob -nocomplain -directory "F:/Tcl_project/images" $second]
set t2 [clock format [file mtime "$f2"] -format %H%M%S]
#puts $f2
set res [string compare "$t1" "$t2"]
if {$res != 0} {
return $res
} else {
return [string compare $t1 $t2]
}
}
but if the filename contains a space, then error:
could not read "{F:/Tcl_project/images/DESERT SPIRIT150X300_PRE.JPG}": no such file or directory
while executing
"file mtime "$f2""
(procedure "sortl" line 7)
invoked from within
"sortl BBWG0902_PRE.JPG {DESERT SPIRIT150X300_PRE.JPG}"
(-compare command)
invoked from within
"lsort -command sortl $img"
invoked from within
"set im [lsort -command sortl $img]"
(file "iim.tcl" line 79)

help me please

RE: space in file mtime

The problem is not with spaces in the file name (if that's what you're suggesting). Consider:

CODE -->

% set fnam "x:/syseng/mus registry and file system requirements.doc"
x:/syseng/mus registry and file system requirements.doc
% file mtime $fnam
1098723166
%
I can only conclude that, as the error message says, the file or path does not exist.

_________________
Bob Rashkin

RE: space in file mtime

(OP)
The file exists. Since the if you remove the spaces from the file name, it's all right.

Example I create a list

CODE --> tcl

foreach val [glob -nocomplain -directory "F:/Tcl_project/images/" *] {


lappend img [file tail $val]

puts $img

}

and call the sort function

CODE --> tcl

set im [lsort -command sortl $img]

RE: space in file mtime

(OP)
what could be the problem?

RE: space in file mtime

Wait a minute. What are f1 and f2 (which I suppose depends on what "first" and "second" are)? You can't apply "file mtime .." to a list. glob returns a list.

_________________
Bob Rashkin

RE: space in file mtime

(OP)
If I can't apply "file mtime .." to a list, how then do I sort the list by file creation time? And why it works, if the file name, no space?

RE: space in file mtime

First of all, I'm pretty sure "it" doesn't work regardless of spaces in file names or not, whatever "it" is:

CODE -->

e:\>tclsh
% set lstA [glob e:/tcl/*.*]
e:/tcl/ah2ab.tcl e:/tcl/bmptst.tcl e:/tcl/cdoll.tcl e:/tcl/clientTst.tcl e:/tcl/cmdScrub.tcl e:/
tcl/cnvTH.tcl e:/tcl/cnvTH2.tcl e:/tcl/fixUPL.tcl e:/tcl/fndrpl.tcl e:/tcl/HxBnProcs.tcl e:/tcl/
imgtest.tcl e:/tcl/lis1245.tcl e:/tcl/LIS2MUS.tcl e:/tcl/lstbxTst.tcl e:/tcl/mde2mus.tcl e:/tcl/
mkAEHFgrdimg.tcl e:/tcl/mkDmp2.tcl e:/tcl/mkSimDmp.tcl e:/tcl/ms2date.tcl e:/tcl/rbtest.tcl e:/t
cl/rcImg.tcl e:/tcl/rnmpix.tcl e:/tcl/scrTbl.tcl e:/tcl/serverTst.tcl e:/tcl/setMcrI.tcl e:/tcl/
setSB.tcl e:/tcl/xflds.tcl
% file mtime $lstA
could not read "e:/tcl/ah2ab.tcl e:/tcl/bmptst.tcl e:/tcl/cdoll.tcl e:/tcl/clientTst.tcl e:/tcl/
cmdScrub.tcl e:/tcl/cnvTH.tcl e:/tcl/cnvTH2.tcl e:/tcl/fixUPL.tcl e:/tcl/fndrpl.tcl e:/tcl/HxBnP
rocs.tcl e:/tcl/imgtest.tcl e:/tcl/lis1245.tcl e:/tcl/LIS2MUS.tcl e:/tcl/lstbxTst.tcl e:/tcl/mde
2mus.tcl e:/tcl/mkAEHFgrdimg.tcl e:/tcl/mkDmp2.tcl e:/tcl/mkSimDmp.tcl e:/tcl/ms2date.tcl e:/tcl
/rbtest.tcl e:/tcl/rcImg.tcl e:/tcl/rnmpix.tcl e:/tcl/scrTbl.tcl e:/tcl/serverTst.tcl e:/tcl/set
McrI.tcl e:/tcl/setSB.tcl e:/tcl/xflds.tcl": no such file or directory
%
I think I would use the -command option in lsort:

CODE -->

% proc timesort {a b} {
if {[file mtime $a]<[file mtime $b]} {return -1} else {return 1}
}
% set lstB [lsort -command timesort $lstA]
e:/tcl/ms2date.tcl e:/tcl/setSB.tcl e:/tcl/setMcrI.tcl e:/tcl/cmdScrub.tcl e:/tcl/HxBnProcs.tcl
e:/tcl/ah2ab.tcl e:/tcl/mkAEHFgrdimg.tcl e:/tcl/mkSimDmp.tcl e:/tcl/mkDmp2.tcl e:/tcl/LIS2MUS.tc
l e:/tcl/lis1245.tcl e:/tcl/fixUPL.tcl e:/tcl/rcImg.tcl e:/tcl/cnvTH.tcl e:/tcl/mde2mus.tcl e:/t
cl/xflds.tcl e:/tcl/clientTst.tcl e:/tcl/serverTst.tcl e:/tcl/lstbxTst.tcl e:/tcl/cnvTH2.tcl e:/
tcl/scrTbl.tcl e:/tcl/fndrpl.tcl e:/tcl/rbtest.tcl e:/tcl/cdoll.tcl e:/tcl/rnmpix.tcl e:/tcl/bmp
tst.tcl e:/tcl/imgtest.tcl
%

_________________
Bob Rashkin

RE: space in file mtime

(OP)
Thank you very much. It works.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close