Computing.Net > Forums > Programming > Batch file to copy and edit file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to copy and edit file

Reply to Message Icon

Name: pball
Date: September 19, 2008 at 12:10:14 Pacific
OS: xp
CPU/Ram: 2 ghz 1 gig
Product: HP
Comment:

I do a bit of encoding and am trying to automate some parts. I have to create an avs script file for the encoding process and would like to be able to make one then have a batch script make more for the rest of the series.

The avs file has a file name in it, which i just use numbers for while i encode. So I'll have to copy the text inside the file, then replace the episode # with the next higher number then write it to a file.

So this is what the first avs file would look like (just making it up don't have one at the moment)

blahblahblah(e:\encoding\series\1.dv2)
interlace(true?)
crop(8,0,-8,0)

I would like to read that file, then replace 1.dv2 with 2.dv2 then write it to 2.avs as the file name.

I'm not familiar with reading files or replacing things in batch so if I could get some directions there I'd appreciate it. If it isn't a pain could you just help me with the reading and replacing and let me try to figure out the rest, such as looping and counting.



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: September 19, 2008 at 14:06:51 Pacific
Reply:

The secret is to do the file from scratch.

FOR %%a IN (e:\encoding\series\*.dv2) DO @(
ECHO AVISource("%%~Fa"^)
ECHO interlace(true?^)
ECHO crop(8,0,-8,0^)) > %%~Na.avs

NOTE: I know not of an interlace filter. Did you mean bob?

0

Response Number 2
Name: Mechanix2Go
Date: September 19, 2008 at 14:16:39 Pacific
Reply:


@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (1.avs) do (
set /a N+=1
if !N! equ 1 (
set str=%%a
set head=!str:~0,-6!
set tail=!str:~-6!
set end=!tail:~-5!
set /a #=!tail:~0,1!
set /a #+=1
echo !head!!#!!end!> !#!.avs
) else (
echo %%a>> !#!.avs
)
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: pball
Date: September 19, 2008 at 18:38:42 Pacific
Reply:

Razor2.3
that would indeed the be the easy way to do it, but that requires editing the batch file, also i made up that script stuff

M2
Lovely looking script but i think it's off cause of my input.

dgdecode_Mpeg2Source("f:\encoding\bebop\1.dv2")
Crop(0,4,-4,0)
Spline36resize(704,528)

that is actually what the avs file will look like plus or minus lines. The file name will always be at the end of the first line though.

also i would just like to create the 2-26 avs files since 1 is the template to go off of.


0

Response Number 4
Name: Razor2.3
Date: September 23, 2008 at 16:15:44 Pacific
Reply:

You know, now that I revisit this, I remember the 'S' in AVS stands for Script. This means you can set a template file up like:

dgdecode_Mpeg2Source("f:\encoding\bebop\" + num + ".dv2")
Crop(0,4,-4,0)
Spline36resize(704,528)

Then, your batch file could do:
FOR /L %%A IN (1,1,10) DO (
@ECHO num = "%%A" > #
COPY #+template.avs %%A.avs
)


0

Response Number 5
Name: pball
Date: September 23, 2008 at 16:31:50 Pacific
Reply:

that doesn't seem to be working on my end. I get a # file and %a.avs file when i run it with a template.avs file in the same folder


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: September 23, 2008 at 17:09:36 Pacific
Reply:

Oh, sorry. Change the %%A to the same case, be it upper or lower. (Fixed example.)


0

Response Number 7
Name: pball
Date: September 23, 2008 at 18:35:21 Pacific
Reply:

I took what you did and just made if copy the template an entered number of times.

@echo off
echo enter episodes
set /p ep=
FOR /L %%A IN (1,1,%ep%) DO (
COPY template.avs %%A.avs
)

So I'll have a bunch of files with this as the first line

DGDecode_mpeg2source("_placeholder_.d2v",info=3)

I'd like to replace _placeholder_ with the name of the file it's in minus the extension. How can I do that in a new loop after the above script makes them?



0

Response Number 8
Name: pball
Date: September 25, 2008 at 11:02:54 Pacific
Reply:

well searching around here found me the replacing part i needed. So I whipped this up.

@echo off
setlocal EnableDelayedExpansion

echo enter episodes
set /p ep=

FOR /L %%A IN (1,1,%ep%) DO (
for /f "tokens=*" %%a in (template.avs) do (
set C=%%a
set B=!C:_replaceme_=%cd%%%A!
echo !B! >> %%A.avs
)
)

That takes a template.avs file with _replaceme_ stuck in where the file name goes. Run this and enter how many avs scripts you wish to make and viola they are made.

EDIT
I made it work by myself yay.

I did a help for in cmd and got this handy info

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file

so I made this

@echo off
setlocal EnableDelayedExpansion

echo drag and drop avs template into window
set /p avs=
for /f "tokens=* delims= " %%f in ("!avs!") do (
set avs2=%%~dpf
)

echo enter episodes
set /p ep=

FOR /L %%A IN (1,1,%ep%) DO (
for /f "tokens=*" %%a in (%avs%) do (
set C=%%a
set B=!C:_replaceme_=%avs2%%%A!
echo !B! >> %avs2%%%A.avs
)
)

it works as long as the input file has no spaces in it path name


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to copy and edit file

batch file to copy and move certain www.computing.net/answers/programming/batch-file-to-copy-and-move-certain/11052.html

Batch Job to Copy folders www.computing.net/answers/programming/batch-job-to-copy-folders-/18383.html

Batch sript to copy the folders modified toda www.computing.net/answers/programming/batch-sript-to-copy-the-folders-modified-toda/19369.html