gpt4 book ai didi

powershell - 从路径中提取文件名

转载 作者:行者123 更新时间:2023-12-03 00:00:47 29 4
gpt4 key购买 nike

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

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)

最佳答案

如果您同意包含扩展程序,这应该可以满足您的要求。

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

关于powershell - 从路径中提取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35813186/

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