Using Windows Batch or VBScript or Powershell, how can I remove an end of file character in text files?

I need to remove a small right arrow at the end of the data (an ASCII EOF marker) in a text file without removing any other data.

A script would need to look in a specific folder, ie c:\data\ and look at each .txt file and if it sees this end EOF marker then it needs to remove it and resave the file.
100questionsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
Test if this works for one file:
Get-Content "X:\path\file.txt" -Encoding Byte | ? {$_ -ne 0x1A} | Set-Content "X:\path\newfile.txt" -Encoding Byte

If it does, we can use this for the entire folder. It basically reads a file byte by byte and writes only those bytes not equal to 0x1A (or 26 decimal,  which is the code for ASCII EOF)

HTH,
Dan
0
100questionsAuthor Commented:
Is this to be inserted in a batch file?
If yes, I tried and it just blinks fast and nothing happens.
0
Dan CraciunIT ConsultantCommented:
Nope. It's a powershell script.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

100questionsAuthor Commented:
Ok, it works well!!
How can we modify it to look at all txt files in folders?
0
Dan CraciunIT ConsultantCommented:
$origFolder = "X:\your\path"
$newFolder = "X:\your\new\path"

$files = gci $origFolder -Recurse -filter "*.txt"
foreach ($file in $files) {
    Get-Content $file.FullName -Encoding Byte | ? {$_ -ne 0x1A} | Set-Content "$newFolder\$file" -Encoding Byte
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
100questionsAuthor Commented:
Thanks. Will this form new files on it's own and it's own naming convention?
0
Dan CraciunIT ConsultantCommented:
This will create new files in the newFolder folder. Basically it will copy the original files, minus the offending character.

That folder must exist, or the script will throw an error.
0
100questionsAuthor Commented:
If no files exist in the folder, will the script still run, but nothing will be created?
0
Dan CraciunIT ConsultantCommented:
yup
0
100questionsAuthor Commented:
May try this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.