Pass partial parameter in bat file


  1. Posts : 57
    Windows 10
       #1

    Pass partial parameter in bat file


    I have about 200 files
    examples:
    20200101 FILE10.TXT
    20200102 FILE10.TXT
    20200103 FILE10.TXT
    20200104 FILE10.TXT

    I need a way to accept only the first 8 positions in a bat file and copy the whole file to another directory.
    If enter 20200101 and it will pass the file 20200101 FILE10.TXT to another directory.
    After it is passed it has to be renamed to update.txt to be run from inside another bat file.
    Presently, I have to manually copy each file to the other directory.
      My Computer


  2. Posts : 8,111
    windows 10
       #2

    Copy 20200104*.txt c:\folder should do it
      My Computer


  3. Posts : 11,247
    Windows / Linux : Arch Linux
       #3

    GUPPY said:
    I have about 200 files
    examples:
    20200101 FILE10.TXT
    20200102 FILE10.TXT
    20200103 FILE10.TXT
    20200104 FILE10.TXT

    I need a way to accept only the first 8 positions in a bat file and copy the whole file to another directory.
    If enter 20200101 and it will pass the file 20200101 FILE10.TXT to another directory.
    After it is passed it has to be renamed to update.txt to be run from inside another bat file.
    Presently, I have to manually copy each file to the other directory.
    Hi there
    @GUPPY

    this would be known as a substring function in most programming languages --however it works in a windows batch cmd :

    %variable:~num_chars_to_skip, -num_chars_to_keep%

    e.g SET _test=123456789abcdef0

    for example to extract only the first 5 characters of variable _test

    SET _result=%_test:~0,5%
    ECHO %_result% =12345

    Now you need CONCATENATE type of function (add the .txt to the first variable where you've extracted the 8 chars)

    e.g

    @echo off
    set myvar="the list: "
    for /r %%i in (*.doc) DO call :concat %%i
    echo %myvar%
    goto :eof

    :concat
    set myvar=%myvar% %1;
    goto :eof

    "Seemples !!!"

    Modify for your directories -- and include copy / other funcs you need..
    Cheers
    jimbo
      My Computer


  4. Posts : 44
    HP: Win 10 / Ubuntu dual boot || T530: Win 7 Pro
       #4

    Good info from the above two posters.... Also An A-Z Index of Windows CMD commands - SS64.com is a handy reference for MSDos box commands.

    ~~~~~~~~~~
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:07.
Find Us




Windows 10 Forums