Copy a file to unknown directory name

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Dec 18, 2008
4
0
#1
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.
 

samintz

Scott Mintz
May 20, 2008
1,204
11
Solon, OH, USA
#2
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:


> 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.
>
>
>
>
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,385
39
Albuquerque, NM
prospero.unm.edu
#3
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?
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
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:

> 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.
>
>
>
>
>


--
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
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