从路径中提取文件名 [英] Extract the filename from a path

查看:46
本文介绍了从路径中提取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从下面的路径中提取文件名:

I want to extract filename from below path:

D:\Server\User\CUST\MEA\Data\In\Files\CORRECTED\CUST_MEAFile.csv

现在我写了这段代码来获取文件名.只要文件夹级别没有改变,就可以正常工作.但是如果文件夹级别发生了变化,则需要重写此代码.我正在寻找一种使其更灵活的方法,例如无论文件夹级别如何,代码始终可以提取文件名.

Now I wrote this code to get filename. This working fine as long as the folder level didn't change. But in case the folder level has been changed, this code need to rewrite. I looking a way to make it more flexible such as the code can always extract filename regardless of the folder level.

($outputFile).split('\')[9].substring(0)

推荐答案

如果您同意包含扩展,这应该可以满足您的需求.

If you are ok with including the extension this should do what you want.

$outputPath = "D:\Server\User\CUST\MEA\Data\In\Files\CORRECTED\CUST_MEAFile.csv"
$outputFile = Split-Path $outputPath -leaf

这篇关于从路径中提取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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