當前位置:首頁 » 編程軟體 » txt去空格腳本

txt去空格腳本

發布時間: 2024-10-24 22:11:57

❶ 求個批量刪除文件內容空格的腳本

import os
def remove_first_line_and_spaces(file_path):
with open(file_path, 'r') as file:
# 讀取文件的第二行開始的所改含旦有內容
content = file.readlines()[1:]
# 刪除所有行的前導空格和尾隨空格
content = [line.strip() for line in content]
# 將新內容寫迴文件
with open(file_path, 'w') as file:
file.write('\n'.join(content))
def process_directory(directory_path):
for filename in os.listdir(directory_path):
# 構建完整的文件核擾路徑
file_path = os.path.join(directory_path, filename)
if os.path.isfile(file_path):
remove_first_line_and_spaces(file_path)
if __name__ == '__main__':
directory_path = 'path/to/directory'
process_directory(directory_path)
注意:請把 'path/to/directory' 替換為你要處理的目錄的實際路徑老哪。

❷ 如何刪除一個文件夾中所有txt文件中的空格

@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('dir /a-d/s/b *.txt') do (
set file=%%~na
set file=!file: =!
ren "%%~fna" "!file!%%~xa"
)
pause
以上代碼是去除文件名中的空格,文件名不變,請採納,謝謝!

❸ 寫bat批處理文件時如何刪除一個文本文件的所有空格謝了

@echooff&
(for/f"delims="%%ain(test.txt)do(
set"line=%%a"
set"line=!line:=!"
echo!line!
))>new.txt

原始文本文件名稱為test.txt,刪除空格後生成的新文本文件為new.txt

❹ 用按鍵精靈刪除txt中的空行和空格,代碼怎麼寫

您好,暫時沒有,個人認為是寫入數據時方法不對,正確的方法應該是

Dim 內容 = Array("1","2","2","2","2","2","2","2","2","2","2","2","2","2","2")

換行寫入txt文件("txtx","sss",內容)

Function 換行寫入txt文件(文件夾名,文件名,內容)

Import "cgc.lua"

Dim 文件路徑= GetSdcardDir()&"/"&文件夾名&"/"

Dim txt文件 = 文件路徑&文件名&".txt"

If Dir.Exist(文件路徑) = 0 Then

Call Dir.Create(文件路徑)// 創建文件夾

End If

If Dir.Exist(txt文件) = 0 Then

Call cgc.CreateFile(txt文件)// 創建文件

End If

For i = 1 To UBound(內容)+1

If i = UBOUND(內容) + 1 Then

Call File.Append(txt文件, 內容(i)) //Chr(13)

Else

Call File.Append(txt文件, 內容(i)&" ") //Chr(13)

End If

Next

End Function

熱點內容
勞拉與馬ftp 發布:2024-10-25 00:21:16 瀏覽:356
奪寶網站源碼 發布:2024-10-25 00:19:02 瀏覽:451
編程文本編輯器 發布:2024-10-25 00:09:28 瀏覽:968
編程徐帥 發布:2024-10-25 00:03:25 瀏覽:302
手機安卓模擬器如何打開文件 發布:2024-10-25 00:02:55 瀏覽:717
pythonday 發布:2024-10-24 23:55:47 瀏覽:422
g編譯c文件 發布:2024-10-24 23:55:03 瀏覽:290
電信上傳速度限制破解 發布:2024-10-24 23:44:17 瀏覽:450
戰地五為什麼連接不了伺服器 發布:2024-10-24 23:37:36 瀏覽:480
安卓如何下載國外網站 發布:2024-10-24 23:30:35 瀏覽:132