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

Author Topic: batch file  (Read 3001 times)

0 Members and 1 Guest are viewing this topic.

dave_watkins

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    batch file
    « on: March 19, 2016, 09:41:04 PM »
    hi guys

    I am out onsite in china and I have written my first batch file using the internet and making it work the code below works well it moves files that are created over the day to a folder and then renames the folder with unique day. this works perfectly well when I run it by clicking on it I then used task scheduler to run it daily at the same time only half works it creates the folder and moves the files to the folder but does not rename it with the date this is a problem because when it runs the next time it overwrites the folder.

    if you have any ideas it would be much appreciated.
    @echo off
    mkdir  "c:\data_log_files\Stored_Data"
    move /y "C:\data_log_files\*Data_Logs*.XLS" "C:\data_log_files\Stored_Data"
    for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename c:data_log_files\Stored_Data Stored_Data(%%d-%%e-%%f)


    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: batch file
    « Reply #1 on: March 20, 2016, 08:20:20 AM »
    c:data_log_files\Stored_Data Stored_Data(%%d-%%e-%%f)

    changed to add the \ for c:\

    c:\data_log_files\Stored_Data Stored_Data(%%d-%%e-%%f)

    also I'd change mkdir to md

    Maybe that will fix it. So you have Data_Logs that have characters leading and trailing in the file names to require the double wild card? Just asking because most files I have seen either have leading or trailing dynamic info used in file names but not both. Additionally if the only files located here that are XLS's are the ones you want you can more simply just use *.xls for all XLS files. But guessing you have a need for the double wild card however just questioning this for prepend and appended characters in file name which is somewhat unusual.

    Below has the suggested change/corrections:

    Code: [Select]
    @echo off
    md  "c:\data_log_files\Stored_Data"
    move /y "C:\data_log_files\*Data_Logs*.XLS" "C:\data_log_files\Stored_Data"
    for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename c:\data_log_files\Stored_Data Stored_Data(%%d-%%e-%%f)

    dave_watkins

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Windows 7
      Re: batch file
      « Reply #2 on: March 21, 2016, 07:54:26 AM »
      thanks for taking a look and the advice I managed to make it work in task scheduler in the script I put just the batch file name and in open in I put the file destination.

      thanks