用目录名中的正斜杠创建目录树 [英] Create directory tree with forward slash in directory name

查看:47
本文介绍了用目录名中的正斜杠创建目录树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图创建一个目录树,其中一个目录的名称中有一个正斜杠 (/).请参阅 $artist 变量了解艺术家姓名和我创建目录的尝试.

Trying to create a directory tree in which one of the directories has a forward slash (/) in the name. See the $artist variable for the artist name and my attempts at creating the directory.

#!/usr/bin/perl

use warnings;
use strict;
use File::Path qw(make_path);
my $srcpath = '/home/<username>;/music';
my $artist = "";
my $album = 'somealbum';

# Using single quotes

#t1
$artist = 'AC/DC';
make_path("${srcpath}/t1/${artist}/${album}/");

#t2
$artist = 'AC//DC';
make_path("${srcpath}/t2/${artist}/${album}/");

#t3
$artist = 'AC\/DC';
make_path("${srcpath}/t3/${artist}/${album}/");

# Using double quotes

#t4
$artist = "AC/DC";
make_path("${srcpath}/t4/${artist}/${album}/");

#t5
$artist = "AC//DC";
make_path("${srcpath}/t5/${artist}/${album}/");

#t6
$artist = "AC\/DC";
make_path("${srcpath}/t6/${artist}/${album}/");

#t7
$artist = "AC\\/DC";
make_path("${srcpath}/t7/${artist}/${album}/");

我想要的目录树(5 个文件夹):
/-> 主页 -> <用户名>-> 音乐 -> AC/DC -> 专辑

Directory tree I want (5 folders):
/ -> home -> <username> -> music -> AC/DC -> somealbum

我得到的目录树(6 个文件夹):
/-> 主页 -> <用户名>-> 音乐 -> AC -> DC -> somealbum

Directory tree I get (6 folders):
/ -> home -> <username> -> music -> AC -> DC -> somealbum

推荐答案

斜线字符是文件名或目录名的非法字符.您需要替换一些其他字符,例如破折号.

The slash character is an illegal character for a file or directory name. You will need to substitute some other character, like the dash character.

这篇关于用目录名中的正斜杠创建目录树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆