none
Converting 300 unix files to dos files RRS feed

  • Question

  • I have over 300 files that were saved in unix and I want to convert them all to dos text based. I saw the utility called unix2dos but it only does one file at a time.  Can someone shed some light on this perhaps someone may be familiar with a utility that can do all of them. BTW all 300+ files have a *.txt extension on them.

    Waiting anxiously for some good news <S>.

    BTW when I selected to ask a question here it first asked me to select a forum category and now one of them had anything to do with Visual Basic.net surprisingly.  Also maybe you can provide me where to go for that forum for the future.

    Thanks

    Les

    Sunday, May 27, 2018 9:13 PM

Answers

  • Hi Les,

    Since you mentioned the UNIX unix2dos utility, I assumed you will be doing the conversion on a UNIX system. The code is for the UNIX/LINUX platform.

    Apologies if I wasn't clear about that.

    If you want to do it on Windows, I would suggest downloading the Windows version of unix2dos e.g., from Erin Waterlader 
    https://waterlan.home.xs4all.nl/dos2unix.html

    Extract it and copy the windows executables from the bin sub-directory to wherever you have your txt files or put them in a location referenced by your PATH variable
    Then from a CLI in the folder where you have the txt files, you can run the command below (in-place conversion):

    FOR  %i IN (*.txt) DO unix2dos -o %i


    To create new converted files (without modifying the original), let's put them in a sub-directory called dosfiles:
    mkdir dosfiles

    FOR  %i IN (*.txt) DO unix2dos -n %i dosfiles\%i


    Regards,

    Ayotunde

    • Marked as answer by Les2011 Thursday, May 31, 2018 5:53 AM
    Monday, May 28, 2018 3:02 AM

All replies

  • I'd ask for help over here.

    https://social.technet.microsoft.com/Forums/en-US/home?forum=win10itprogeneral

    https://social.technet.microsoft.com/Forums/en-US/home?forum=w8itprogeneral

    https://social.technet.microsoft.com/Forums/en-US/home?forum=w7itprogeneral

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverfiles

     (vb.net forum is here)

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.


    Sunday, May 27, 2018 9:52 PM
    Moderator
  • Hi,

    If you have put all of them in the same location, you can use a loop to convert all of them:

    cd /path/to/location/

    for i in `ls *.txt`; do unix2dos -n $i `echo $i | cut -d . -f 1`-win.txt; done

    You will find a set of new files with names like filename-win.txt.

    If you would rather do an in-place conversion i.e., (over)writing the changes to the original files, the command would be:

    for i in `ls *.txt`; do unix2dos -o $i; done

    Regards,

    Sunday, May 27, 2018 9:53 PM
  • It depends on which of the following you need to do.

    1. use an existing utility
    2. write a script (VBScript or JavaScript) or batch file (bat or cmd extension)
    3. write a program using a language such as C# or VB.Net

    You should go for # 1 if possible and avoid # 3 if possible of course. If you use a TechNet forum as Dave suggests then they will most likely be able to help with existing utilities and they can even help with scripts and batch files.



    Sam Hobbs
    SimpleSamples.Info


    Sunday, May 27, 2018 11:38 PM
  • Thank you Sam for your input

    Les

    Monday, May 28, 2018 12:30 AM
  • Hi Dave,

    Thank you for the vb.net forum address

    Les

    Monday, May 28, 2018 12:33 AM
  • You are welcome.

    After thinking I realize that what I said is a bit misleading. If it were me and I had to write something then I would use C#. So it depends on your experience and preferences. I am making assumptions when I say you should try to find a utility. You can do whatever works for you.



    Sam Hobbs
    SimpleSamples.Info

    Monday, May 28, 2018 12:35 AM
  • Hi Ayotunde

    Thanks for this snippet I will try it later tonight and feed back to you.  BTW I assume this will work in Windows 10?

    Les


    • Edited by Les2011 Monday, May 28, 2018 12:36 AM
    Monday, May 28, 2018 12:35 AM
  • Hi

    for some reason this string is not working for me.

    Lets say I have all my .txt files in directory  les/egtb/

    So I changed to the directory using cd les/egtb/

    I did a dir and it listed all the txt files

    Then I ran your code snippet   for i in `ls *.txt`; do unix2dos -o $i; done

    Its been a long time since I have worked in the command window but I would appreciate it if you can elaborate on what I might be doing wrong.

    Thx

    Les

    Monday, May 28, 2018 1:27 AM
  • This forum is not the place to get help. No one is supposed to provide any help in this forum except to suggest where to get help. You will get the best help in the relevant forum. You should mark a reply here that helps you to decide what forum to use. If no one has suggested a forum for what you are seeking help with then say so and then we will know you want other suggestions for where to post.


    Sam Hobbs
    SimpleSamples.Info

    Monday, May 28, 2018 2:27 AM
  • Hi Les,

    Since you mentioned the UNIX unix2dos utility, I assumed you will be doing the conversion on a UNIX system. The code is for the UNIX/LINUX platform.

    Apologies if I wasn't clear about that.

    If you want to do it on Windows, I would suggest downloading the Windows version of unix2dos e.g., from Erin Waterlader 
    https://waterlan.home.xs4all.nl/dos2unix.html

    Extract it and copy the windows executables from the bin sub-directory to wherever you have your txt files or put them in a location referenced by your PATH variable
    Then from a CLI in the folder where you have the txt files, you can run the command below (in-place conversion):

    FOR  %i IN (*.txt) DO unix2dos -o %i


    To create new converted files (without modifying the original), let's put them in a sub-directory called dosfiles:
    mkdir dosfiles

    FOR  %i IN (*.txt) DO unix2dos -n %i dosfiles\%i


    Regards,

    Ayotunde

    • Marked as answer by Les2011 Thursday, May 31, 2018 5:53 AM
    Monday, May 28, 2018 3:02 AM
  • Hi your code worked great.  What I did not do was download the link to get the unix2dos utility you mentioned.  When I saw the same name I thought it was the same but it turned out the one you recommended was just what the doctor ordered.  Thank you so much for your help

    Les

    Monday, May 28, 2018 4:03 AM
  • Hi Sam,

    I thought I was in the correct forum which I thought was vb.net?? In the past people would pose a question and the many people who have been so supportive have always done there best to help whether is was a code snippet or suggest a utility to do what the user was asking about.  Dave above was kind enough to point me to this very forum since I earlier tried to get on this forum and I was asked which forum I wanted and it was a much different list then what it was about a year ago.  So when I asked for help here Dave provided me with this forum and it actually still took me to the forum that about a year ago I was familiar with.  When did this forum make it clear that no one should not provide any help other then to tell you where to go to get help?? I am very confused.  I have seen hundreds of thousands of people providing help here so I am still very confused about this new policy.  Perhaps someone else who reads this can weigh in also.

    Thanks,

    Les  

    Monday, May 28, 2018 4:04 AM
  • Look at the top of the thread. It is:

    See where it says "Where is the Forum For…?"? Now read the description of this forum at PURPOSE OF THIS FORUM - This forum tells you where to go ask questions - Please Read Before Posting, especially the part that says:

    Answering the questions directly ... is out of scope for this forum.

    It is to your advantage to look for answers in the relevant forum because many more of the people that are most likely to help will see it there. If you only look here for answers then you will never know what you could have gotten from those others.

    I don't understand why you say that Dave pointed you to this forum, Dave pointed you to other forums.



    Sam Hobbs
    SimpleSamples.Info

    Monday, May 28, 2018 4:26 AM

  • I thought I was in the correct forum which I thought was vb.net?? 

    This is "where is" forum for direction on where best to ask questions. The VB.Net forum is over here.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Monday, May 28, 2018 4:49 AM
    Moderator
  • Hi Dave,

    Now I am really confused.  When I click your link for the VB.Net forum I am still here?? and that is the same link you gave me before.  So exactly what do I do for vb help?? This is the only site I have ever used for like the last 4 or 5 years or so.  Even on the link you gave me it says "Where is the forum for"

    I just don't get it please help me so I can get this right.

    Les

    Monday, May 28, 2018 6:16 AM
  • Hi Sam,

    The last forum Dave sent me was

     (vb.net forum is here)

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

    and when I click on that I get pushed over here????

    This has never been like this over the years I have always bookmarked this link.  I have asked Dave for perhaps a better explanation as to what is going on.

    Les

    Monday, May 28, 2018 6:18 AM
  • Hi Dave,

    Now I am really confused.  When I click your link for the VB.Net forum I am still here?? 

    No, it takes you to a different MSDN forum. Visual Basic which is within the Visual Studio Languages grouping.

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Monday, May 28, 2018 12:21 PM
    Moderator