Page 1 of 1

Batch script to pass all files in directory and execute the vbs script

Posted: 09 Feb 2023 02:04
by bhas85
My requirement is: In a dir i have text files. I need to pass the files names to the vbs script.

From command prompt i am passing each file like below. Now my requirement is to pass all files in directory through the script. Sometimes i will get filenames with spaces as well 2023-02-03- 15474.txt.Need to remove spaces and process the .txt files. I tried with below script. but the below script didn't worked. getting error as "filelist" doesn't exist, Please kindly someone help me with the batch script.

Below is the manual way i will run the vbs script.
c:\Programs\FT\FTMain\cmd>send.vbs ft=SEND_FF appli=Root flow=NLP12 filename=p:\prog\2023-02-03-15474.txt


$FileList = Get-ChildItem -Path "path of the files"

If ($FileList.count -gt '0')

{

foreach ($SingleFile in $FileList) {

& send.vbs ft=SEND_FF appli=Root flow=NLP12 filename=$SingleFile

}
}

else {

Write-Output "File doesn't exist..."

}
}


catch {

Write-Output "Something wrong happened while getting files"
Write-Output "Error is $($Error[0].exception.message)"

}

Re: Batch script to pass all files in directory and execute the vbs script

Posted: 09 Feb 2023 10:39
by Hackoo
Where is the vbscript code ? I saw a Powershell script ?
Please try to format your code and explain more your aim

Re: Batch script to pass all files in directory and execute the vbs script

Posted: 09 Feb 2023 11:38
by bhas85
Hi Hackoo

My requirement is to pass files from P:\prog\*.txt as a parameter at filename which is high lighted with the script. Please let me know if i am not clear with my requirement.

Running the command manually from command prompt temporarily

C:\Programs\FT\FTMain\cmd>send.vbs ft=SEND_FF appli=Root flow=NLP12 filename=p:\prog\2023-02-03-15474.txt

Script

Code: Select all

@echo off
set filelocation = "P:\prog\"
set vbscript = "c:\programs\FT\FTMain\cmd\send.vbs"
for /f "tokens=*" %%f in ('dir /b %filelocation%') do (
 call %vbscript% ft=SEND_FF appli-Root flow=NLP12783 filename="%%f"
)

Re: Batch script to pass all files in directory and execute the vbs script

Posted: 09 Feb 2023 13:00
by Hackoo
And the source code of send.vbs where is it ?