Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need to run script on all files in a folder, how do I get next fil

2 views
Skip to first unread message

margarita25

unread,
Jan 25, 2009, 5:44:04 PM1/25/09
to

Hello all,

I'm having a problem, I want to run the below script on all files in a
folder.
I have this script that works nicely to extract a specific line from a file,
but it needs to run on every file that comes into the incoming folder and all
files have a different names but begin with "Order_Product_CD... and differ
by unique account id and a part number. ie.
Order_Product_CD_Request_ACCOUNTID_PARTNUMBER.txt The script is called with
a .bat and the output appends to a cds.txt file.

Does any one know how I can get this script to run on each file in the
incoming folder?


Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile =
objFSO.OpenTextFile("\\Server\d$\cds\cd_request_load\incoming\Order_Product_CD_Request_ACCOUNTID_PARTNUMBER.txt", ForReading)

strTargetText = objFile.ReadAll
objFile.Close

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True

Set objFile =
objFSO.OpenTextFile("\\Server\d$\cds\cd_request_load\incoming\FindValue.txt",
ForReading)

Do Until objFile.AtEndOfStream
strName = objFile.ReadLine
objRegEx.Pattern = ".{0,}" & strName & ".{0,}\r"
Set colMatches = objRegEx.Execute(strTargetText)

If colMatches.Count > 0 Then
For Each strMatch in colMatches
strText = strText & strMatch.Value
Next
End If
Loop

Wscript.Echo strText

Thanks for any help!!

Very Best Regards,

Margarita Morales

ArarghMai...@not.at.arargh.com

unread,
Jan 25, 2009, 9:15:12 PM1/25/09
to
On Sun, 25 Jan 2009 14:44:04 -0800, margarita25
<marga...@discussions.microsoft.com> wrote:

>
>Hello all,
>
>I'm having a problem, I want to run the below script on all files in a
>folder.
>I have this script that works nicely to extract a specific line from a file,
>but it needs to run on every file that comes into the incoming folder and all
>files have a different names but begin with "Order_Product_CD... and differ
>by unique account id and a part number. ie.
>Order_Product_CD_Request_ACCOUNTID_PARTNUMBER.txt The script is called with
>a .bat and the output appends to a cds.txt file.
>

<snip>
Wrong newsgroup, but:

If the script can accept the file name from the command line, then in
the batch file:

For %%f in (*.*) do call <script> %%f

or something close to that. :-)
--
ArarghMail901 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.

margarita25

unread,
Jan 27, 2009, 2:52:01 AM1/27/09
to
Hi and thank you for your quick reply. Sorry for logging to the wrong
group. it seem to be the best fit for what I know of vb thus far.

In regards to your reply:
My .bat file indicates:
cscript //nologo collectFFID.vbs >> D:\MK\cd_request_load\incoming\cds.txt

to call the .vbs and the call appends records to the cds.txt file, however
the .vbs script is where the file name is indicated, so every time you want
to run the script, you have to change the file name in the script.

("\\Server\d$\cds\cd_request_load\incoming\Order_Product_CD_Request_ACCOUNTID_PARTNUMBER.txt", ForReading)

If I place, the line you suggested in my .bat file, what value would replace
the file name? I've tried to place \Ord*.txt in place of the file name,
but it errors with a message something like "unable to locate file...."

Thanks again for your help. Oh, what group should I had placed this
request in? Just so I know better next time. ;)

cheers!
Margarita

ArarghMai...@not.at.arargh.com

unread,
Jan 27, 2009, 3:25:14 PM1/27/09
to
On Mon, 26 Jan 2009 23:52:01 -0800, margarita25
<marga...@discussions.microsoft.com> wrote:

>Hi and thank you for your quick reply. Sorry for logging to the wrong
>group. it seem to be the best fit for what I know of vb thus far.
>
>In regards to your reply:
>My .bat file indicates:
>cscript //nologo collectFFID.vbs >> D:\MK\cd_request_load\incoming\cds.txt
>
>to call the .vbs and the call appends records to the cds.txt file, however
>the .vbs script is where the file name is indicated, so every time you want
>to run the script, you have to change the file name in the script.
>
>("\\Server\d$\cds\cd_request_load\incoming\Order_Product_CD_Request_ACCOUNTID_PARTNUMBER.txt", ForReading)
>
>If I place, the line you suggested in my .bat file, what value would replace
>the file name? I've tried to place \Ord*.txt in place of the file name,
>but it errors with a message something like "unable to locate file...."

Haven't a clue. Try the script reference for command line parameters.

>Thanks again for your help. Oh, what group should I had placed this
>request in? Just so I know better next time. ;)

One concerning batch files or vba. This one is for an old 16-bit
compiler.

margarita25

unread,
Feb 2, 2009, 1:32:03 PM2/2/09
to

Hi ArarghMail901, Thanks for your help anyway.

I ended up using SQL instead of using vb. I set up a DTS package and used
the BCP utility to move the files from the directory folder into the db and
then query for the specific records from the load table. this also allowed me
to send a Acknowledgement email to the CD requestor after loading the order
into the CRM system.

Thanks once more, I really appreciate your efforts in helping me. :)
--
cheers
Margarita

0 new messages