As a beginner, I've searched these forums and couldn't find a solution. I'm trying to compare a last file date with the current file date to see if they match. However, even when the match, the code goes to ELSE. (this part: If>%strNewString%=%strNewString2%)
Here is what I created:
Let>FilePath={"C:\Users\myname\Desktop\"}
//Find latest file
GetNewestFile>C:\Users\myname\Desktop\NEW*,strFile
//Find latest file date
FileDate>%strFile%,dFileDate
//Find latest file time
FileTime>%strFile%,strFileTime
//Read date & time of last file
ReadFile>C:\Users\myname\Desktop\Counter.txt,lastfile
Let>DateTime=%dFileDate%,%strFileTime%
Let>tmp1=,
StringReplace>lastfile,tmp1,,strNewString
Let>tmp2=,
StringReplace>DateTime,tmp2,,strNewString2
Let>%newfile%=%strNewString2%
If>%strNewString%=%strNewString2%
Goto>TheSame
Else
And these are the results:
1: //Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
5: //Create File Path shortcut
7: Let>FilePath={"?C:\Users\myname\Desktop\"}
9: //Find latest file
10: GetNewestFile>C:\Users\myname\Desktop\NEW*,strFile
12: //Find latest file date
13: FileDate>C:\Users\myname\Desktop\NEW_2023_Feb.xlsx,dFileDate
15: //Find latest file time
16: FileTime>C:\Users\myname\Desktop\NEW_2023_Feb.xlsx,strFileTime
17: //Read date & time of last file
18: ReadFile>C:\Users\myname\Desktop\Counter.txt,lastfile
20: Let>DateTime=20230208,152926
22: Let>tmp1=,
23: StringReplace>lastfile,tmp1,,strNewString
25: Let>tmp2=,
26: StringReplace>DateTime,tmp2,,strNewString2
28: Let>%newfile%=20230208152926
30: If>20230208152926
=20230208152926
Any help would be appreciated!!
Thanks!
If/Else/Endif with compare (=)
Moderators: Dorian (MJT support), JRL
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: If/Else/Endif with compare (=)
Your values match, so without going through the code my first observation is that you're missing the Endif at the very end.
Yes, we have a Custom Scripting Service. Message me or go here
Re: If/Else/Endif with compare (=)
Hi Dorian...thanks for the reply! I do have the Endif at the end. Would I need any brackets or quotations? Do I need to Dim any values? Does combining the date & time confuse the comparison? Thanks!!
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: If/Else/Endif with compare (=)
Looking at it closer it looks like there are control characters in the %strNewString% variable. So it looks like it matches (to us as humans), but doesn't.
As opposed to :
So you can either just use ReadLn and only read line 1 :
Or you could continue to use ReadFile but then use Trim :
One other (unrelated) thing to note is that this :
..should be this :
These may help :
Using Variables and When to use Percent Symbols
User Defined Variables
Code: Select all
30: If>20230208152926
=20230208152926
Code: Select all
30: If>20230208152926=20230208152926
Code: Select all
ReadLn>C:\Users\myname\Desktop\Counter.txt,1,lastfile
Code: Select all
ReadFile>C:\Users\myname\Desktop\Counter.txt,lastfile
trim>lastfile,lastfile
Code: Select all
Let>%newfile%=%strNewString2%
Code: Select all
Let>newfile=%strNewString2%
Using Variables and When to use Percent Symbols
User Defined Variables
Yes, we have a Custom Scripting Service. Message me or go here
Re: If/Else/Endif with compare (=)
that's great Dorian! Thanks...I give those a try!!
Re: If/Else/Endif with compare (=)
This is what worked:
ReadFile>C:\Users\myname\Desktop\Counter.txt,lastfile
trim>lastfile,lastfile
Thanks for all your help!! It was making me frustrated!
ReadFile>C:\Users\myname\Desktop\Counter.txt,lastfile
trim>lastfile,lastfile
Thanks for all your help!! It was making me frustrated!
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: If/Else/Endif with compare (=)
You're very welcome.
Yes, we have a Custom Scripting Service. Message me or go here