You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:批量将.out文件转为.txt的自动化方法(Cmd/PowerShell/Python)

Hey there! Converting 100 .out files one by one with WordPad sounds like a total time-suck. No worries—here are three easy, automated ways to get this done using Cmd, PowerShell, or Python, depending on what you're most comfortable with.

Using Command Prompt (Cmd)

If your .out files are plain text (which they seem to be, since you can open them in WordPad), renaming them to .txt is all you need. This is the fastest method for simple conversions:

  1. Open Cmd and navigate to the folder where your .out files are stored (use cd path\to\your\folder).
  2. Run this command:
for %f in (*.out) do ren "%f" "%~nf.txt"
  • %f represents each .out file in the folder.
  • %~nf grabs the filename without the .out extension, so we can append .txt to it.

Note: If you're putting this in a batch file, use %%f instead of %f.

Using PowerShell

PowerShell offers a more flexible approach if you need to filter files or add extra logic later:

  1. Open PowerShell and go to your file folder (use cd path\to\your\folder).
  2. Run this command:
Get-ChildItem -Filter *.out | Rename-Item -NewName { $_.BaseName + '.txt' }
  • Get-ChildItem -Filter *.out lists all .out files in the directory.
  • Rename-Item changes each file's extension—$_.BaseName gives the filename without the original extension.

If you need to include subfolders too, add -Recurse to Get-ChildItem:

Get-ChildItem -Filter *.out -Recurse | Rename-Item -NewName { $_.BaseName + '.txt' }
Using Python

If you need to handle specific text encodings (e.g., if some .out files have non-UTF-8 characters) or perform extra processing (like cleaning up content), Python is a great choice. Here's a simple script:

  1. Create a new file called convert_out_to_txt.py in your file folder.
  2. Paste this code:
import os

# Get all .out files in the current directory
out_files = [f for f in os.listdir('.') if f.endswith('.out')]

for file in out_files:
    # Get the filename without extension
    txt_filename = os.path.splitext(file)[0] + '.txt'
    
    # Read the .out file and write to .txt
    try:
        # Adjust encoding if needed (e.g., 'latin-1' for older files)
        with open(file, 'r', encoding='utf-8') as infile, open(txt_filename, 'w', encoding='utf-8') as outfile:
            content = infile.read()
            outfile.write(content)
        print(f"Converted: {file} -> {txt_filename}")
    except Exception as e:
        print(f"Error converting {file}: {str(e)}")
  1. Run the script by opening Cmd/PowerShell in the folder and typing python convert_out_to_txt.py.

Note: If you get encoding errors, try changing encoding='utf-8' to encoding='latin-1' or another appropriate encoding for your files.

内容的提问来源于stack exchange,提问作者Henry Chan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:13:02