Author Topic: Getting rid of non-number folders  (Read 2097 times)

0 Members and 1 Guest are viewing this topic.

Rabbit

  • Guest
Getting rid of non-number folders
« on: July 31, 2013, 02:18:51 PM »
I've got to move the content of a boat load of folders into other folders.  The folders to be moved are named by a number, i.e. 1001, 1002, 2001, 2002, etc.  Within each of these folders are files that I will copy over to the new locations.  My problem is that when I do a vl-directory-files to get these 'numbered' folders, there are other files I don't need, ie. 'plot.log', 'abc', 'abc123'.  I only need the ones which are just numbers.

I've worked out how to get a list of the files and the return is: ("1001" "1002" "plot.log" "abc" "abc123")

I need only the numbered items in the list into a list: ("1001" "1002")

Any ideas?
And this doesn't work (foreach item Folders (vl-remove (not (wcmatch item "*#")))).  It will return the 'abc123'.

Thanks,
Rabbit

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Getting rid of non-number folders
« Reply #1 on: July 31, 2013, 02:31:36 PM »
If they are always four numbers, a "####" filter should work.  If you use the directory-only flag for the (vl-directory-files...) that should filter out that plot.log file as well as others.  If you absolutely had to, you could construct a list of wildcard matches for every permutation of valid names ("100#" "100#.#"), and iterate that list over the list of returned folder names.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Getting rid of non-number folders
« Reply #2 on: July 31, 2013, 03:04:05 PM »
Something like this will grab your names that are integers.


Code: [Select]
(vl-remove-if-not
  (function (lambda (x) (vl-every '(lambda (n) (<= 48 n 57)) (vl-string->list x))))
  '("1001" "1002" "plot.log" "abc" "abc123")
)


This will return all integers 6 digits or less:
Code: [Select]
(vl-remove-if-not
  (function (lambda (x) (wcmatch x "#,##,###,####,#####,######")))
  '("1001" "1002" "plot.log" "abc" "abc123")
)
« Last Edit: July 31, 2013, 03:08:08 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rabbit

  • Guest
Re: Getting rid of non-number folders
« Reply #3 on: July 31, 2013, 03:20:29 PM »
ronjonp, that's it.  I would have never been able to figure that out on my own.  I'll need to reverse engineer it and see what you did.

But, it worked perfectly on my most complicated folder.

Very much appreciated,
Rabbit

-edit-  The first one worked that is.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Getting rid of non-number folders
« Reply #4 on: July 31, 2013, 03:52:22 PM »
Glad to help. The second one only works on integers 6 digits or less.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Getting rid of non-number folders
« Reply #5 on: August 01, 2013, 03:40:41 AM »
Another alternative working on any length of digits, but only using wcmatch:
Code: [Select]
(vl-remove-if '(lambda (p) (wcmatch p "*[~0123456789]*"))
  '("1001" "1002" "plot.log" "abc" "abc123"))
("1001" "1002")
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Getting rid of non-number folders
« Reply #6 on: August 01, 2013, 07:30:06 AM »
Or, using a range:
Code: [Select]
(vl-remove-if '(lambda ( s ) (wcmatch s "*[~0-9]*")) '("1001" "1002" "plot.log" "abc" "abc123"))