本帖最后由 batman 于 2011-5-30 10:50 编辑
vbs的:- Dim opath, npath, fso, vbnum, vbstr, vbout
- opath = "这里换成文本所在目录的路径"
- Set fso = CreateObject("scripting.filesystemobject")
- npath = fso.GetParentFolderName(opath) & "\newfolder"
- If fso.FolderExists(npath) Then fso.DeleteFolder(npath)
- fso.CreateFolder(npath)
- For Each file In fso.GetFolder(opath).Files
- If LCase(fso.GetExtensionName(file)) = "txt" Then vbstr = fso.OpenTextFile(file, 1).ReadAll()
- For i = 0 To UBound(Split(vbstr, vbCrLf & vbCrLf))
- vbnum = vbnum & " " & i & " "
- Next
- sort UBound(Split(vbstr, vbCrLf & vbCrLf)), vbnum
- For Each num In Split(vbnum, " ")
- If num <> "" Then vbout = vbout & Split(vbstr, vbCrLf & vbCrLf)(num) & vbCrLf & vbCrLf
- Next
- fso.OpenTextFile(npath & "\" & file.Name, 2, 1).Write vbout
- Next
- Set fso = Nothing
- MsgBox "ok"
-
- Function sort(num, vbnum)
- Dim a, b
- Randomize
- For a = 0 To num
- b = Int(Rnd * num)
- vbnum = Replace(vbnum, " " & a & " ", "#")
- vbnum = Replace(vbnum, " " & b & " ", " " & a & " ")
- vbnum = Replace(vbnum, "#", " " & b & " ")
- Next
- End Function
复制代码 ps:开始看错题意,还写了遍历函数并改写了原文本。。。 |