![]() |
![]() |
#1 |
Registered User
Join Date: Jun 2020
Location: Germany
Posts: 382
|
![]()
Is there any way to determine whether the current path is a directory or the root of a drive?
I need to set a path as a variable to set a target for copy operations. I tried using CD but the end of output is different if it's a drive or a directory. It is either Code:
DRIVE: or DRIVE:DIRECTORY Code:
Set TARGET 'CD' Copy SOMEFILE to ${TARGET}NEWFILE Code:
DRIVE:DIRECTORYNEWFILE And I can't do ${TARGET}/NEWFILE because then it won't work when it's a drive. To add more info, yes I need NEWFILE because I need to rename some files. And I hope this would be possible to fix with just shell scripting. No additional software or arexx. Last edited by EctoOne; 22 September 2022 at 01:48. |
![]() |
![]() |
#2 |
Ex nihilo nihil
Join Date: Oct 2017
Location: CH
Posts: 5,157
|
Depending on your OS version, this can be an idea that need a bit of adaptation : https://eab.abime.net/showthread.php?t=108682 ?
|
![]() |
![]() |
#3 |
Registered User
Join Date: Jun 2020
Location: Germany
Posts: 382
|
Thanks, using INFO to determine what the current path is works. Don't know how safe this is, but I came up with this:
Code:
SET CWD `CD` INFO >T:eoCWD ${CWD} SEARCH >NIL: FROM T:eoCWD SEARCH Unit QUIET IF WARN ; Directory SETENV eoTARGET "${CWD}/" ELSE ; Drive SETENV eoTARGET "${CWD}" ENDIF DELETE >NIL: T:eoCWD Using "Unit" as search string might not be the best way, but since I'm not parsing any arguments, I couldn't use a more unique string. Unit is one of the strings that comes up in the output of INFO. And since there is no output if it's a directory, I don't think there will be any problem. |
![]() |
![]() |
#4 |
Ex nihilo nihil
Join Date: Oct 2017
Location: CH
Posts: 5,157
|
![]() |
![]() |
![]() |
#5 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,051
|
[QUOTE=EctoOne;1566047]I
And when I use something like this: Code:
Set TARGET 'CD' Copy SOMEFILE to ${TARGET}NEWFILE You could do it like this: Code:
assign target: "" copy somefile to target:newfile assign target: Code:
.key dummy assign target<$$>: "" copy somefile to target<$$>:newfile assign target<$$>: Edit: you probably only used the current directory for the example, but if the target is the current directory, you don't need to supply a target path at all you could just do Code:
copy somefile newfile |
![]() |
![]() |
#6 |
Registered User
Join Date: Jun 2020
Location: Germany
Posts: 382
|
Thanks thomas, I normally try to avoid making assigns but your solution is so simple that I might use it. Because it also makes it easier to access sub dirs or at least it's better to read.
|
![]() |
![]() |
#7 |
Registered User
Join Date: Jan 2021
Location: Darksideofthemoon
Posts: 70
|
A short version to check for directory or disk
Code:
cd >ram:test search >nil: ram:test #?:[a-z,0-9] pattern if warn echo "is drive" endif Last edited by freakofnature; 22 September 2022 at 17:30. |
![]() |
![]() |
#8 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,051
|
The first echo should probably be cd, shouldn't it?
|
![]() |
![]() |
#9 |
Registered User
Join Date: Jan 2021
Location: Darksideofthemoon
Posts: 70
|
It should!
![]() Corrected, thanks Thomas! |
![]() |
![]() |
#10 |
Registered User
Join Date: Jun 2020
Location: Germany
Posts: 382
|
Wow, I didn't know that the Amiga had the support for this type of pattern matching.
|
![]() |
![]() |
#11 |
Registered User
Join Date: Jun 2020
Location: Germany
Posts: 382
|
Found another solution using ECHO instead of parsing a file and thought it might be worth sharing it.
The short version would be this: Code:
SET cwd "`CD`" IF "`ECHO "${cwd}" LEN 1`" EQ ":" ECHO "is drive" ENDIF Code:
SET eoTARGET `REQUESTFILE SYS: TITLE "Select install drive" DRAWERSONLY` IF NOT "`ECHO "${eoTARGET}" LEN 1`" EQ ":" SET eoTARGET "${eoTARGET}/" ENDIF ECHO "${eoTARGET}" |
![]() |
![]() |
#12 |
Registered User
Join Date: Jan 2021
Location: Darksideofthemoon
Posts: 70
|
Nice try.
echo $var len 1 is unreliable on AOS3.0 to 3.9, as it fails on path names containing <space>, like "Ram Disk:". Returning string then is "m :", every last char taken from all parts. It works on 3.2 as well as on older os with shell replacement like zshell, but not vinced. Brackets are used to access parsed arguments. You can safely omit them on local vars. |
![]() |
![]() |
#13 |
Registered User
Join Date: Jun 2020
Location: Germany
Posts: 382
|
Huh, didn't notice that because I have a line in my user-startup that relabels my ram disk to ram. Wouldn't it be possible to wrap it in additional quotes? I will look into that.
I know about the brackets but I'm so used to them from bash scripting, also don't you need them anyway if you want to directly add something? Like in my second example where I add the /: Code:
SET eoTARGET "${eoTARGET}/" Edit: I can't reproduce the behavior you described. It works fine on my regular installation and even when I run the script using just a Workbench 3.1 disk. ![]() Last edited by EctoOne; 04 November 2022 at 00:46. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Reading files from current directory in assembly | hukka | Coders. System | 40 | 21 May 2021 12:14 |
Returning the current working floppy drive device | mcgeezer | Coders. Asm / Hardware | 5 | 08 July 2019 21:38 |
vasm Get Current Work Directory (Windows expert needed) | phx | Coders. General | 13 | 15 October 2018 20:57 |
Current options for an Amiga 500 hard drive | carloratm | support.Hardware | 0 | 27 August 2018 21:16 |
Add directory to path with ARexx? | Firestone | Coders. Scripting | 5 | 07 May 2017 04:28 |
|
|