read an unknown directories name + copy to it

August 8, 2009 at 12:20:47
Specs: Windows 7
Hello everyone,
I would appreciate some help please. I am trying to copy two files "test1.txt" and "test2.txt" into an unknown directory, e.g. into the directory "%USERNAME%\Documents\test\04pql7hw.example"
The first section of the directory name is a randomized string of letters
and numbers and the second section "example" is constant for every pc,
e.g the directory name could be "gjl39756.example" or

So far i think that the starting point should be a batch file which copies a list of the directory "%USERNAME%\Documents\test" sub directorie's into a
text document, and it saves into the same directory.

dir /ad >list.txt

As the only subdirectory in the directory
"%USERNAME%\Documents\test" is the unknown directory e.g
"04pql7hw.example" the resulting text document will always have the
directory name at the same line and character positions of the file.
here is the an example of the resulting list.txt

 Volume in drive C has no label.
 Volume Serial Number is 82CE-AEC8

 Directory of C:\Users\%USERNAME%\Test\

08/08/2009  02:51    <DIR>          .
08/08/2009  02:51    <DIR>          ..
06/08/2009  22:49    <DIR>          04pql7hw.example
               0 File(s)              0 bytes
               3 Dir(s)  430,968,176,640 bytes free

I then thought that a vbscript could read that specifice line and
characters, and then use this information to copy the two files to the
unknown folder.

The script i have so far is this...please dont laugh as i am a scripting

Set FS = CreateObject("Scripting.FileSystemObject")
    Set f1 = fs.OpenTextFile("%USERNAME%\test\", 1, False)
myarr = split(f1.ReadAll, vbnewline)
mystr = mid( myarr(8), 36, 16)

If i am going at this from the complete wrong angle please tell me...
Thankyou in advance for any help on this issue
Regards Alex

See More: read an unknown directories name + copy to it

Report •

August 9, 2009 at 01:16:34
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/ad "%USERNAME%\Documents\test"') do (
copy blabla "%%a"

If at first you don't succeed, you're about average.


Report •

August 9, 2009 at 06:28:15
thankyou so much you solved my problem without needing a
vbscript, Perfect!!!!!!!! regards alex

Report •

August 9, 2009 at 07:19:28
Thankyou again for the answer but I would just like to ask one
more question I would like to copy the file attributes (read only)
with the files...I believe the command to do this /k however I'm
not sure were to place this command in the code, or if it is even
possible....Thanks in advance

Report •

Related Solutions

August 9, 2009 at 07:34:11
lol solved my own problem

@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/ad 
"%USERNAME%\Documents\test"') do (
xcopy /k /u blabla "%%a" /y

Report •

Ask Question