Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Insert filename into files in batch  (Read 3246 times)

0 Members and 1 Guest are viewing this topic.

_unknown_

    Topic Starter


    Beginner

    • Experience: Beginner
    • OS: Windows 7
    Insert filename into files in batch
    « on: January 30, 2016, 12:47:20 PM »
    I have numerous .vrt files with a pattern in the file name from a directory:
    Code: [Select]
    Data2016001045000.level1_level2.newDATA_main.vrt
    Data2016002055000.level1_level2.newDATA_main.vrt
    and so on . . .

    and the content of the files looks like this:
    Code: [Select]
       <Insert="Line 1">
         <Insert="Line 2">file1.vrt</Line2>
         <Insert="Line 2">1</Line2>
         <Insert="Line 3">file2.vrt</Line3>
         <Insert="Line 3">1</Line3>
         <Another line="Line 4">0</Line4>
       </Insert>

    In this line, "file1.vrt" should be replaced with the file that I want to insert from another directory. The file that should be inserted in here should be the same as the file name above but will only differ in the last part of the file name: Data2016001045000.level1_level2.newDATA _abc.vrt.
    Code: [Select]
         <Insert="Line 2">file1.vrt</Line2>

    In this line, "file2.vrt" should be replaced with the file that I want to insert from another directory. The file that should be inserted in here should be the same as the file name above but will only differ in the last part of the file name: Data2016001045000.level1_level2.newDATA _def.vrt.
    Code: [Select]
         <Insert="Line 3">file2.vrt</Line3>

    The output should be like this:
    Code: [Select]
       <Insert="Line 1">
         <Insert="Line 2">C:\path\to\file\Data2016001045000.level1_level2.newDATA_abc.vrt</Line2>
         <Insert="Line 2">1</Line2>
         <Insert="Line 3">C:\path\to\file\Data2016001045000.level1_level2.newDATA_def.vrt</Line3>
         <Insert="Line 3">1</Line3>
         <Another line="Line 4">0</Line4>
       </Insert>

    That means there is an equivalent *.newDATA_abc and *.newDATA_def to be inserted in every *.newDATA_main.vrt file, . So that in every run of the batch file the newDATA_abc and newDATA_def will be included in processing the *newDATA_main.vrt files.

    Allan

    • Moderator

    • Mastermind
    • Thanked: 1260
    • Experience: Guru
    • OS: Windows 10
    Re: Insert filename into files in batch
    « Reply #1 on: January 31, 2016, 02:13:39 PM »
    Please stop opening new threads for the same problem. You already have at least one or two other threads going. I'm locking this one.