how do you code this?
i have these files with their file sizes:
357471675_OtherSupporting_page_0001.txt - more than 1000 bytes
357471675_OtherSupporting_page_0002.txt - more than 1000 bytes
357471675_OtherSupporting_page_0003.txt - more than 1000 bytes
357471675_OtherSupporting_page_0004.txt - less than 500 bytes
357471675_OtherSupporting_page_0005.txt - less than 3 bytes
357471675_OtherSupporting_page_0006.txt - more than 1000 bytes
357471675_OtherSupporting_page_0007.txt - less than 500 bytes
357471675_OtherSupporting_page_0008.txt - less than 3 bytes
357471675_OtherSupporting_page_0009.txt - more than 1000 bytes
357471675_OtherSupporting_page_0010.txt - less than 500 bytes
the contents of files with more than 1000 bytes are random character or paragraphs
the contents of files with less than 500 bytes are "Sequence Number: X", where x is a random number
and files with less than 3 bytes are blank.
They are sorted by name, files with more than 1000 bytes belongs to the file with less than 500 bytes, as for the above example, 357471675_OtherSupporting_page_0001.txt to 357471675_OtherSupporting_page_0003.txt belongs to 357471675_OtherSupporting_page_0004.txt, 357471675_OtherSupporting_page_0006.txt belongs to 357471675_OtherSupporting_page_0007.txt and 357471675_OtherSupporting_page_0009.txt to 357471675_OtherSupporting_page_0010.txt.
Now this is what I wanted to do:
1. I want to delete the files with less than 3 bytes.
2. I want to merge 357471675_OtherSupporting_page_0001.txt to 357471675_OtherSupporting_page_0003.txt and write it to a text file with this filename, 357471675_OtherSupporting_seq_X.txt, where X is the sequence number found in where these files belong to.
3. And if the files doesn't requires merging, as for the examplae above, 357471675_OtherSupporting_page_0006.txt and 357471675_OtherSupporting_page_0009.txt they will be renamed to 357471675_OtherSupporting_seq_X.txt where X is the sequence number found in where these files belong to.
I have written some scripts to do that but my batch files requires a proper file structure, it only works on these files structure:
357471675_OtherSupporting_page_0001.txt - more than 1000 bytes
357471675_OtherSupporting_page_0002.txt - less than 500 bytes
357471675_OtherSupporting_page_0003.txt - more than 1000 bytes
357471675_OtherSupporting_page_0004.txt - less than 500 bytes
357471675_OtherSupporting_page_0005.txt - more than 1000 bytes
357471675_OtherSupporting_page_0006.txt - less than 500 bytes
357471675_OtherSupporting_page_0007.txt - more than 1000 bytes
357471675_OtherSupporting_page_0008.txt - less than 500 bytes
Note that I manually deleted all the blank text files.
Here's my script:
Code: Select all
@echo off
color 1F
title Please wait...
MODE CON: COLS=30 LINES=1
setlocal enabledelayedexpansion
for /f "tokens=2 delims= " %%z in ('findstr "SequenceNumber" "*.txt"') do (
echo %%z>> seq
)
set "suffix=.txt"
for /f "tokens=1-2 delims=_" %%a in ('dir /b "*.txt"') do (set "fnum=%%a_%%b")
for /f "tokens=1 delims=" %%y in ('findstr /m "SequenceNumber" "*.txt"') do (
set "delf=%%y"
del /f /q !delf!
)
for /f "tokens=1 delims=" %%x in ('dir /b "*.txt"') do (
set "renit=%%x"
for /f "tokens=1 delims=" %%w in (seq) do (
ren "!renit!" "!fnum!_seq_%%w%suffix%"
)
)
del /f /q seq
Note also that, the filename of my source files are not constant:
the "dynamic_dynamic_page_0001.txt"
thanks in advance.