1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Copy a file to unknown directory name

Discussion in 'Support' started by glennw, Jun 8, 2009.

  1. glennw

    Joined:
    Dec 18, 2008
    Messages:
    4
    Likes Received:
    0
    This might be simple.

    I need to copy a file to a directory name that will be changing monthly.

    I _know_ the directory name will be the only directory that starts with a "2" so Dir 2* will always return my directory name (for example, 20090430)

    How can I copy a file to that directory name?

    One way thought I had was to store the directory name as a variable (actually store the directory name in a file and then create a variable from the one line in that file) and then copy the file to that variable name.

    Is there any easier way?

    Thanks.
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,179
    Likes Received:
    11
    Well, if it's as simple as copying a single file, just use <TAB>
    completion to fill out the directory name.

    copy myfile 2<TAB>

    etc.

    -Scott

    glennw <> wrote on 06/08/2009 11:21:52 AM:


     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    You can skip the intermediate file and stash the name directly in a variable using @EXECSTR:

    Code:
    set dirname=%@execstr[dir /ad /f 2*]
    
     
  4. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    605
    Likes Received:
    0
    You could also use this in a batch file

    copy myfile %@expand[2*,d]


    On Mon, Jun 8, 2009 at 8:21 AM, glennw<> wrote:



    --
    Jim Cook
    2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
    Next year they're Sunday.
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    glennw wrote:
    | This might be simple.
    |
    | I need to copy a file to a directory name that will be changing
    | monthly.
    |
    | I _know_ the directory name will be the only directory that starts
    | with a "2" so Dir 2* will always return my directory name (for
    | example, 20090430)
    |
    | How can I copy a file to that directory name?
    | ...
    |
    | Is there any easier way?



    samintz wrote:
    | Well, if it's as simple as copying a single file, just use <TAB>
    | completion to fill out the directory name.
    |
    | copy myfile 2<TAB>
    |
    | etc.

    If instead of interactively, you need to it in a batch file, you could do it
    as:

    copy myfile %@expand[2*,D]
    --
    HTH, Steve
     
  6. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    I like your suggestion better than my own....
     

Share This Page