移动功能在 Windows 的 Raku 中不起作用
move function does not work in Raku in Windows
这是我的文件夹结构:
C:\USERS\SUMAN\OPENMP_CMAKE
│ shlib.pl
│ shlib.raku
│
└───resources
└───libraries
shlib.raku
包含这一行
move "shlib.pl", "resources/libraries"
当我运行这个脚本时,它不能移动文件。阅读 docs here,我希望它能工作。相反,它抛出这个错误:
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
估计是系统问题。但是有办法解决这个问题吗?因为它会帮助我实现自动化。这是我的系统信息:
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
在 repl.it (Linux) 中,我也看不到它是否有效,这是错误:
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
显然,move
不适用于目录,如果您在 Linux
中做的大致相同,这就是错误提示
move "shlib.pl", IO::Path.new("resources/libraries/shlib.pl")
这在 Linux 中有效,你能检查一下它在 Windows 中是否有效吗?由于使用 IO::Path
,它确实创建了一个应该独立于文件系统约定的路径
您可以使用 Raku 将多个文件从一个目录复制到另一个目录,但是(希望代码可移植性)Raku 提供了一种机制来限制对 OS-provided shell.
也就是说:在使用Raku的copy
或move
或rename
命令时,给这些file-system命令一个dir()
参数,表示which-files-in-which-directory你想操作。包含一个 for
语句来遍历您已识别的文件(and/or 目录)。以下是您导航到 source
目录时的示例:
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
乐 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
如果您位于 parent
目录中,则 copy
或 move
或 rename
from/to source/destination 个目录:
乐 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
我猜 Raku 制定这个 design-decision 是为了让用户 learn/remember one pattern-matching 语言 (Raku-regexes) 而不是两种 (Raku-regexes AND shell-globbing).
这是我的文件夹结构:
C:\USERS\SUMAN\OPENMP_CMAKE
│ shlib.pl
│ shlib.raku
│
└───resources
└───libraries
shlib.raku
包含这一行
move "shlib.pl", "resources/libraries"
当我运行这个脚本时,它不能移动文件。阅读 docs here,我希望它能工作。相反,它抛出这个错误:
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
估计是系统问题。但是有办法解决这个问题吗?因为它会帮助我实现自动化。这是我的系统信息:
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
在 repl.it (Linux) 中,我也看不到它是否有效,这是错误:
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
显然,move
不适用于目录,如果您在 Linux
move "shlib.pl", IO::Path.new("resources/libraries/shlib.pl")
这在 Linux 中有效,你能检查一下它在 Windows 中是否有效吗?由于使用 IO::Path
您可以使用 Raku 将多个文件从一个目录复制到另一个目录,但是(希望代码可移植性)Raku 提供了一种机制来限制对 OS-provided shell.
也就是说:在使用Raku的copy
或move
或rename
命令时,给这些file-system命令一个dir()
参数,表示which-files-in-which-directory你想操作。包含一个 for
语句来遍历您已识别的文件(and/or 目录)。以下是您导航到 source
目录时的示例:
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
乐 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
如果您位于 parent
目录中,则 copy
或 move
或 rename
from/to source/destination 个目录:
乐 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
我猜 Raku 制定这个 design-decision 是为了让用户 learn/remember one pattern-matching 语言 (Raku-regexes) 而不是两种 (Raku-regexes AND shell-globbing).