将文件夹中所有文件的格式从 Unicode 更改为 ANSI 的 Powershell 脚本 [英] Powershell script to change the format of all files in a folder from Unicode to ANSI

查看:101
本文介绍了将文件夹中所有文件的格式从 Unicode 更改为 ANSI 的 Powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我一个 Powershell 脚本,将文件夹中所有文件的格式从 Unicode 更改为 ANSI?这是一个示例文件夹结构:

Can someone give me a Powershell script that will change the format of all files in a folder from Unicode to ANSI? Here is a sample folder structure:

c:\DBObjects
  +StoredProcs
      - sp1.sql
      - sp2.sql
      - sp3.sql
  +Views
     - v1.sql
     - v2.sql
  .Functions
     - fn1.sql
     - fn2.sql

我为一个文件尝试了以下脚本,并且成功了.但是它会创建另一个文件:

I tried the following script for one file and it worked. However it will create another file:

Get-Content sp1.sql -encoding Unicode | Set-Content sp1_Ansi.sql -encoding ASCII

谢谢!

推荐答案

尝试

Set-Content sp1.sql -Encoding ASCII -Value (Get-Content sp1.sql)

注意整个文件会被临时读入内存.如果不能接受,则需要使用管道方法写入新文件,然后删除旧文件,并将新文件重命名为旧文件名.

Note that the entire file will be read into memory temporarily. If that's not acceptable, you'll need to use the pipeline method to write to a new file, then delete the old file, and rename the new file to the old file's name.

这篇关于将文件夹中所有文件的格式从 Unicode 更改为 ANSI 的 Powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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