Removing items from a list.

Discussion in 'AutoCAD' started by BillZ, May 19, 2004.

  1. BillZ

    BillZ Guest

    R2005 Vlisp:

    I make a list of directory lists using vl-directory-files. I initially remove any name that is less than 3 characters so "." and ".." aren't part of the list. Then I still need to remove some specific directories so I use extra vl-remove calls to trim the list.
    Can I somehow remove the specified directories in one call instead?

    (setq tmp_lst (mapcar '(lambda (x)(vl-remove-if-not '(lambda (str)(> (strlen str) 2)) ;get under year directories.
    (vl-directory-files (strcat "G:/" x) nil -1))) dir_year)
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "EPS_File")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Features_Options")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Lists")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Livewells")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Photos")) x)) tmp_lst) ;remove folders
    )

    This is a sample list:

    (("7200_WC-12" "7202_FB-1236_JONBOAT" "7207_WC-14_ADVENTURE" "7211_14_LAKER"
    "7215_WC-16_ADVENTURE" "7225_SV-14" "7226_FB-1436_JONBOAT" "7233_SV-16"
    "7239_SV-18" "7247_16_LAKER" "7267_SV_18_ALASKAN" "7270_1790_BASS"
    "7271_1800_PRO_BASS_SE" "7278_14_REBEL" "7280_16_REBEL_ADV" "7284_16_REBEL_DLX"
    "7318_1600_EXPLORER" "7319_1600_EXPLORER_DLX" "7330_1600_ANGLER"
    "7331_1600_ANGLER_DLX" "7332_1700_PRO_ANGLER" "7333_1700_PRO_ANGLER_DLX"
    "7352_1660_PRO_V" "7354_1660_PRO_V_SE" "7358_1660_PRO_V_DELUX"
    "7360_1660_PRO_V_DLX_SE" "7365_1775_PRO_V" "7366_1775_PRO_V_SIGNATURE"
    "7367_1775_PRO_V_SE" "7371_1775_PRO_V_DLX" "7372_1775_PRO_V_DLX_SIGN"
    "7373_1775_PRO_V_DLX_SE" "7379_1890_PRO_V" "7380_1890_PRO_V_SIGNATURE"
    "7381_1890_PRO_V_SE" "7385_1890_PRO_V_DLX" "7386_1890_PRO_V_DLX_SIGNATURE"
    "7387_1890_PRO_V_DLX_SE" "7388_1650_TYEE" "7397_1750_TYEE_OB"
    "7398_1750_TYEE_OB_GS" "7400_1700_PRO_SPORT_ADV" "7403_1750_TYEE_IO"
    "7404_1750_TYEE_IO_GS" "7418_1700_FISHERMAN" "7420_1800_FISHERMAN_OB"
    "7421_1800_FISHERMAN_IO" "7428_1850_TYEE_OB" "7429_1850_TYEE_OB_GS"
    "7430_1850_TYEE_OB_SIGN" "7448_1850_TYEE_IO" "7449_1850_TYEE_IO_GS"
    "7450_1850_TYEE_IO_SIGN" "7464_1950_TYEE_MAG_OB_GS" "7468_1950_TYEE_MAG_IO_GS"
    "7484_2100_BARON_OB" "7485_2100_BARON_OB_GS" "7496_2100_BARON_IO"
    "7497_2100_BARON_IO_GS" "7523_2250_GENMAR_SPORT_CABIN_HT"
    "7558_2450_GENMAR_SPORT_CABIN" "7680_1800_SPORTSMAN_(PONTOON)"
    "7686_2100_SPORTSMAN_(PONTOON)" "7692_2100_EXECUTIVE_(PONTOON)"
    "7694_EXECUTIVE_RE_(PONTOON)" "7698_2450_CHAIRMAN_SE_(PONTOON)"
    "Engineering_Manual" "Nests" "Plant_Drawings" "Vendor") ("7200_WC-12"
    "7207_WC-14_ADVENTURE" "7211_14_LAKER" "7215_WC-16_ADVENTURE" "7221_SSV-14"
    "7235_SSV-16" "7241_SSV-18" "7242_SSV-18_ALASKAN" "7245_SSV-18_ALASKAN_SS"
    "7247_16_LAKER" "7250_SSV-16_ALASKAN" "7251_SSV-16_ALASKAN_SS"
    "7253_SSV-20_ALASKAN" "7255_SSV-20_ALASKAN_SS" "7278_14_REBEL"
    "7280_16_REBEL_ADV" "7284_16_REBEL_DLX" "7291_1650_MR_PIKE" "7293_17_MR_PIKE"
    "7294_1440-V_REBEL" "7295_1440-V_REBEL_SS" "7298_1650-V_REBEL"
    "7299_1650-V_REBEL_SS" "7323_1650_EXPLORER" "7324_1650_EXPLORER_SS"
    "7335_1650_ANGLER" "7337_1650_ANGLER_DLX" "7338_1700_ANGLER"
    "7339_1700_ANGLER_SS" "7354_1660_PRO_V_SE" "7360_1660_PRO_V_DLX_SE"
    "7367_1775_PRO_V_SE" "7373_1775_PRO_V_DLX_SE" "7389_1800_PRO_V_SE"
    "7391_1800_PRO_V_TILLER" "7392_1900_PRO_V_SE" "7393_1900_PRO_V_LE"
    "7394_1900_GARY_ROACH" "7395_1900_MR_WALLEYE" "7399_1750_TYEE_OB_GS"
    "7400_1700_PRO_SPORT_ADV" "7401_1600_PRO_SPORT" "7405_1750_TYEE_IO_GS"
    "7420_1800_FISHERMAN_OB" "7421_1800_FISHERMAN_IO" "7436_1850_TYEE_GS_OB"
    "7438_1850_TYEE_GS_IO" "7439_1850_TYEE_IO_ITS" "7465_1950_TYEE_GS_OB"
    "7469_1950_TYEE_GS_IO" "7473_1950_TYEE_IO_ITS" "7480_2025_PRO_V_MAG_SE"
    "7481_2025_PRO_V_MR_WALLEYE" "7482_2025_PRO_V_LE" "7490_2100_FISHERMAN_OB"
    "7491_2100_FISHERMAN_IO" "7508_2150_BARON_MAGNUM_OB"
    "7510_2150_BARON_MAGNUM_IO" "7511_2150_BARON_IO_ITS" "Concept"
    "Engineering_Manual" "Nests" "Plant_Drawings" "Vendor"))

    TIA

    Bill
     
    BillZ, May 19, 2004
    #1
  2. Something like this maybe?

    (setq remove_list '("EPS" "Features" "ETC"))
    (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(or (> (strlen str) 2)
    (member str remove_list)
    )) x)) tmp_lst)


    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

    initially remove any name that is less than 3 characters so "." and
    ".." aren't part of the list. Then I still need to remove some
    specific directories so I use extra vl-remove calls to trim the list.
    (strlen str) 2)) ;get under year directories.
    "EPS_File")) x)) tmp_lst) ;remove folders
    "Features_Options")) x)) tmp_lst) ;remove folders
    "Lists")) x)) tmp_lst) ;remove folders
    "Livewells")) x)) tmp_lst) ;remove folders
    "Photos")) x)) tmp_lst) ;remove folders
     
    Ken Alexander, May 19, 2004
    #2
  3. BillZ

    BillZ Guest

    Ah,
    I wondered if I could do an "or" or something similar.

    Thanks

    Bill
     
    BillZ, May 19, 2004
    #3
  4. ;; perhaps ...

    (vl-remove-if
    '(lambda (x)
    (wcmatch (strcase x)
    "`.,`.`.,EPS_FILE,FEATURES_OPTIONS,LISTS,LIVEWELLS,PHOTOS"
    )
    )
    lst
    )

    ;; another way, perhaps more maintainable ..

    (vl-remove-if
    '(lambda (x)
    (member (strcase x)
    '( "."
    ".."
    "EPS_FILE"
    "FEATURES_OPTIONS"
    "LISTS"
    "LIVEWELLS"
    "PHOTOS"
    )
    )
    )
    lst
    )

    R2005 Vlisp:

    I make a list of directory lists using vl-directory-files. I initially remove any name that is less than 3 characters so "." and
    ".." aren't part of the list. Then I still need to remove some specific directories so I use extra vl-remove calls to trim the
    list.
    Can I somehow remove the specified directories in one call instead?

    (setq tmp_lst (mapcar '(lambda (x)(vl-remove-if-not '(lambda (str)(> (strlen str) 2)) ;get under year directories.
    (vl-directory-files (strcat "G:/" x) nil -1))) dir_year)
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "EPS_File")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Features_Options")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Lists")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Livewells")) x)) tmp_lst) ;remove folders
    tmp_lst (mapcar '(lambda (x)(vl-remove-if '(lambda (str)(= str "Photos")) x)) tmp_lst) ;remove folders
    ) <snip>
     
    michael puckett, May 19, 2004
    #4
  5. BillZ

    BillZ Guest

    Thanks,

    Any chance that this method would be faster than an "or"?

    Bill
     
    BillZ, May 19, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.