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

Author Topic: Appending Files and Combining File names  (Read 3063 times)

0 Members and 1 Guest are viewing this topic.

JohnD

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Appending Files and Combining File names
    « on: March 30, 2015, 03:24:47 PM »
    Hi,

    I'm new to DOS and I've written a batch file that combines the contents of multiple csv files, creating a new file (without duplicate headers). However, what I'm struggling to work out is how to rename the new file according to the filename/s of the original csvs.
    For example, I have two csv files called:
    YYMMDD Type 1_Part 1
    YYMMDD Type 1_Part 2

    What my batch file creates is a new file called "Combined data". I then manually rename the new file (in the format YYMMDD, followed by the type of data the file contains). So, the final result is "YYMMDD Type 1".

    I do this daily, but the dates and the type of data changes each time. So, essentially what I need to be able to do is to combine csvs which have the same date and 'Type' of data and produce a master csv named by the date of the file and the type of the data (without the '_Part x' on the end).

    Any help would be much appreciated!

    Thanks.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Appending Files and Combining File names
    « Reply #1 on: March 30, 2015, 04:04:36 PM »
    To give you exact code we need a representative list of the filenames - as spaces and things will change the way it is handled.

    JohnD

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Windows 7
      Re: Appending Files and Combining File names
      « Reply #2 on: March 31, 2015, 03:53:46 AM »
      The spaces within the examples will remain the same. However, the character length of each part of text changes. I.e. 'Type' could be 'Model', '1' could be '15', Part could be 'Component' and '1' could be '100'.

      E.g. one day it might be:
      YYMMDD Model 15_Part 6
      YYMMDD Model 15_Component 1

      The desired outcome: YYMMDD Model 15

      Another day it may be:
      YYMMDD Design 12_Specification 3
      YYMMDD Design 12_Specification 4

      The desired outcome: YYMMDD Design 12

      Again, what I'm essentially looking to do is to rename the new file according to what is left of the underscore in the original files.

      Thanks.

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Appending Files and Combining File names
      « Reply #3 on: March 31, 2015, 04:01:37 AM »
      If the part before the underscore is what you need then a simple for loop can extract it.

      Code: [Select]
      for /f "delims=_" %%a in ("YYMMDD Model 15_Part 6") do echo "%%a"
      Getting it inside your script will depend on how it is written.

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Appending Files and Combining File names
      « Reply #4 on: April 02, 2015, 02:51:29 AM »
      Was this enough information to help you?