File IO on a Mac

A forum for issues on macOS; the UNIX and Linux forums may have relevent posts

File IO on a Mac

Postby lancepawl on Wed Sep 06, 2017 11:41 am

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
lancepawl
 
Posts: 10
Joined: Tue Sep 05, 2017 1:43 pm

Re: File IO on a Mac

Postby AndyS|Dyalog on Thu Sep 07, 2017 8:22 am

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.
User avatar
AndyS|Dyalog
 
Posts: 255
Joined: Tue May 12, 2009 6:06 pm

Re: File IO on a Mac

Postby lancepawl on Thu Sep 07, 2017 10:44 pm

Hello Andy,
Thanks for the information. It was helpful!

Regards,

Lance
lancepawl
 
Posts: 10
Joined: Tue Sep 05, 2017 1:43 pm


Return to macOS

Who is online

Users browsing this forum: No registered users and 1 guest