File IO on a Mac
3 posts
• Page 1 of 1
File IO on a Mac
Hello,
I transferred my APL2WiN workspaces to Dyalog on the Mac. The functions should mostly run unchanged except for the file IO, since the Mac does not use the same path syntax as the PC. However, I am having trouble figuring out the correct path to read a file from the Mac Desktop to put into an array. I checked the Dyalog documentation files but there is hardly any information specific to the Mac OS. I also tried to find commands to change to a specific directory on a Mac and list the directory contents, but didn't find anything. Does anyone have information for these things or know of any Dyalog Mac OS specific documentation?
Thanks & Regards,
Lance
I transferred my APL2WiN workspaces to Dyalog on the Mac. The functions should mostly run unchanged except for the file IO, since the Mac does not use the same path syntax as the PC. However, I am having trouble figuring out the correct path to read a file from the Mac Desktop to put into an array. I checked the Dyalog documentation files but there is hardly any information specific to the Mac OS. I also tried to find commands to change to a specific directory on a Mac and list the directory contents, but didn't find anything. Does anyone have information for these things or know of any Dyalog Mac OS specific documentation?
Thanks & Regards,
Lance
- lancepawl
- Posts: 10
- Joined: Tue Sep 05, 2017 1:43 pm
Re: File IO on a Mac
When Dyalog for macOS starts up, the current working directory is your home directory as defined by macOS. In my case, /Users/andys.
My desktop is saved in /Users/andys/Desktop, so I can access files on (?in?) the Desktop by referring to '/Users/andys/Desktop/myfile' or 'Desktop/myfile'.
We recommend that on all platform you do not change the current working directory once you have started APL; that's one of the reasons why ⎕CD does not exist in Dyalog APL, and is most unlikely ever to be added. It is possible to use ⎕NA to change the current working dirctory, but "here be dragons" ..
To list the contents of the Desktop directory you can use either
⎕←0 (⎕ninfo ⍠ 1)'Desktop/*'
or
⎕←⎕sh 'ls Desktop'
The first is faster, but currently if you want to do a recursive listing you'll have to write a function in APL to do that, whereas the second can be made recursive simply by adding the -R flag to ls. You might also like to investigate ⎕sh'find Desktop' which allows you to match on name, timestamp, size etc etc.
My desktop is saved in /Users/andys/Desktop, so I can access files on (?in?) the Desktop by referring to '/Users/andys/Desktop/myfile' or 'Desktop/myfile'.
We recommend that on all platform you do not change the current working directory once you have started APL; that's one of the reasons why ⎕CD does not exist in Dyalog APL, and is most unlikely ever to be added. It is possible to use ⎕NA to change the current working dirctory, but "here be dragons" ..
To list the contents of the Desktop directory you can use either
⎕←0 (⎕ninfo ⍠ 1)'Desktop/*'
or
⎕←⎕sh 'ls Desktop'
The first is faster, but currently if you want to do a recursive listing you'll have to write a function in APL to do that, whereas the second can be made recursive simply by adding the -R flag to ls. You might also like to investigate ⎕sh'find Desktop' which allows you to match on name, timestamp, size etc etc.
-
AndyS|Dyalog - Posts: 263
- Joined: Tue May 12, 2009 6:06 pm
Re: File IO on a Mac
Hello Andy,
Thanks for the information. It was helpful!
Regards,
Lance
Thanks for the information. It was helpful!
Regards,
Lance
- lancepawl
- Posts: 10
- Joined: Tue Sep 05, 2017 1:43 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group