gpt4 book ai didi

perl - 如何取消链接带有空格的 Windows 文件夹?

转载 作者:行者123 更新时间:2023-12-04 06:18:21 25 4
gpt4 key购买 nike

我正在尝试删除不符合我们命名标准的文件和文件夹。好吧,我似乎可以遍历收集到的不匹配的文件和文件夹的数组并删除它们。我遇到的问题是我无法删除其中有空格的文件。我正在使用 Strawberry Perl 在 Windows 上运行。

这是数组的示例

Picture.jpg
Sample Document.doc
New Folder

我唯一能成功删除的是 Picture.jpg在这个例子中。

这是函数
foreach my $folder (@$returned_unmatches) {
print "$folder\n";
remove_root_junk($office,$folder);
}

这是子程序。
sub remove_root_junk {

my $office = shift;

my $folder = shift;

my $order_docs_path = $office_names{$office};

unlink "$order_docs_path\\$folder";

}
$order_docs_path只是我工作的完整路径。在这种情况下 C:\Data\Locations\Canton\Order_Documents如果这有帮助的话。

最佳答案

一般情况下,不支持直接解链目录。 unlink 的文档说:

Note: unlink will not attempt to delete directories unless you are superuser and the -U flag is supplied to Perl. Even if these conditions are met, be warned that unlinking a directory can inflict damage on your filesystem. Finally, using unlink on directories is not supported on many operating systems. Use rmdir instead.



如果您的子目录不为空,则 rmdir文档建议使用 rmtreeFile::Path .

关于perl - 如何取消链接带有空格的 Windows 文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6935321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com