main(
List
<
String
>
arguments) {
var
newPath
=
path
.
join
(
'/Users/shailen'
,
'dart/projects'
);
print(newPath);
输出有个问题,因为不同平台的路径分隔符是不同的,这个问题后面会解决
main(List<String> arguments) {
print(path.split(
'/Users/shailen'
));
print(path.split(
r'C:\tempdir\tmp.txt'
));
输出效果如下
main(
List
<String> arguments) {
print
(path.relative(Directory.systemTemp.path));
var
path1 =
'docs/book.html'
;
var
path2 =
'articles/list'
;
print
(path.relative(path1, from: path2));
print
(path.relative(path2, from: path1));
var
samples =
'http://www.dartlang.org/samples'
;
var
docs =
'http://www.dartlang.org/docs'
;
print
(path.relative(samples, from: docs));
print
(path.relative(docs, from: samples));
输出效果如下
main(
List
<String> arguments) {
var
uri = path.toUri(
'http://dartlang.org/samples'
);
print
(path.fromUri(uri));
输出效果如下
main(List<String> arguments) {
new File(
'${Directory.systemTemp.path}/dir/myFile.txt'
).create(recursive: true)
.then((
file
) {
print
(path.
basename
(
file
.path));
print
(path.
dirname
(
file
.path));
print
(path.basenameWithoutExtension(
file
.path));
print
(path.extension(
file
.path));
输出效果如下
Python 技术篇-不使用os模块判断指定路径是文件还是文件夹,使用pathlib库判断文件和文件夹
Python 技术篇-不使用os模块判断指定路径是文件还是文件夹,使用pathlib库判断文件和文件夹