All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
2个页面间不通过Session与url的传值方式_[Asp.Net教程]
Delphi带导航菜单的主界面实例
HTML 5 预览(4)_[Html教程]
.NET,Socket开发中的异步Socket_.net资料_编程技术
xmlHTTP,xmlDOC,与,C#中DataSet的结合,实现AJAX简单示例_.net资料_编程技术
获取所有用户表及根据表Id取得表字段信息_[SQL,Server教程]
33条C#、.Net经典面试题目及答案_.net资料_编程技术
asp.net2.0中Server对象的方法和属性
PHP脚本编程中的文件系统函数库_php资料_编程技术
char、varchar、text和nchar、nvarchar、ntext的区别_[SQL Server教程]
Reading number is top 10 pictures
The real super beauty1
2012 national geographic daily picture8
A man's favorite things16
全身蕾丝丝质美臀
海底兵马俑
青春清纯美女大集合2
世界五大海盗
牛奶和人奶哪个好?
Cesarean section, bloody, silently into it!1
Born After 90 Beijing sports university campus flower photos2
Download software ranking
Boxer Classic video1
Call Of Duty5
Unix video tutorial15
Boxer's Top ten classic battle7
Call Of Duty2
电脑知识及技巧大合集
Tram sex maniac 2 (H) rar bag14
Such love down(擒爱记)
Unix video tutorial14
卡丁车单机版
归海一刀 published in(发表于) 2014/2/1 0:21:08 Edit(编辑)
批量修改同一个目录中的所有文本文件的方法_[SQL,Server教程]

批量修改同一个目录中的所有文本文件的方法_[SQL,Server教程]

批量修改同一个目录中的所有文本文件的方法_[SQL Server教程]























在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下执行通过









































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.