批量修改同乙個目錄中的所有文字檔案的方法

2021-04-01 00:10:46 字數 3387 閱讀 6092

在temp/目錄下,所有的*.txt檔案.

我想把所有的檔案中的一列資料去掉如:

a.txt  -----> a.txt

a b 1 1       a 1 1

c d 2 2       c 2 2

e f 3 3       e 3 3

g h 4 4       g 4 4

i j 5 5       i 5 5

解決方法:

'批量處理文字檔案的方法

'a:批量處理某乙個目錄下的文字檔案

'b:批量修改文字檔案中的第二列資料去掉

得到temp/目錄中的所有文字檔案

dim di as io.directoryinfo

di = new io.directoryinfo("f://root/tbak")

dim fi as io.fileinfo

for each fi in di.getfiles("*.txt")

dim s as string

dim reader as io.streamreader

reader = new io.streamreader(fi.fullname)

s = reader.readtoend

reader.close()

'第乙個檔案處理操作

processstring(s, fi.fullname)

next

--檔案中處理過程

public sub processstring(byval content as string, byval filename as string)

dim reader as io.stringreader

reader = new io.stringreader(content)

dim writer as io.streamwriter

writer = new io.streamwriter(filename)

dim line as string

line = reader.readline()

while (line <> nothing)

dim ss as string()

ss = line.split(" ")

--處理數租操縱

array.copy(ss, 2, ss, 1, ss.length - 2)

writer.writeline(string.join(" ", ss, 0, ss.length - 1))

line = reader.readline

end while

writer.close()

reader.close()

end sub

--window xp ,sql_server2000下測試通過!

---檔案copy,然後放到指定目錄,刪除原來目錄檔案

'60秒重新整理頁面,判斷是否有r0011.txt檔案

'如果r0011.txt檔案不存在,在指定目錄中去copy文字檔案,設定當前時間為:文字檔案時間+"23:59:00",copy檔案到

' c:/,並更名為:r0011.txt檔案

'等待60秒,迴圈

'每30秒重新整理一次

dim lsql as string

response.addheader("refresh", "30")

if io.file.exists("f:/root/r0011.txt") then

response.write("資料正等待處理.......")

else

'從源目錄中拷貝檔案

dim di as io.directoryinfo

di = new io.directoryinfo("f://root/tbak")

dim fi as io.fileinfo

for each fi in di.getfiles("*.txt")

if io.file.exists("f:/root/r0011.txt") then

'如果上乙個檔案還沒入庫,則等待

response.write("上乙個檔案正在進行入庫處理.......")

exit for

else

dim s, year, month, day as string

dim reader as io.streamreader

reader = new io.streamreader(fi.fullname)

s = reader.readtoend

'更新系統當然時間.

'a:得到年份

year = "20" + left(right(fi.name(), len(fi.name) - 1), 2)

'b:得到月份

month = right(left(right(fi.name(), len(fi.name) - 1), 4), 2)

'c:得到日期

day = right(left(right(fi.name(), len(fi.name) - 1), 6), 2)

'設定系統時間

lsql = " exec master..xp_cmdshell 'date " & day & "-" & month & "-" & year & "' "

lsql = lsql + "exec master..xp_cmdshell 'time 23:50:00' "

zehua.data.datahelper.exesql("provider=sqloledb;server=(local);database=idbs;user id=sa;password=", lsql)

processstring(s, "f:/root/r0011.txt")

reader.close()

'如果檔案存在,刪除檔案

if io.file.exists(fi.fullname) then

io.file.delete(fi.fullname)

end if

end if

next

if fi is nothing then

response.write("資料已經全部處理完畢!")

end if

end if

public sub processstring(byval content as string, byval filename as string)

dim sw as io.streamwriter

sw = new io.streamwriter(filename, false, system.text.encoding.default)

sw.write(content)

sw.close()

end sub

--windowxp  sql-server2000下執行通過

php 在同乙個表單中新增和修改

我的方法是在同乙個表單中做文章,下面的例子是我用 thinkphp框架寫的 如果你不懂thinkphp,沒有關係,我只是想說說我的解決方案.前台如果是這樣的.說明,表示提交到article控制器的add方法.進行接收操作.就是這樣乙個簡單的表單,我們在後台直接接收資料.public function...

在同乙個程式中結合C

在同乙個程式中結合c 和c 在同乙個程式中結合c 以及c我們需要注意的4大主題 1.name mangling 名稱重整 2.statics 靜態物件初始化 3.動態記憶體分配 4.資料結構的相容性。對於名稱重整 我們知道在c 中由於過載的存在我們需要對函式的名稱進行重整,但是c的函式我們就不需要重...

同乙個系統中啟動多個tomcat

需要在同一系統裡啟動多個tomcat,應該怎麼處理?tomcat是個服務程式,需要占用幾個通訊埠,所以預設情況是不能啟動多個tomcat,如果要啟動多個tomcat,需要修改配置檔案,通過在配置檔案設定不同的通訊埠就可以做到.檔案 tomcat home conf server.xml 是tomca...