Create folder name with decimal

Create folder name with decimal

BeKirra
Advisor Advisor
1,072 Views
8 Replies
Message 1 of 9

Create folder name with decimal

BeKirra
Advisor
Advisor

I was helped with creating folders in couple years ago.

It works fine for me and I never go back to look at it again until now.

I noticed that if the new folder name contains a decimal point, all characters after the decimal will lose in the folder name.

For example:

(makepath "C:/ABC.DEF")

It returns "C:/ABC\\"

In other words, the new folder is "ABC" instead of "ABC.DEF"

 

I have looked the code below but cannot figure it out.

Your help is much appreciated.

 

 

(defun makepath (path / temp items item dir)
(setq path (if (= (type path) 'STR) (vl-string-right-trim "/\\" path) nil))
(while (and path (/= temp path))
(setq items (cons (vl-filename-base path) items)
temp path
path (vl-filename-directory path)
)
)
(while (setq item (car (setq items (cdr items))))
(setq dir (strcat path item))
(if (or (vl-directory-files path item -1)(vl-mkdir dir))
(setq path (strcat dir "\\"))
(setq items (prompt (strcat "\nUnable to create directory \"" dir "\"\n")))
)
)
)

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Accepted solutions (1)
1,073 Views
8 Replies
Replies (8)
Message 2 of 9

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

try with this quick fix.

Add an extra decimal at the end of DEF.

(makepath "C:/ABC.DEF.")

 

Or add the below highlighted codes in your program.

Then you can run the program as (makepath "C:/ABC.DEF")

Click the +sign to see the Code

Spoiler
 
(defun makepath (path / temp items item dir)
(setq path (if (= (type path) 'STR) (vl-string-right-trim "/\\" path) nil))

;if the path name contains a decimal point then add an extra decimal point at the end.
(if (vl-string-search "." path)
(setq path (strcat path "."))
);if
;.
;.
;.
;Remaining codes are same

 

0 Likes
Message 3 of 9

BeKirra
Advisor
Advisor

Thanks. It works perfectly.

But can you explain that the reason of adding an extra decimal point to the end of the path?

Thanks in advance.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 4 of 9

Ajilal.Vijayan
Advisor
Advisor

Becuase at this line in the code

(setq items (cons (vl-filename-base path) items)

the vl-filename-base command is returning the value just before the decimal point appears in the supplied argument.

 

So (vl-filename-base "C:/ABC.DEF") will return "ABC"

whereas (vl-filename-base "C:/ABC.DEF.") will return ABC.DEF

Hope this helps.

 

Message 5 of 9

BeKirra
Advisor
Advisor

Thanks.

I should check with the HELP carefully. It makes sense.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 6 of 9

Ajilal.Vijayan
Advisor
Advisor
BeKirra wrote:

Thanks.

I should check with the HELP carefully. It makes sense.

You're welcome, BeKirra
Glad I could help.

0 Likes
Message 7 of 9

BeKirra
Advisor
Advisor

As I said before, the code looks alright by adding these lines to makepath:

(setq path
(if (= (type path) 'STR)
(vl-string-right-trim "/\\" path)
nil
)
)

 

I find that if the new path is more than 1 level and if the upper level name contains a decimal, all characters after the decimal in the level will be removed. This seems the same problem previously.

 

For example:

Set path: "C:/ABC.DEF/GHJ.KLM"

 

then (makepath "C:/ABC.DEF/GHJ.KLM") returns

"C:/ABC/GHJ.KLM"

 

Thanks in advance.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 8 of 9

Ajilal.Vijayan
Advisor
Advisor

This seems interesting and the same time now I dont know how to fix this Smiley Sad

Will update you once got any solution.

0 Likes
Message 9 of 9

BeKirra
Advisor
Advisor

Sorry, everything are correct in my post #7 except the code.

It should be:

(if (vl-string-search "." path)
(setq path (strcat path "."))
);if

 

When I look into the HELP for the details of the following items used in makepath, it seems that nothing to do with them:

1) vl-filename-base

2) vl-filename-directory

3) vl-directory-files

Did I miss something?

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes