Unix newlines to windows newlines (on Windows)

2019-01-21 22:36发布

Does anyone know of a way (say Powershell, or a tool) in Windows that can recurse over a directory and convert any unix files to windows files.

I'd be perfectly happy with a way in Powershell to at least detect a unix file.

It's easy do this for one single file, but I'm after something a bit more scalable (hence leaning towards a Powershellish solution).

10条回答
The star\"
2楼-- · 2019-01-21 23:08

You can use Visual Studio. File -> Advanced Save Options...

查看更多
smile是对你的礼貌
3楼-- · 2019-01-21 23:11

I spent 6 hours yesterday and today testing the code given above in a loop with 10,000 files, many of them >50kb in size. Bottom line, the powershell code is very inefficient/slow/unusable for large files and large number of files. It also does not preserve BOM bytes. I found unix2dos 7.2.3 to be the fastest and most practical solution. Hope this helps others and saves them time.

查看更多
走好不送
4楼-- · 2019-01-21 23:12

download vim, open your file and issue

:se fileformat=dos|up

Batch for multiple files (all *.txt files in C:\tmp - recursive):

:args C:\tmp\**\*.txt
:argdo se fileformat=dos|up
查看更多
等我变得足够好
5楼-- · 2019-01-21 23:16

There is dos2unix and unix2dos in Cygwin.

查看更多
Deceive 欺骗
6楼-- · 2019-01-21 23:19

Opening a file with Unix line endings in Wordpad and saving it will rewrite all the line endings as DOS. A bit laborious for large numbers of files, but it works well enough for a few files every once in a while.

查看更多
太酷不给撩
7楼-- · 2019-01-21 23:24

It works for me:

 Get-ChildItem -Recurse -File | % { $tmp = Get-Content $_; $tmp | Out-File "$_" -Encoding UTF8 }
查看更多
登录 后发表回答