Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...My thanks to the contributors who freely share their knowledge and enthusiasms. This forum restores some measure of my faith in human nature..."

Geography

Where in the world do Tek-Tips members come from?
rommeq (Programmer)
18 Jun 12 6:24
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
Bong (Programmer)
18 Jun 12 10:20
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

rommeq (Programmer)
18 Jun 12 10:54
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]
rommeq (Programmer)
18 Jun 12 11:29
what could be the problem?
Bong (Programmer)
19 Jun 12 10:13
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

rommeq (Programmer)
19 Jun 12 14:08
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?
Bong (Programmer)
20 Jun 12 9:29
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

rommeq (Programmer)
21 Jun 12 17:18
Thank you very much. It works.

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!

Back To Forum

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