How can I use PowerShell to `save as…` a different file extension?

前端 未结 4 1843
你的背包
你的背包 2021-01-16 12:22

I\'m using the following powershell script to open a few thousand HTML files and \"save as...\" Word documents.

param([string]$htmpath,[string]$docpath = $d         


        
4条回答
  •  太阳男子
    2021-01-16 13:18

    Based on our comments above, it seems that moving the files is all you want to accomplish. The following works for me. In the current directory, it replaces .txt extensions with .py extensions. I found the command here.

    PS C:\testing dir *.txt | Move-Item -Destination {[IO.Path]::ChangeExtension( $_.Name, "py")}
    

    You can also change *.txt to C:\path\to\file\*.txt so you don't need to execute this line from the location of the files. You should be able to define a destination in a similar manner, so I'll report back if I find a simple way to do that.

    Also, I found Microsoft's TechNet Library while I was searching. It has many tutorials on scripting using PowerShell. Files and Folders, Part 3: Windows PowerShell should help you to find additional info on copying and moving files.

提交回复
热议问题