⎕nparts : file or directory ?

General APL language issues

⎕nparts : file or directory ?

Postby Yves on Sun Oct 21, 2018 10:29 am

Dear All,
with ⎕nparts, i am in trouble.
i use dropfile event to catch path.

with a text file with extension :
      ⎕nparts chn
┌→────────────────────────────────────────────┐
│ ┌→───────────────────────────┐ ┌→──┐ ┌→───┐ │
│ │C:\Users\user\Desktop\hazel\│ │nut│ │.txt│ │
│ └────────────────────────────┘ └───┘ └────┘ │
└∊────────────────────────────────────────────┘


with the same text file without extension :
      ⎕nparts chn
┌→─────────────────────────────────────────┐
│ ┌→───────────────────────────┐ ┌→──┐ ┌⊖┐ │
│ │C:\Users\user\Desktop\hazel\│ │nut│ │ │ │
│ └────────────────────────────┘ └───┘ └─┘ │
└∊─────────────────────────────────────────┘

no soucy.

the path to my work directory is C:\Users\user\Desktop\hazel\
      ⎕nparts chn
┌→─────────────────────────────────────┐
│ ┌→─────────────────────┐ ┌→────┐ ┌⊖┐ │
│ │C:\Users\user\Desktop\│ │hazel│ │ │ │
│ └──────────────────────┘ └─────┘ └─┘ │
└∊─────────────────────────────────────┘
the cut is not really in the good place.
and ⎕nexists said only if file exist or not.

am i wrong ?
how can i test if it is a file or directory ?

Regards,
Yves
Yves
 
Posts: 39
Joined: Mon Nov 30, 2015 11:33 am

Re: ⎕nparts : file or directory ?

Postby Veli-Matti on Sun Oct 21, 2018 11:53 am

Interesting, my []nparts (version 17) works nicely:
      ⎕nparts 'd:\users\user\desktop\hazel\nut.txt'
┌────────────────────────────┬───┬────┐
│d:\users\user\desktop\hazel\│nut│.txt│
└────────────────────────────┴───┴────┘
⎕nparts 'd:\users\user\desktop\hazel\nut'
┌────────────────────────────┬───┬┐
│d:\users\user\desktop\hazel\│nut││
└────────────────────────────┴───┴┘
⎕nparts 'd:\users\user\desktop\hazel\'
┌────────────────────────────┬┬┐
│d:\users\user\desktop\hazel\│││
└────────────────────────────┴┴┘

..but instead of it I'd recommend using []ninfo (1=directory, 2=file):
      1 ⎕ninfo'd:\users\user\desktop\hazel\nut.txt'
2
1 ⎕ninfo'd:\users\user\desktop\hazel\nut'
2
1 ⎕ninfo'd:\users\user\desktop\hazel\'
1
1 ⎕ninfo'd:\users\user\desktop\hazel'
1


-Veli-Matti
Veli-Matti
 
Posts: 93
Joined: Sat Nov 28, 2009 3:12 pm

Re: ⎕nparts : file or directory ?

Postby Yves on Sun Oct 21, 2018 8:35 pm

Thanks Veli-Matti :)

i am under Dyalog APL/W-64 Version 17.0.33947 and ⎕nparts is unchanged :(
of course, and thank you, i use ⎕info to complete my function.
Yves
 
Posts: 39
Joined: Mon Nov 30, 2015 11:33 am

Re: ⎕nparts : file or directory ?

Postby AndyS|Dyalog on Mon Oct 22, 2018 11:18 am

⎕NPARTS is working as intended.

For any name ⎕NPARTS returns
    the directory in which the name resides
    the name stripped of any path and any extension
    the extension (if any)
⎕NPARTS does not care what type of object the base name is - indeed, it doesn't care whether the object exists or not. All that is required is that the name contained in the right argument conforms to the naming convention of the operating system.

So:
      ⎕nparts '../i/do/not.exist'
┌────────┬───┬──────┐
│../i/do/│not│.exist│
└────────┴───┴──────┘

Even with a left argument of 1, ⎕NPARTS does not check for the existence of the object or not:
      1 ⎕nparts'../i/do/not.exist' 
┌────────────────────┬───┬──────┐
│/home/andys/../i/do/│not│.exist│
└────────────────────┴───┴──────┘

Note that on Windows the ".." can be resolved so you would see '/home/i/do/' in the first element.

I agree that the documentation needs some changes .. the word "file" is misleading in some places; I have raised an issue requesting that the documentation is made more precise.
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest