1.

Solve : Rename a file per content?

Answer»

I have multiple files in a folder and each one needs to be opened; read the first line and determine one of several files to append the entire contents of the opened file to.
Example:
77521.txt
:JobShop22:
Text1
Text2
Text3

77522.txt
:JobShop48:
Text1
Text2
Text3


77523.txt
:JobShop22:
TextA
TextB
TextC


If first line == ":JobShop22:" then append to file Job22Output.txt
If first line == ":JobShop66:" then append to file Job66Output.txt
If first line == ":JobShop48:" then append to file Job48Output.txt

RESULTS:
Job22Output.txt
:JobShop22:
Text1
Text2
Text3
:JobShop22:
TextA
TextB
TextC



Job48Output.txt
:JobShop48:
Text1
Text2
Text3

I hope this makes sense!
Any help on this would be greatly appreaciated.



Anyone??? EDIT: Nevermind.This ASKS for user input, then sets %file% as the first line of %filevar% and it will append the full contents of %filevar% to the TXT file, depending on what the first line is.

@echo off
:loop
set /p filevar=FILE NAME INCLUDING PATH:
set /p file=<"%filevar%"
if %file% == :JobShop22: type "%filevar%" >> Job22Output.txt & goto win
if %file% == :JobShop66: type "%filevar%" >> Job66Output.txt & goto win
if %file% == :JobShop48: type "%filevar%" >> Job48Output.txt & goto win
Echo Error! File does not contain SPECIFIED strings in the first line!
pause
goto :loop
:win
Echo ALL DONE!
pauseThank you!
That part is exactly what I needed.
What do I need to do to make it read multiple files from a folder without the user input?That is FAIRLY simple as well, but the code gets MUCH longer depending on how many files you want.

Basically, delete Code: [Select]set /p filevar=FILE NAME INCLUDING PATH:
And replace Code: [Select]set /p file=<"%filevar%"With Code: [Select]set /p file=<"YOUR FILE NAME HERE"
Then, copy it over and over, replacing "goto win" with "goto WIN2" the second time, and ":win" with ":win2" the second time(and so on and so forth). Just do a bit of nitpicking with the script and it will work as many times as you want.



Discussion

No Comment Found