# problem with a loop in a batch script



## calacausi (Apr 24, 2008)

hi all,
I should write a batch script to copy some files from one to another location. 
Searching on the net I found an example and rearrange it. It seems to work, but... only once! The script only works the first time it's used; then, it looks like it isnt able to reload the html code. 
How can I modify it to execute the copy operation more than one time?
Please help me. this is the script code

@echo off
title Copy files
echo select one file from the dropdown...
If not exist %0 goto ERROR
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.htm
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.vbs
start /w wscript.exe %TEMP%\UserIn.vbs
call %TEMP%\UserIn.bat
copy %USERNAME% %PASSWORD%
del %TEMP%\UserIn.vbs
del %TEMP%\UserIn.htm
del %TEMP%\UserIn.bat
goto DONE

:ERROR
cls
echo %0 put path-name and file name
goto DONE

:HTML
Copy files










*COPY FILES*


Select file to copy: Copy to directory: 

:VBS
Set fs = CreateObject("Scripting.FileSystemObject")
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.htm"))

Set web = CreateObject("InternetExplorer.Application")
web.Offline = True
web.AddressBar = False
web.Left=200
web.Top=100
web.Height = 350
web.Width = 500
web.Resizable=False
web.MenuBar = False
web.StatusBar = False
web.Silent = True
web.ToolBar = False
web.Navigate strFile
Do While web.Busy
Loop
On Error Resume Next
Set doc = Nothing
Do Until Not doc Is Nothing
Set doc = web.Document
Loop

srcfld="sourcefolder"

set folder = fs.GetFolder(srcfld)
k=0
For Each file in folder.Files
strFile = file.name
doc.Forms(0).elements("username").options.length=k+1
doc.Forms(0).elements("username").options(k).text=unescape(strFile)
doc.Forms(0).elements("username").options(k).value=unescape(strFile)
k=k+1
Next
web.Visible = True
Err.Clear

Do Until doc.Forms(0).elements("b_submit").Value <> "Copy"
Wscript.Sleep 100
If Err.Number <> 0 Then Exit Do
Loop
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
Set ts = fs.OpenTextFile(strFile, 2, True)
ts.WriteLine "SET USERNAME=" & Cartella & "\" & doc.Forms(0).elements("username").Value
ts.WriteLine "SET PASSWORD=" & doc.Forms(0).elements("password").Value
ts.Close
'web.Quit

ONE


----------

