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 "9kny0x5w.example".
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 novice…
Set FS = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.OpenTextFile("%USERNAME%\test\", 1, False)
myarr = split(f1.ReadAll, vbnewline)
f1.close
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
Best Answer
Reading and parsing a directory listing is one way (although I would use "dir /ad /b" in this case to make it simpler to parse) although it is kinda hacky. You can enumerate a directory's subdirectories using the FileSystemObject too, which would be my preferred way.
http://www.microsoft.com/technet/scriptcenter/guide/sas_scr_jozd.mspx?mfr=true