Batch convert unix to dos format

Find, replace, find in files, replace in files, regular expressions

Batch convert unix to dos format

Postby buckley » Sun Oct 25, 2009 11:44 am

Hello,

I searched the forums but could not find an answer to this question. I know I can convert 1 file but how can I convert a whole folder?

Regards, Tom
buckley
Newbie
 
Posts: 1
Joined: Sun Oct 25, 2009 11:43 am

Re: Batch convert unix to dos format

Postby Mofi » Mon Oct 26, 2009 3:54 am

There is the script Convert all open files to DOS line terminators.

But much faster is to use Search - Replace in Files. Open this dialog, enter as search string ^n and as replace string ^r^n and run this NON regular expression replace on all files in a directory (recursively). If your directory (structure) contains also already DOS files. Run a second replace in files searching for ^r^r^n and replace it with ^r^n to fix the wrongly inserted carriage return in the DOS files.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Batch convert unix to dos format

Postby ridgerunner » Sun Nov 29, 2009 5:18 pm

Or, you can run a single Perl regular expression replace that will modify only Unix files (and will leave DOS files alone)
Code: Select all
Find What:
(?<!\r)\n
Replace With:
\r\n

The (?<!\r)\n expression says: "match a newline, but only if it is not preceded by a carriage return."
Negative lookbehind subexpressions (using (?<! ...) syntax) can be very handy!
User avatar
ridgerunner
Basic User
Basic User
 
Posts: 18
Joined: Thu Sep 15, 2005 11:00 pm
Location: SLC, UT USA


Return to Find/Replace/Regular Expressions