CurrentDirectory broken?

CurrentDirectory broken? - Messages

#1 Posted: 10/30/2020 4:31:10 AM
Dionysios J. Pantazis

Dionysios J. Pantazis

16 likes in 179 posts.

Group: User

Is the CurrentDirectory function still broken? Looking at https://smath.com/bts/Issues/IssueDetail.aspx?id=4586 its unresolved?

I am on 0.99.7579.3197

No matter where I save the .sm file, it ALWAYS returns "C:\Program Files (x86)\SMath Studio\"

This breaks many of my include statements and excel file imports/exports as I have them defined as -

path:= "xls\workbook.xlsm"

root_dir:=CurrentDirectory("")

and then

path:= concat(root_dir,path) will return

"C:\Program Files (x86)\SMath Studio\xls\workbook.xlsm" instead of

"C:\Users\someguy\JobFolder\xls\workbook.xlsm"

I know that this has come and gone a few times with both uni and AlexM weighing in on it, but I thought it was fixed.

Is there a fix?
Join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#2 Posted: 10/30/2020 4:43:46 AM
Вячеслав Мезенцев

Вячеслав Мезенцев

1402 likes in 1708 posts.

Group: Moderator

CurrentDirectory() is just a wrapper for the system variable Environment.CurrentDirectory (.Net). So it can't be broken. With an empty argument, it shows the current folder specified in the program and nothing else.
Russia ☭ forever, Viacheslav N. Mezentsev
#3 Posted: 10/30/2020 6:00:52 AM
Dionysios J. Pantazis

Dionysios J. Pantazis

16 likes in 179 posts.

Group: User

uni-

why isn't the proper directory showing up?

Join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#4 Posted: 10/30/2020 8:24:06 AM
Вячеслав Мезенцев

Вячеслав Мезенцев

1402 likes in 1708 posts.

Group: Moderator

It looks like SMath Studio doesn't change the folder when saving the document. I addressed this question to Andrey. Let's wait for his answer.
Russia ☭ forever, Viacheslav N. Mezentsev
#5 Posted: 10/30/2020 8:16:56 PM
Andrey Ivashov

Andrey Ivashov

2270 likes in 3734 posts.

Group: Super Administrator

If it is based on Environment.CurrentDirectory then result will differ according to the way how you have opened SMath Studio:
- If opened clicking on program icon - current directory will be equal to SMath Studio installation directory;
- If opened clicking on the Worksheet file - current directory is a folder where file is located.
#6 Posted: 10/31/2020 6:24:25 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

Is the CurrentDirectory function still broken? Looking at https://smath.com/bts/Issues/IssueDetail.aspx?id=4586 its unresolved?

I am on 0.99.7579.3197

No matter where I save the .sm file, it ALWAYS returns "C:\Program Files (x86)\SMath Studio\"

This breaks many of my include statements and excel file imports/exports as I have them defined as -

path:= "xls\workbook.xlsm"

root_dir:=CurrentDirectory("")

and then

path:= concat(root_dir,path) will return

"C:\Program Files (x86)\SMath Studio\xls\workbook.xlsm" instead of

"C:\Users\someguy\JobFolder\xls\workbook.xlsm"

I know that this has come and gone a few times with both uni and AlexM weighing in on it, but I thought it was fixed.

Is there a fix?



I recommend to use CurrentDirectory(DocumentDirectory()). This should work for files which have been saved at least once.

What it does is quite straightforward. It gets the directory of the currently active document and sets the current directory to it. Both functions are from Uni's mathcad file access functions plugin.

This way you can have multiple documents open at the same time. When switching between them, the directory is changed once you execute the document.

In your case you could set the root to DocumentDirectory().
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#7 Posted: 10/31/2020 10:58:46 AM
NDTM Amarasekera

NDTM Amarasekera

130 likes in 352 posts.

Group: User

Wrote


I recommend to use CurrentDirectory(DocumentDirectory()). This should work for files which have been saved at least once.



Image of an example attached pl. Works fine in latest SS.

Document_Directory.png
Look within!... The secret is inside you. Best Regards Eng. NDTM Amarasekera - Sri Lanka
#8 Posted: 11/2/2020 12:31:42 AM
Dionysios J. Pantazis

Dionysios J. Pantazis

16 likes in 179 posts.

Group: User

Wrote

This way you can have multiple documents open at the same time. When switching between them, the directory is changed once you execute the document.

In your case you could set the root to DocumentDirectory().



Exactly. Thank you.
Join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
  • New Posts New Posts
  • No New Posts No New Posts