Reputation: 3545
This is my folder structure:
C:\USERS\SUMAN\OPENMP_CMAKE
│ shlib.pl
│ shlib.raku
│
└───resources
└───libraries
the shlib.raku
contains this line
move "shlib.pl", "resources/libraries"
When I run this script, it cannot move file. Reading the docs here, I expected it to work. Instead it throws this error:
Failed to move 'C:\Users\suman\openmp_cmake\shlib.pl' to 'C:\Users\suman\openmp_cmake\resources\libraries': Failed to copy file: operation not permitted
in block <unit> at c:\Users\suman\openmp_cmake\shlib.raku line 1
I suppose it is system related. But is there a way to get around this? Because it will help me automate things. This is my system information:
Host Name: SUMANKHANAL
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19043 N/A Build 19043
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: N/A
Registered Organization: N/A
Product ID: 00331-20350-00000-AA867
Original Install Date: 2/19/2022, 1:41:50 PM
System Boot Time: 4/10/2022, 9:35:07 PM
System Manufacturer: Dell Inc.
System Model: Inspiron 5379
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 142 Stepping 10 GenuineIntel ~2001 Mhz
BIOS Version: Dell Inc. 1.17.0, 8/18/2021
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC+05:45) Kathmandu
Total Physical Memory: 8,025 MB
Available Physical Memory: 1,442 MB
Virtual Memory: Max Size: 14,425 MB
Virtual Memory: Available: 3,820 MB
Virtual Memory: In Use: 10,605 MB
Page File Location(s): C:\pagefile.sys
Domain: WORKGROUP
Logon Server: \\SUMANKHANAL
Hotfix(s): 7 Hotfix(s) Installed.
[01]: KB5010472
[02]: KB5012117
[03]: KB5000736
[04]: KB5012599
[05]: KB5011352
[06]: KB5011651
[07]: KB5005699
Network Card(s): 2 NIC(s) Installed.
[01]: Qualcomm QCA61x4A 802.11ac Wireless Adapter
Connection Name: Wi-Fi
DHCP Enabled: Yes
DHCP Server: 192.168.1.254
IP address(es)
[01]: 192.168.1.83
[02]: fe80::d948:4175:e48d:b886
[03]: 2400:1a00:b111:3e81:c506:663d:5c33:418a
[04]: 2400:1a00:b111:3e81:d948:4175:e48d:b886
[05]: 2400:1a00:b111:3e81::2
[02]: Bluetooth Device (Personal Area Network)
Connection Name: Bluetooth Network Connection
Status: Media disconnected
Hyper-V Requirements: VM Monitor Mode Extensions: Yes
Virtualization Enabled In Firmware: Yes
Second Level Address Translation: Yes
Data Execution Prevention Available: Yes
In repl.it (Linux) also, I don't see if its working, here is the error:
Failed to move '/home/runner/WrithingCharmingSemicolon/openmp_cmake/shlib.pl' to '/home/runner/WrithingCharmingSemicolon/openmp_cmake/resources/libraries': Failed to copy file: illegal operation on a directory
in block <unit> at shlib.raku line 1
Upvotes: 6
Views: 225
Reputation: 2289
You can copy multiple files from one directory to another using Raku, however (in the hope of code portability) Raku provides a mechanism that limits reliance upon your OS-provided shell.
Which is to say: when using Raku's copy
or move
or rename
commands, give these file-system commands a dir()
parameter, indicating which-files-in-which-directory you wish to operate upon. Include a for
statement to loop over the files (and/or directories) you've identified. Below is an example when you've navigated to the source
directory:
Shell:
$ pwd
~/parent
$ cd source
~/parent/source$ ls
~/parent/source$ echo "for all persons" > persons.txt
~/parent/source$ echo "now is the time" > time.txt
~/parent/source$ ls
persons.txt time.txt
Raku one-liners:
~parent/source$ raku -e 'for dir(test => / .+ \.txt $ /) {.say};'
"persons.txt".IO
"time.txt".IO
~/parent/source$ raku -e 'mkdir IO::Path.new("../dest");'
~/parent/source$ raku -e 'for dir(test => / .+ \.txt $ /) { copy $_, "../dest/$_", createonly => True};'
~/parent/source$ ls ../dest
persons.txt time.txt
If you're sitting in a parent
directory, it's a tiny bit more work to copy
or move
or rename
from/to the appropriate source/destination directories:
Raku one-liners:
~/parent$ raku -e 'for dir("./source", test => / .+ \.txt $ /) {.say};'
"./source/persons.txt".IO
"./source/time.txt".IO
~/parent$ raku -e 'mkdir IO::Path.new("./dest2");'
~/parent$ raku -e 'for dir("./source", test => / .+ \.txt $ /) { copy $_, "./dest2/" ~ $_.basename, createonly => True};'
~/parent$ ls ./dest2
persons.txt time.txt
My guess is Raku instituted this design-decision to allow users to learn/remember one pattern-matching language (Raku-regexes) rather than two (Raku-regexes AND shell-globbing).
https://docs.raku.org/type/IO::Path
Upvotes: 5
Reputation: 23467
Apparently, move
does not work on directories, that's what the error says if you do more or less the same in Linux
move "shlib.pl", IO::Path.new("resources/libraries/shlib.pl")
This works in Linux, can you please check if it works in Windows? It does create a path which should be independent of the filesystem conventions, thanks to using IO::Path
Upvotes: 4