Creating a txt file certain structure.

March 26, 2010 at 03:37:54
Specs: Windows Server 2003, 3.0/4 Gb.
Good afternoon.
Need batch which does the following:
1) Check in enactments folder (D:\log) existence of a file group.txt
a) If the file is not there, run the command from step 2.
b) If the folder D:\log file group.txt is, changes the name of an existing file on group1.txt, unless there group1.txt - changes in group2.txt, group3.txt, group4.txt, ... run the command from step 2.
2) echo %date% %time%> D: \ log \ group.txt

3) echo %name%>> D: \ log \ group.txt
4) day.ovpl %name%>> D: \ log \ group.txt

5) echo %name%>> D: \ log \ group.txt
6) day.ovpl %name%>> D: \ log \ group.txt

7) ...

8) echo %name%>> D: \ log \ group.txt
9) day.ovpl %name%>> D: \ log \ group.txt

Continue until you do go over all the variable %name%.
The values for the variable %name% are listed in the file D: \ log \ name.txt - in the column indicated dozens of words, example:
february
march
april
The result, in the folder D:\log a few old files group1.txt, group2.txt, group3.txt, group4.txt and new group.txt, the files are as follows:

february
lkhjfaklhdfjkh dklhfsjklhdf dkafhdsjklfhkjd
adsfli;fjdklsjf ldfjklasdjflkj dlfajdklfkl
march
lkhjfaadf32dfjkh dkldfsfhfsjklhdf dkafhdsjfhkjd
adsflisdfjdklsjf ldfjklfsfdjflkj dlfajdkfkl
april
dafsjklsdjfl lkasfjhdfjkl
34jkl2hjkl45huiyuh kdjfhkjl4h5k3 kh453892yhjk
l4h3jk2g5jk
b4kj5hjk234h5jk4h5jk flgjslkjg 45hjklhjklj


See More: Creating a txt file certain structure.

Report •


#1
March 26, 2010 at 08:42:06
What about this:

@echo off
setlocal enabledelayedexpansion

set p_dir=D:\temp

if not exist %p_dir%\group.txt goto :new

set max=0

for /L %%a in (1,1,99999) do (
if exist %p_dir%\group%%a.txt set max=%%a
)

echo max=%max%

for /L %%a in (%max%,-1,1) do (
set /a onehigher=%%a+1
echo rename %p_dir%\group%%a.txt %p_dir%\group!onehigher!.txt
)

echo rename %p_dir%\group.txt %p_dir%\group1.txt

:new
echo %date% %time%> %p_dir%\group.txt
echo %name%>> %p_dir%\group.txt
day.ovpl %name%>> %p_dir%\group.txt
echo %name%>> %p_dir%\group.txt
day.ovpl %name%>> %p_dir%\group.txt
echo %name%>> %p_dir%\group.txt
day.ovpl %name%>> %p_dir%\group.txt


Report •

#2
March 29, 2010 at 00:16:40
tvc, thank you very much for your help.
I want to clarify one point, the variables in the file name.txt may be many (10, 20 - 50).
You can edit the batch, taking into account the above said?

Report •

#3
March 31, 2010 at 06:20:54
Help please to realize the functional indicated higher.
Continue until you do go over all the variable %name%.
The values for the variable %name% are listed in the file D: \ log \ name.txt - in the column indicated dozens of words, example:
february
march
april
dsfkjsdkl
dfsjklhfldk
sdfkjl
....
lksdnhfjkldhf
The variables in the file name.txt may be many (10, 20 - 50).


Report •

Related Solutions

#4
March 31, 2010 at 07:17:09
I'm not sure I understand that

Report •

#5
April 1, 2010 at 01:50:24
It's my mistake.
I'll try to explain.
In the first part:
Need batch which does the following:
1) Check in enactments folder (D: \ log) existence of a file group.txt
a) If the file is not there, run the command from step 2.
b) If the folder D: \ log file group.txt is, changes the name of an existing file on group1.txt, unless there group1.txt - changes in group2.txt, group3.txt, group4.txt, ... run the command from step 2.

- all ok.

It remains to implement the second part.
Need a cycle that takes the first variable with a file name.txt, inserts it instead of %name% and executes two commands:
echo %name%>>%p_dir%\group.txt
day.ovpl %name%>>%p_dir%\group.txt
then takes the following variable name.txt and until you do go over all the variables from the file name.txt.

For example, if the file name.txt contains 6 variables (in real name.txt, variables will be greater than 40):

qwe
asd
zxc
rty
fgh
vbn

then the cycle should substitute the value of name.txt and run the following commands for each variable from name.txt:

echo qwe>>%p_dir%\group.txt
day.ovpl qwe>>%p_dir%\group.txt

echo asd>>%p_dir%\group.txt
day.ovpl asd>>%p_dir%\group.txt

echo zxc>>%p_dir%\group.txt
day.ovpl zxc>>%p_dir%\group.txt

echo rty>>%p_dir%\group.txt
day.ovpl rty>>%p_dir%\group.txt

echo fgh>>%p_dir%\group.txt
day.ovpl fgh>>%p_dir%\group.txt

echo vbn>>%p_dir%\group.txt
day.ovpl vbn>>%p_dir%\group.txt


Report •

#6
April 1, 2010 at 07:52:16
@echo off

set p_dir=D:\temp

for /f %%f in (test.txt) do (
echo %%f>>%p_dir%\group.txt
day.ovpl %%f>>%p_dir%\group.txt
)


Report •

#7
April 3, 2010 at 03:42:49
'Collect' the two parts together, but does not work, goes into a loop.
Help solve the problem:

@echo off
setlocal enabledelayedexpansion

set p_dir=D:\temp

if not exist %p_dir%\group.txt goto :new

set max=0
## Here, goes into a loop
for /L %%a in (1,1,99999) do (
if exist %p_dir%\group%%a.txt set max=%%a
)

## Here, goes into a loop
echo max=%max%

for /L %%a in (%max%,-1,1) do (
set /a onehigher=%%a+1
echo rename %p_dir%\group%%a.txt %p_dir%\group!onehigher!.txt
)

echo rename %p_dir%\group.txt %p_dir%\group1.txt

:new

for /f %%f in (test.txt) do (
echo %%f>>%p_dir%\group.txt
day.ovpl %%f>>%p_dir%\group.txt
)


Report •

#8
April 3, 2010 at 07:30:26
You may be confusing a long action with an endless loop, which may be harder to differentiate on older (slower) machines. Run this & report:

@echo on
setlocal enabledelayedexpansion

set p_dir=D:\temp

if not exist %p_dir%\group.txt goto :new

set max=0

for /L %%a in (1,1,99999) do (
if exist %p_dir%\group%%a.txt set max=%%a
echo counter=%%a
echo max=!max!
)

echo max=%max%
echo max=!max!


Report •

#9
April 5, 2010 at 04:31:56
Can't be running that long

Report •

#10
April 6, 2010 at 05:42:21
Here part of the log:
...
D:\TEMP>(
if exist D:\TEMP\group43.txt set max=99992
echo counter=99992
echo max=!max!
)
counter=99992
max=2

D:\TEMP>(
if exist D:\TEMP\group44.txt set max=99993
echo counter=99993
echo max=!max!
)
counter=99993
max=2

D:\TEMP>(
if exist D:\TEMP\group45.txt set max=99994
echo counter=99994
echo max=!max!
)
counter=99994
max=2

D:\TEMP>(
if exist D:\TEMP\group46.txt set max=99995
echo counter=99995
echo max=!max!
)
counter=99995
max=2

D:\TEMP>(
if exist D:\TEMP\group47.txt set max=99996
echo counter=99996
echo max=!max!
)
counter=99996
max=2

D:\TEMP>(
if exist D:\TEMP\group48.txt set max=99997
echo counter=99997
echo max=!max!
)
counter=99997
max=2

D:\TEMP>(
if exist D:\TEMP\group49.txt set max=99998
echo counter=99998
echo max=!max!
)
counter=99998
max=2

D:\TEMP>(
if exist D:\TEMP\group50.txt set max=99999
echo counter=99999
echo max=!max!
)
counter=99999
max=2

D:\TEMP>echo max=2
max=2

D:\TEMP>echo max=!max!
max=2


P.S.: before start, in D:\TEMP I created a file group2.txt.


Report •

#11
April 6, 2010 at 05:52:21
And 1 more question.
If I have a file test.txt variables can contain spaces. How do I edit the second part:
:new
for /f %%f in (test.txt) do (
echo %%f>>%p_dir%\group.txt
day.ovpl %%f>>%p_dir%\group.txt
)

to accommodate this?

Report •

#12
April 6, 2010 at 09:34:19
just add the tokens:
for /f "tokens=*" %%f in (test.txt) do (

Report •

#13
April 6, 2010 at 10:49:07
That is weird ... I don't see how this :

if exist D:\TEMP\group43.txt set max=99992
echo counter=99992

matches code :

if exist %p_dir%\group%%a.txt set max=%%a
echo counter=%%a

%%a should be equal ... how can it be 43 and 99992 at the same time ?

I see 2 things only:
- setlocal enabledelayedexpansion ... you did specify it ?
- "%%a.txt" may be interpreted wrongly ?!


Report •

#14
April 7, 2010 at 01:23:46
started again
...
D:\TEMP>(
if exist D:\TEMP\group99992.txt set max=99992
echo counter=99992
echo max=!max!
)
counter=99992
max=2

D:\TEMP>(
if exist D:\TEMP\group99993.txt set max=99993
echo counter=99993
echo max=!max!
)
counter=99993
max=2

D:\TEMP>(
if exist D:\TEMP\group99994.txt set max=99994
echo counter=99994
echo max=!max!
)
counter=99994
max=2

D:\TEMP>(
if exist D:\TEMP\group99995.txt set max=99995
echo counter=99995
echo max=!max!
)
counter=99995
max=2

D:\TEMP>(
if exist D:\TEMP\group99996.txt set max=99996
echo counter=99996
echo max=!max!
)
counter=99996
max=2

D:\TEMP>(
if exist D:\TEMP\group99997.txt set max=99997
echo counter=99997
echo max=!max!
)
counter=99997
max=2

D:\TEMP>(
if exist D:\TEMP\group99998.txt set max=99998
echo counter=99998
echo max=!max!
)
counter=99998
max=2

D:\TEMP>(
if exist D:\TEMP\group99999.txt set max=99999
echo counter=99999
echo max=!max!
)
counter=99999
max=2

D:\TEMP>echo max=2
max=2

D:\TEMP>echo max=!max!
max=2


Report •

#15
April 8, 2010 at 04:33:02
Looks OK now ... something changed in your code, between the output as posted in R10 and the one in R14. Looks OK now. If it takes too much time to go to counter of 99999 (after removing ECHO ON and other ECHO's), limit the counter to a less high number. Take in mind that it should still be high enough.

Report •

#16
April 8, 2010 at 04:48:19
tvc, thank you.

Report •

Ask Question