powershell - extract file name and extension

前端 未结 9 925
温柔的废话
温柔的废话 2020-12-24 04:09

I need to extract file name and extension from e.g. my.file.xlsx. I don\'t know the name of file or extension and there may be more dots in the name, so I need to search the

9条回答
  •  难免孤独
    2020-12-24 04:42

    Use Split-Path

    $filePath = "C:\PS\Test.Documents\myTestFile.txt";
    $fileName = (Split-Path -Path $filePath -Leaf).Split(".")[0];
    $extension = (Split-Path -Path $filePath -Leaf).Split(".")[1];
    

提交回复
热议问题