开发者

How can I unlink a windows folder with spaces?

开发者 https://www.devze.com 2023-03-25 22:01 出处:网络
I am trying to remove files and folders that do not match our naming standard. Well I can seem to loop through an array of collected files and folders that do n开发者_Go百科ot match and delete them. T

I am trying to remove files and folders that do not match our naming standard. Well I can seem to loop through an array of collected files and folders that do n开发者_Go百科ot match and delete them. The problem I am running into is I cannot remove files that have spaces in them. I am running on Windows with Strawberry Perl.

Here is a sample of the array

Picture.jpg
Sample Document.doc
New Folder

The only thing I can delete successfully is Picture.jpg in this example.

Here is the function

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

Here is the subroutine.

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 is just the full path up to where I am working. In this case C:\Data\Locations\Canton\Order_Documents if this help at all.


Under normal circumstances, directly unlinking a directory is not supported. The documentation for unlink says:

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.

If your subdirectory is not empty, the rmdir documentation suggests using rmtree in File::Path.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号