Extra check in UploadFiles

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Extra check in UploadFiles

Post by Burger » Mon Feb 20, 2023 4:39 pm

Hi Guys,

I've the following code when Imacros start uploading my files which are in a specific folder.

Can someone help me to extend the following code ?


I'm using the following Imacros edition:

Windows : Windows server 2019
iMacros version : 12.6 Browser Enterprise edition

Code: Select all

Sub UploadFiles()

	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")

	Dim attachmentsPath : attachmentsPath = Replace(Settings("Paths.AttachmentsFolder"), "{{LRN}}", PeachApp("LRN"), 1, -1, vbTextCompare)
	Dim attachmentsFolder
	Set attachmentsFolder = fso.GetFolder(attachmentsPath)

	Set fso = Nothing

	Dim file
	For Each file In attachmentsFolder.Files

		If PROD Then On Error Resume Next
		im.Play(Array("Upload File", "uploadsFolder", attachmentsPath, "fileName", file.Name))

		Script.SaveErrorState()
		On Error Goto 0
		Script.RestoreErrorState()

		If Err.Number = 0 Then
			Logger.LogInfo(Array("Uploaded ", file.Name))
		Else
			Err.Description = "Failed to upload " & file.Name & ", " & Err.Description
			HandleError()
		End If

	Next

End Sub
This code will upload all my files in the specific folder where the code is at the moment.
In that folder there are 2 types of files. .PDF files and .TXT files.

I want to extend the code that he will upload all .pdf files but only the .TXT files which matchs my file name.
So for example my file name = Test-123test.txt
He may only pick the .TXT file which has 123test.txt in his name.

Can someone help me on this?

Thanks in advance!
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Wed Feb 22, 2023 10:32 am

chivracq wrote:
Wed Jan 11, 2023 3:24 pm
Trying to quote chivracq. Don't know if I place this in the correct session for the right help I need? Could you put this threat to the right section if this is the wrong one ?

Thanks in advance!
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Extra check in UploadFiles

Post by Tom, Tech Support » Wed Feb 22, 2023 12:50 pm

Ah yes, the AutoPEACH project, I remember working on this!

Here's how you can change that For loop to achieve what you want:

Code: Select all

	For Each file In attachmentsFolder.Files

        Dim uploadFile : uploadFile = True

        If UCase(Right(file.Name, 4)) = ".TXT" Then
            uploadFile = StringHelper.Match(file.Name, "123test")
        End If

        If uploadFile Then
            If PROD Then On Error Resume Next
            im.Play(Array("Upload File", "uploadsFolder", attachmentsPath, "fileName", file.Name))

            Script.SaveErrorState()
            On Error Goto 0
            Script.RestoreErrorState()

            If Err.Number = 0 Then
                Logger.LogInfo(Array("Uploaded ", file.Name))
            Else
                Err.Description = "Failed to upload " & file.Name & ", " & Err.Description
                HandleError()
            End If
        End If

	Next

Of course, you probably don't want to hard-code the value "123test" in your script, so I'd suggest adding it as a setting to the config (.ini) file under the [Main] section like so:

Code: Select all

[Main]
TxtFileMatch=123test

Then change the reference in the code above to the following:

Code: Select all

            uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch"))
Regards,

Tom, iMacros Support
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Wed Feb 22, 2023 2:01 pm

Tom, Tech Support wrote:
Wed Feb 22, 2023 12:50 pm
Ah yes, the AutoPEACH project, I remember working on this!

Here's how you can change that For loop to achieve what you want:

Code: Select all

	For Each file In attachmentsFolder.Files

        Dim uploadFile : uploadFile = True

        If UCase(Right(file.Name, 4)) = ".TXT" Then
            uploadFile = StringHelper.Match(file.Name, "123test")
        End If

        If uploadFile Then
            If PROD Then On Error Resume Next
            im.Play(Array("Upload File", "uploadsFolder", attachmentsPath, "fileName", file.Name))

            Script.SaveErrorState()
            On Error Goto 0
            Script.RestoreErrorState()

            If Err.Number = 0 Then
                Logger.LogInfo(Array("Uploaded ", file.Name))
            Else
                Err.Description = "Failed to upload " & file.Name & ", " & Err.Description
                HandleError()
            End If
        End If

	Next

Of course, you probably don't want to hard-code the value "123test" in your script, so I'd suggest adding it as a setting to the config (.ini) file under the [Main] section like so:

Code: Select all

[Main]
TxtFileMatch=123test

Then change the reference in the code above to the following:

Code: Select all

            uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch"))
Hi Tom,

Yes Exactly! It's the AutoPeach :)

Thanks for your help! I think I need a little more help.

The .txt file needs to be found based on the file which iMacros is using at that moment for fill in the website forms.

So for example; The file which iMacros is reading for the webforms is named: 123456 - Test123.csv

In my Folder there are multiple .txt files :

100KG 100022 - Test123.txt
101KG 100022 - Test456.txt
102KG 100022 - Test789.txt

So in this case:

The code should only use the : 100KG 100022 - Test123.txt file for uploading.
There are also .pdf files in the same folder but these are not important right now because all the .pdf files needs to be uploaded. so the only extra check should be based on the .TXT files

Thanks again for your help!
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Extra check in UploadFiles

Post by Tom, Tech Support » Wed Feb 22, 2023 2:22 pm

Burger wrote:
Wed Feb 22, 2023 2:01 pm
The .txt file needs to be found based on the file which iMacros is using at that moment for fill in the website forms.

So for example; The file which iMacros is reading for the webforms is named: 123456 - Test123.csv

In my Folder there are multiple .txt files :

100KG 100022 - Test123.txt
101KG 100022 - Test456.txt
102KG 100022 - Test789.txt

So in this case:

The code should only use the : 100KG 100022 - Test123.txt file for uploading.
There are also .pdf files in the same folder but these are not important right now because all the .pdf files needs to be uploaded. so the only extra check should be based on the .TXT files

The code change I provided should do exactly that, unless I am somehow misinterpreting what you actually want. I only listed the code that needed to be changed, which is inside the For loop. I didn't list the the other code in the UploadFiles routine that remains the same - that code is still selecting the files to upload from the folder based on the LRN number. Here's the full listing if that helps:

Code: Select all

Sub UploadFiles()

	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")

	Dim attachmentsPath : attachmentsPath = Replace(Settings("Paths.AttachmentsFolder"), "{{LRN}}", PeachApp("LRN"), 1, -1, vbTextCompare)
	Dim attachmentsFolder
	Set attachmentsFolder = fso.GetFolder(attachmentsPath)

	Set fso = Nothing

	Dim file
	For Each file In attachmentsFolder.Files

        Dim uploadFile : uploadFile = True

        If UCase(Right(file.Name, 4)) = ".TXT" Then
            uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch"))
        End If

        If uploadFile Then
            If PROD Then On Error Resume Next
            im.Play(Array("Upload File", "uploadsFolder", attachmentsPath, "fileName", file.Name))

            Script.SaveErrorState()
            On Error Goto 0
            Script.RestoreErrorState()

            If Err.Number = 0 Then
                Logger.LogInfo(Array("Uploaded ", file.Name))
            Else
                Err.Description = "Failed to upload " & file.Name & ", " & Err.Description
                HandleError()
            End If
        End If

	Next

End Sub

Did you already try this change and does it not behave as expected? If not, what is the behavior you are observing?
Regards,

Tom, iMacros Support
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Wed Feb 22, 2023 2:51 pm

Tom, Tech Support wrote:
Wed Feb 22, 2023 2:22 pm
Burger wrote:
Wed Feb 22, 2023 2:01 pm
The .txt file needs to be found based on the file which iMacros is using at that moment for fill in the website forms.

So for example; The file which iMacros is reading for the webforms is named: 123456 - Test123.csv

In my Folder there are multiple .txt files :

100KG 100022 - Test123.txt
101KG 100022 - Test456.txt
102KG 100022 - Test789.txt

So in this case:

The code should only use the : 100KG 100022 - Test123.txt file for uploading.
There are also .pdf files in the same folder but these are not important right now because all the .pdf files needs to be uploaded. so the only extra check should be based on the .TXT files

The code change I provided should do exactly that, unless I am somehow misinterpreting what you actually want. I only listed the code that needed to be changed, which is inside the For loop. I didn't list the the other code in the UploadFiles routine that remains the same - that code is still selecting the files to upload from the folder based on the LRN number. Here's the full listing if that helps:

Code: Select all

Sub UploadFiles()

	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")

	Dim attachmentsPath : attachmentsPath = Replace(Settings("Paths.AttachmentsFolder"), "{{LRN}}", PeachApp("LRN"), 1, -1, vbTextCompare)
	Dim attachmentsFolder
	Set attachmentsFolder = fso.GetFolder(attachmentsPath)

	Set fso = Nothing

	Dim file
	For Each file In attachmentsFolder.Files

        Dim uploadFile : uploadFile = True

        If UCase(Right(file.Name, 4)) = ".TXT" Then
            uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch"))
        End If

        If uploadFile Then
            If PROD Then On Error Resume Next
            im.Play(Array("Upload File", "uploadsFolder", attachmentsPath, "fileName", file.Name))

            Script.SaveErrorState()
            On Error Goto 0
            Script.RestoreErrorState()

            If Err.Number = 0 Then
                Logger.LogInfo(Array("Uploaded ", file.Name))
            Else
                Err.Description = "Failed to upload " & file.Name & ", " & Err.Description
                HandleError()
            End If
        End If

	Next

End Sub

Did you already try this change and does it not behave as expected? If not, what is the behavior you are observing?
Thanks for your fast reply Tom!

The problem is, we do multiple insert on the same LRN number but with another prefix behind it.

So what we do is:

We have Multiple File names but with another text behind the " - " so for example:

Testname - Test123.csv
Testname - Test456.csv

In upload files the code will navigate to the folder which belongs to the LRN number and will search for the .TXT files.
But we do have multiple .TXT files in this folder For example:

C:/TEMP/LRN1234 has also two .TXT files
Testname - Test123.txt
Testname - Test456.txt

So what I've to do is I think something

Code: Select all

If UCase(Right(file.name, 4)) = ".TXT" Then
		uploadFile = StringHelper.Match(Split(file.Name, "-")(1), Split({{translimaFileName}}, "-")(1))
So the code will match the filename after the - and also the file name after the - for the translimaFileName

Is that correct ?
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Extra check in UploadFiles

Post by Tom, Tech Support » Wed Feb 22, 2023 5:05 pm

Burger wrote:
Wed Feb 22, 2023 2:51 pm
So what I've to do is I think something
Code: Select all

If UCase(Right(file.name, 4)) = ".TXT" Then
uploadFile = StringHelper.Match(Split(file.Name, "-")(1), Split({{translimaFileName}}, "-")(1))
So the code will match the filename after the - and also the file name after the - for the translimaFileName

Is that correct ?

The Match function does a regular expression match on the target text. Put simply, it will match all file names containing the target text anywhere within the file name. So given your last example,
C:/TEMP/LRN1234 has also two .TXT files
Testname - Test123.txt
Testname - Test456.txt

the way I coded it originally will upload "Testname - Test123.txt" and skip all other .txt files that don't contain 'test123' anywhere in the name, while also still uploading all the pdf files.

If you want to match specifically on the text being at the end of the file name just before the extension, then you can change the Match expression to the following:

Code: Select all

uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch") & "\.txt")
Regards,

Tom, iMacros Support
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Thu Feb 23, 2023 8:45 am

Tom, Tech Support wrote:
Wed Feb 22, 2023 5:05 pm
Burger wrote:
Wed Feb 22, 2023 2:51 pm
So what I've to do is I think something
Code: Select all

If UCase(Right(file.name, 4)) = ".TXT" Then
uploadFile = StringHelper.Match(Split(file.Name, "-")(1), Split({{translimaFileName}}, "-")(1))
So the code will match the filename after the - and also the file name after the - for the translimaFileName

Is that correct ?

The Match function does a regular expression match on the target text. Put simply, it will match all file names containing the target text anywhere within the file name. So given your last example,
C:/TEMP/LRN1234 has also two .TXT files
Testname - Test123.txt
Testname - Test456.txt

the way I coded it originally will upload "Testname - Test123.txt" and skip all other .txt files that don't contain 'test123' anywhere in the name, while also still uploading all the pdf files.

If you want to match specifically on the text being at the end of the file name just before the extension, then you can change the Match expression to the following:

Code: Select all

uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch") & "\.txt")
I think I understand you..

But the test123 text must be based on the name which iMacros is processing right now.

So if iMacros is processing my csv file named : Testfile - Test123.csv

Test123.txt should be the target text to find. So it must be variable.

For exmaple; Next csv file will be named like Peach230223 - target123.csv
Then should be my match on txt file 100KG - target123.txt (target123.txt should be the target .txt)

So I think I need to make the last part of the match variable right ? Just based on the file which is processing now ?
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Thu Feb 23, 2023 11:33 am

Burger wrote:
Thu Feb 23, 2023 8:45 am
Tom, Tech Support wrote:
Wed Feb 22, 2023 5:05 pm
Burger wrote:
Wed Feb 22, 2023 2:51 pm
So what I've to do is I think something
Code: Select all

If UCase(Right(file.name, 4)) = ".TXT" Then
uploadFile = StringHelper.Match(Split(file.Name, "-")(1), Split({{translimaFileName}}, "-")(1))
So the code will match the filename after the - and also the file name after the - for the translimaFileName

Is that correct ?

The Match function does a regular expression match on the target text. Put simply, it will match all file names containing the target text anywhere within the file name. So given your last example,
C:/TEMP/LRN1234 has also two .TXT files
Testname - Test123.txt
Testname - Test456.txt

the way I coded it originally will upload "Testname - Test123.txt" and skip all other .txt files that don't contain 'test123' anywhere in the name, while also still uploading all the pdf files.

If you want to match specifically on the text being at the end of the file name just before the extension, then you can change the Match expression to the following:

Code: Select all

uploadFile = StringHelper.Match(file.Name, Settings("TxtFileMatch") & "\.txt")
I think I understand you..

But the test123 text must be based on the name which iMacros is processing right now.

So if iMacros is processing my csv file named : Testfile - Test123.csv

Test123.txt should be the target text to find. So it must be variable.

For exmaple; Next csv file will be named like Peach230223 - target123.csv
Then should be my match on txt file 100KG - target123.txt (target123.txt should be the target .txt)

So I think I need to make the last part of the match variable right ? Just based on the file which is processing now ?
EDIT: I got it Tom!

I've added the following code:

Code: Select all

	startIndex = InStr(PeachApp.fileName, "- ")
	endIndex = InstrRev(PeachApp.fileName, ".")
	useName = Mid(PeachApp.fileName, startIndex + 1, endIndex - startIndex -1)
	
		If UCase(Right(file.Name, 4)) = ".TXT" Then
            'uploadFile = StringHelper.Match(file.Name,Split(TestApp.fileName,"- ")(1))
			uploadFile = StringHelper.Match(file.Name,useName)
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Extra check in UploadFiles

Post by Tom, Tech Support » Fri Feb 24, 2023 3:14 pm

Burger wrote:
Thu Feb 23, 2023 8:45 am
But the test123 text must be based on the name which iMacros is processing right now.

So if iMacros is processing my csv file named : Testfile - Test123.csv

Test123.txt should be the target text to find. So it must be variable.
Okay, I see, this was not clear to me previously, and after seeing your final solution, it totally makes sense now.

Burger wrote:
Thu Feb 23, 2023 11:33 am
EDIT: I got it Tom!

I've added the following code:

Code: Select all

	startIndex = InStr(PeachApp.fileName, "- ")
	endIndex = InstrRev(PeachApp.fileName, ".")
	useName = Mid(PeachApp.fileName, startIndex + 1, endIndex - startIndex -1)
	
		If UCase(Right(file.Name, 4)) = ".TXT" Then
            'uploadFile = StringHelper.Match(file.Name,Split(TestApp.fileName,"- ")(1))
			uploadFile = StringHelper.Match(file.Name,useName)
Excellent, happy to hear that you were able to cross the finish line on this one!
Regards,

Tom, iMacros Support
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Mon Mar 27, 2023 7:48 am

Tom, Tech Support wrote:
Fri Feb 24, 2023 3:14 pm
Burger wrote:
Thu Feb 23, 2023 8:45 am
But the test123 text must be based on the name which iMacros is processing right now.

So if iMacros is processing my csv file named : Testfile - Test123.csv

Test123.txt should be the target text to find. So it must be variable.
Okay, I see, this was not clear to me previously, and after seeing your final solution, it totally makes sense now.

Burger wrote:
Thu Feb 23, 2023 11:33 am
EDIT: I got it Tom!

I've added the following code:

Code: Select all

	startIndex = InStr(PeachApp.fileName, "- ")
	endIndex = InstrRev(PeachApp.fileName, ".")
	useName = Mid(PeachApp.fileName, startIndex + 1, endIndex - startIndex -1)
	
		If UCase(Right(file.Name, 4)) = ".TXT" Then
            'uploadFile = StringHelper.Match(file.Name,Split(TestApp.fileName,"- ")(1))
			uploadFile = StringHelper.Match(file.Name,useName)
Excellent, happy to hear that you were able to cross the finish line on this one!
Thanks for all your help!
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Mon Mar 27, 2023 12:52 pm

Tom, Tech Support wrote:
Fri Feb 24, 2023 3:14 pm
Burger wrote:
Thu Feb 23, 2023 8:45 am
But the test123 text must be based on the name which iMacros is processing right now.

So if iMacros is processing my csv file named : Testfile - Test123.csv

Test123.txt should be the target text to find. So it must be variable.
Okay, I see, this was not clear to me previously, and after seeing your final solution, it totally makes sense now.

Burger wrote:
Thu Feb 23, 2023 11:33 am
EDIT: I got it Tom!

I've added the following code:

Code: Select all

	startIndex = InStr(PeachApp.fileName, "- ")
	endIndex = InstrRev(PeachApp.fileName, ".")
	useName = Mid(PeachApp.fileName, startIndex + 1, endIndex - startIndex -1)
	
		If UCase(Right(file.Name, 4)) = ".TXT" Then
            'uploadFile = StringHelper.Match(file.Name,Split(TestApp.fileName,"- ")(1))
			uploadFile = StringHelper.Match(file.Name,useName)
Excellent, happy to hear that you were able to cross the finish line on this one!
Tom,

I've a questions regarding this, don't know if I need to make a new thread, if so please tell me and I will create a new one!

Just the question; Hopefully you remeber how to build our script!
Is there a possiblity to check the count of the PDF files in the specific folder of the LRN number which is being processed by iMacros ?
So what I want to trigger is that if there aren't more then 2 .pdf files in the attachement folder, the csv file need to stay in the polling folder. So everytime iMacros just run, he needs to check for every csv file is there are more then 2 pdf files in the attachement folder.

hopefully you can point me into the right direction where I need to build this function!
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Extra check in UploadFiles

Post by Tom, Tech Support » Fri Mar 31, 2023 9:56 am

Burger wrote:
Mon Mar 27, 2023 12:52 pm
Tom,

I've a questions regarding this, don't know if I need to make a new thread, if so please tell me and I will create a new one!

Just the question; Hopefully you remeber how to build our script!
Is there a possiblity to check the count of the PDF files in the specific folder of the LRN number which is being processed by iMacros ?
So what I want to trigger is that if there aren't more then 2 .pdf files in the attachement folder, the csv file need to stay in the polling folder. So everytime iMacros just run, he needs to check for every csv file is there are more then 2 pdf files in the attachement folder.

hopefully you can point me into the right direction where I need to build this function!
Hi Davy,

I don't recall all the specific ins-and-outs for this particular project--not without diving back into the code or running it a couple of times myself--but the logic for counting the number of PDFs is already similar to the code that exists in the UploadFiles routine. You need to loop over all the files in the folder, check the file extension for each file and if it's a PDF then increment a counter. So, something like the following function, which will return the number of PDFs in the current attachments folder:

Code: Select all

Function CountPDFs()

	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")

	Dim attachmentsPath : attachmentsPath = Replace(Settings("Paths.AttachmentsFolder"), "{{LRN}}", PeachApp("LRN"), 1, -1, vbTextCompare)
	Dim attachmentsFolder : Set attachmentsFolder = fso.GetFolder(attachmentsPath)

	Set fso = Nothing
 	CountPDFs = 0

	Dim file
	For Each file In attachmentsFolder.Files
        	If UCase(Right(file.Name, 4)) = ".PDF" Then
            		CountPDFs = CountPDFs + 1
        	End If
	Next

End Function
As far as when and where to call this function and what to do once you have the result, I can't immediately say without getting reacquainted with the full project code, but I'm sure you have a better idea than me at this point.
Regards,

Tom, iMacros Support
Burger
Posts: 16
Joined: Thu Jan 14, 2021 6:56 am

Re: Extra check in UploadFiles

Post by Burger » Fri Mar 31, 2023 10:39 am

Tom, Tech Support wrote:
Fri Mar 31, 2023 9:56 am
Burger wrote:
Mon Mar 27, 2023 12:52 pm
Tom,

I've a questions regarding this, don't know if I need to make a new thread, if so please tell me and I will create a new one!

Just the question; Hopefully you remeber how to build our script!
Is there a possiblity to check the count of the PDF files in the specific folder of the LRN number which is being processed by iMacros ?
So what I want to trigger is that if there aren't more then 2 .pdf files in the attachement folder, the csv file need to stay in the polling folder. So everytime iMacros just run, he needs to check for every csv file is there are more then 2 pdf files in the attachement folder.

hopefully you can point me into the right direction where I need to build this function!
Hi Davy,

I don't recall all the specific ins-and-outs for this particular project--not without diving back into the code or running it a couple of times myself--but the logic for counting the number of PDFs is already similar to the code that exists in the UploadFiles routine. You need to loop over all the files in the folder, check the file extension for each file and if it's a PDF then increment a counter. So, something like the following function, which will return the number of PDFs in the current attachments folder:

Code: Select all

Function CountPDFs()

	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")

	Dim attachmentsPath : attachmentsPath = Replace(Settings("Paths.AttachmentsFolder"), "{{LRN}}", PeachApp("LRN"), 1, -1, vbTextCompare)
	Dim attachmentsFolder : Set attachmentsFolder = fso.GetFolder(attachmentsPath)

	Set fso = Nothing
 	CountPDFs = 0

	Dim file
	For Each file In attachmentsFolder.Files
        	If UCase(Right(file.Name, 4)) = ".PDF" Then
            		CountPDFs = CountPDFs + 1
        	End If
	Next

End Function
As far as when and where to call this function and what to do once you have the result, I can't immediately say without getting reacquainted with the full project code, but I'm sure you have a better idea than me at this point.
Hi Tom,

Thanks for your reply. Yes I will have a look where I've to place and call this function! btw, is it possible to debug the code in Visual studio or something ? So I can intervene on a specific piece of code.
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Extra check in UploadFiles

Post by Tom, Tech Support » Fri Mar 31, 2023 6:01 pm

Burger wrote:
Fri Mar 31, 2023 10:39 am
btw, is it possible to debug the code in Visual studio or something ? So I can intervene on a specific piece of code.
Not typically with a regular VBScript file. You have to resort to adding MsgBox calls in the script in order to pause and/or display variable values. The core library included with your project also provides the Script.DebugOut routine, which you can use for logging messages and values to the script log file when it is run in debug mode. You can pass either a single message string to DebugOut, or an Array of items which it will convert to strings and concatenate together before writing to the file. The second approach is convenient for inspecting/outputting variable values, for example:

Code: Select all

Script.DebugOut(Array("The value of myVar = ", myVar))
To enable debug mode, add Debug=True to the [Main] section of the config file, or pass /debug on the command line. In fact, when using cscript to run the script from a command prompt, you will see all the log messages displayed in the console, in addition to them being written to the log file:

Code: Select all

cscript AutoPEACH.wsf /debug
Regards,

Tom, iMacros Support
Post Reply