Author Topic: How to inspect the filename in the edit_box controls inputs...  (Read 2696 times)

0 Members and 1 Guest are viewing this topic.

jxphklibin

  • Guest
How to inspect in the DCL dialog box, edit_box controls in the filename which in inputs not to include these characters “/: *? “|”, i.e. conforms to the filename naming rule.

I've made this code as follows....but not seem to work.

Code: [Select]
;; Returning the naming rules in line with the file name string
;; 返回符合文件名命名规则的字符串
;; 前提条件是:没有路径名的字符串
(defun RetFNameStr (str /)
  (setq str (vl-string->list str))
  (foreach item '(92 47 58 42 63 34 60 62 124)
    (setq str (vl-remove item str));或(setq str (vl-remove-if '(lambda (x) (= x item)) str))
  )
  (vl-string-trim " " (vl-list->string str))
;;;  (vl-string-right-trim
;;;    " "
;;;    (vl-string-left-trim " " (vl-list->string str))
;;;  )
);;(vl-string-trim " " str) 删除前后空格
Code: [Select]
(setq TmpF      (get_tile \"ZBOutpath\")
        Tmppath (strcat (vl-filename-directory TmpF) "\\")
        Tmp1     (RetFNameStr (vl-string-subst "" Tmppath TmpF))
)
(setq TmpF (strcat Tmppath Tmp1))

The following picture shows :
« Last Edit: March 12, 2009, 08:06:43 PM by jxphklibin »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #1 on: March 12, 2009, 12:12:50 PM »
Use WCMATCH with this filter
[~...]    Matches any single character not enclosed
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #2 on: March 12, 2009, 02:20:42 PM »
Hi,

Look at the snvalid function.
Speaking English as a French Frog

jxphklibin

  • Guest
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #3 on: March 12, 2009, 07:49:23 PM »
Use WCMATCH with this filter
[~...]    Matches any single character not enclosed


命令: (setq str "c:\\add\\  dfdfef.add dfd ")
"c:\\add\\  dfdfef.add dfd "
命令: (wcmatch str "*[\\/:*?\"<>|]*")
T
命令: (wcmatch str "*[~\\/:*?\"<>|]*")
T
命令: (wcmatch str "*[~\\/:*?\"<>|]*")
T
命令: (wcmatch str "[~\\/:*?\"<>|]")
nil
命令: (wcmatch str "[\\/:*?\"<>|]")
nil

??????????

jxphklibin

  • Guest
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #4 on: March 12, 2009, 07:52:14 PM »
Hi,

Look at the snvalid function.

What is the snvalid function?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #5 on: March 12, 2009, 08:04:34 PM »
You can not test the \ character because it is needed within the path.
You will have to separate the file name and test it.

I don't know where I got this:
Quote
This is a test for valid file names, Layer and block names too!

Checks the symbol table name for valid characters
(snvalid sym_name [flag])

The snvalid  function inspects  the system  variable EXTNAMES  to determine  the
rules to enforce  for the active  drawing. If extnames  is 0, snvalid  validates
using the symbol name rules in effect  prior to AutoCAD 2000. If  extnames is  1
(the default value), snvalid validates using the rules for extended symbol names
introduced with AutoCAD 2000. The following are not allowed in any symbol names,
regardless of the setting of extnames:

Control and graphic characters
   Null strings
   Vertical bars as the first or last character of the name

AutoLISP does not enforce restrictions on the length of symbol table names if extnames is 1.

Arguments

sym_name

A string that specifies a symbol table name.

flag

An integer that specifies whether the vertical bar character is allowed within sym_name. The flag argument can be one of the following:
0  Do not allow vertical bar characters anywhere in sym_name. This is the default.
1  Allow vertical bar characters in sym_name, as long as they are not the first or last characters in the name.

Return Values

 T, if sym_name is a valid symbol table name, otherwise nil.
If extnames is 1, all characters are allowed except control and graphic characters and the following:

Characters Disallowed in Symbol Table Names

< >   less-than and greater-than symbol
/ \   forward slash and backslash
"   quotation mark
:   colon
?   question mark
*   asterisk
|   vertical bar
,   comma
=   equal sign
`   backquote
;   Semi-colon (ASCII 59)
A symbol table name may contain spaces.
If  extnames is  0, symbol  table names  can consist  of upper  and lower  case
alphabetic letters (e.g., A-Z), numeric digits (e.g., 0-9), and the dollar  sign
($), underscore (_), and hyphen (–) characters.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jxphklibin

  • Guest
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #6 on: March 12, 2009, 08:22:15 PM »
At (vl-filename-directory str) where str contains a single "/" or doubled "\ \" when the problem has made the path, that is to obtain the path may not exist

Such asthe filename in the edit_box is “D:\My Documents\   45df?\/*\\dfa”,Bold are part of the user input the file name of chaos,Then should not to work.
« Last Edit: March 12, 2009, 08:29:14 PM by jxphklibin »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to inspect the filename in the edit_box controls inputs...
« Reply #7 on: March 12, 2009, 08:58:11 PM »
You can test like this:
Code: [Select]
    (setq err (vl-catch-all-apply 'findfile (list str)))

    (if (vl-catch-all-error-p err)
      (null (alert (vl-catch-all-error-message err)))
    )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.