Войти

Показать полную графическую версию : [решено] Разделение одного txt файла на несколько txt файлов


Alexander_88
23-10-2018, 06:51
Здравствуйте. Есть большой txt файл. В нём список сообщений с разделителем (в конце каждого сообщения). Необходимо разделить данный txt файл на несколько других txt файлов. В базовом txt файле, много сообщений с ссылками на различные имена файлов. Нужно разделить этот txt файл по маске (которую я укажу) имени файла ссылки :). То есть в результате у нас получится множество txt файлов, в каждом из которых будут сообщения с ссылками, где имена файлов будут совпадать с указанной маской.

Пример:
базовый txt файл:
Subject message


http://s5.depic.me/0686/zp0hjgh3m7d_o/0634yandex_m.jpg
http://s6.depic.me/06876/26fhgh8kxo8_o/0634yandex_t.jpg

File Name.type: 0634yandex.avi
Resolution: 1920x1080
Duration: 0:08:56
Filesize: 952Mb

Download
https://k2s.cc/file/f07we76wee3/0634yandex.mp4
//==================
Subject message


http://s7.depic.me/065676/cjb9jhkjhbm78_o/0087start_m.jpg
http://s7.depic.me/07666/56ygjfjh7kikg_o/0087start_t.jpg

File Name.type: 0087start.wmv
Resolution: 640x480
Duration: 0:53:20
Filesize: 311Mb

Download
https://k2s.cc/file/059we76456/0087start.mp4
//==================
Subject message


http://s5.depic.me/06396/xj0hgkoio_o/0248google_m.jpg
http://s5.depic.me/67556/w12jhgjblxh_o/0248google_t.jpg

File Name.type: 0248google.mp4
Resolution: 1280x720
Duration: 0:05:44
Filesize: 169Mb

Download
https://k2s.cc/file/8c76web35b/0248google.mp4
//==================
Subject message


http://s6.depic.me/07396/uzpqptzh8rxl_o/0007start_m.jpg
http://s7.depic.me/07156/puojhjh95tn_o/0007start_t.jpg

File Name.type: 0007start.mp4
Resolution: 1280x720
Duration: 0:05:35
Filesize: 59Mb

Download
https://k2s.cc/file/28s76ds8d82/0007start.mp4
//==================

Примечание: Домены в ссылках могут быть разными.

К скрипте я указываю путь/имя создаваемых файлов, а также маску имени файла в ссылке:
firstpackuurl.txt
*start*

secondpackurl.txt
*yandex*

В результате выполнения скрипта, должны создаться два txt файла:

firstpackuurl.txt
Subject message


http://s7.depic.me/065676/cjb9jhkjhbm78_o/0087start_m.jpg
http://s7.depic.me/07666/56ygjfjh7kikg_o/0087start_t.jpg

File Name.type: 0087start.wmv
Resolution: 640x480
Duration: 0:53:20
Filesize: 311Mb

Download
https://k2s.cc/file/059we76456/0087start.mp4
//==================
Subject message


http://s6.depic.me/07396/uzpqptzh8rxl_o/0007start_m.jpg
http://s7.depic.me/07156/puojhjh95tn_o/0007start_t.jpg

File Name.type: 0007start.mp4
Resolution: 1280x720
Duration: 0:05:35
Filesize: 59Mb

Download
https://k2s.cc/file/28s76ds8d82/0007start.mp4
//==================

secondpackurl.txt
Subject message


http://s5.depic.me/0686/zp0hjgh3m7d_o/0634yandex_m.jpg
http://s6.depic.me/06876/26fhgh8kxo8_o/0634yandex_t.jpg

File Name.type: 0634yandex.avi
Resolution: 1920x1080
Duration: 0:08:56
Filesize: 952Mb

Download
https://k2s.cc/file/f07we76wee3/0634yandex.mp4
//==================

megaloman
23-10-2018, 15:52
FileIn = "Z:\Box_In\Большой txt файл.txt"
Delim = "//=================="
sURL = "[b]Download"

OutFiles = Array("start", "Z:\Box_Out\firstpackuurl.txt", _
"yandex", "Z:\Box_Out\secondpackurl.txt", _
"oszone", "Z:\Box_Out\для отладки несуществующего.txt", _
"google", "Z:\Box_Out\thirdpackurl.txt")
i1 = LBound(OutFiles)
NFiles = Int(((UBound(OutFiles) - i1) + 1) / 2)

Set FSO = CreateObject("Scripting.FileSystemObject")

Set fIn = FSO.OpenTextFile(FileIn, 1, False) ', -2)
Alls = fIn.ReadAll
fIn.Close

Mas = Split(Alls, Delim)
Set Alls = Nothing

ReDim OutTxt(NFiles)
For i = 1 To NFiles
OutTxt(i) = ""
Next

For Each iMas In Mas
iURL = Split(iMas, sURL)
i2 = UBound(iURL)
If i2 - i1 > 0 Then
For i = 1 To NFiles
ii = InStrRev(iURL(i2), OutFiles(2 * i - 2 + i1))
If ii > 0 Then
OutTxt(i) = OutTxt(i) + iMas + Delim
End If
Next
End If
Next

For i = 1 To NFiles
If Len(OutTxt(i)) <> 0 Then
Set fIn = FSO.CreateTextFile(OutFiles(2 * i - 1 + i1), True)
fIn.Write OutTxt(i)
fIn.Close
End If
Next

Alexander_88
26-10-2018, 18:05
Спасибо, компьютер как назло сломался. На днях протестирую обязательно

Alexander_88
25-11-2018, 23:50
Проверил, все работает.. единственное, в каждом выводимом txt документе, в самом верху одна пустая строка.




© OSzone.net 2001-2012