Jump to content

Sort file names


RepCad

Recommended Posts

Hi all,

I have all file names list of a directory, but it's not sorted, I'm trying to sort them in a new list

 

(setq lst ("1.dwg" "10.dwg" "11.dwg" "2.dwg" "3.dwg" "4.dwg" "5.dwg" "6.dwg" "7.dwg" "8.dwg" "9.dwg"))
(setq li (vl-sort lst '<))

But it returns : ; error: bad function.

It should returns 

("1.dwg" "2.dwg" "3.dwg" "4.dwg" "5.dwg" "6.dwg" "7.dwg" "8.dwg" "9.dwg" "10.dwg" "11.dwg")

 

Does somone have any ideas?

Link to comment
Share on other sites

 

(setq lst '("1.dwg"	"10.dwg"    "11.dwg"	"2.dwg"	    "3.dwg"
	    "4.dwg"	"5.dwg"	    "6.dwg"	"7.dwg"	    "8.dwg"
	    "9.dwg"
	   )
)
(vl-sort lst
	 '(lambda (a b)
	    (< (atoi (substr a 1 (- (strlen a) 4)))
	       (atoi (substr b 1 (- (strlen b) 4)))
	    )
	  )
)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...