none
Copy the content of the text file not the file itself RRS feed

  • Question

  • Hi

    I have a problem, I am converting .dat file to .txt file using powershell and there is no problem, but when i try to read that file using the software I am working with, it cant read the file. but when i copy and paste it manually to new file, it works.

    any suggestions?

    Friday, July 25, 2014 2:53 PM

All replies

  • You can try something like:

    $file=Get-ChildItemC:\Test\Test.dat

    Rename-Item -Path $file -NewName test.txt

    See if that works


    Freddy91761_1


    Friday, July 25, 2014 3:22 PM
  • not working
    Friday, July 25, 2014 3:31 PM
  • What is the error message?

    Freddy91761_1

    Friday, July 25, 2014 3:34 PM
  • there is no error, but no result either
    Friday, July 25, 2014 4:22 PM
  • I think your question... or statements, rather, don't include enough information for us to help. Let me see if I can ask some questions that may help me, and others, help you.

    You: "I am converting .dat file to .txt file using powershell and there is no problem..."
    Me: How do you "convert" your .dat file to a .txt file so that there's "no problem?"

    You: "...but when i try to read that file using the software I am working with..."
    Me: With what software are you using to read the file?

    You: "...but when i copy and paste it manually to new file, it works."
    Me: When you copy and paste, are you copying the file and pasting the file, or copying the contents of the file, and pasting that into some program and then saving it?

    If I understand correctly, you need PowerShell to open a.dat file, read the contents of the file, and then create a new .txt file that has the contents of the .dat file? If so, do this:

    $FileContents = Get-Content -Path 'C:\folder\PathToFile.dat'
    Add-Content -Value $FileContent -Path 'C:\folder\NewFile.txt'


    Friday, July 25, 2014 9:21 PM
  • Possibly encoding of file

    Monday, July 28, 2014 8:24 PM