Puzzle for a rainy day

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Puzzle for a rainy day

Post by ChrisGreaves »

I continue to locate duplicate MP3 audio tracks on my data drive T:\ - an unencrypted Veracrypt partition on my laptop hard drive. Win10 automatically kept up to date.
The program is written in Word2003/VBA and reports these two files as duplicates by comparing their file contents, not their names. The MP3 tracks are 943Kb in size.

The two files are stored in the same folder “T:\Music\2018\201804\20180407\” and yet to this human eye the names appear to be identical.

Perhaps one of the hyphens is a hard-hyphen, or an optional hyphen or a soft hyphen. I write a comparisons procedure and it baulks at the hyphen, but the ASCII code reads “045” for each hyphen!

Code: Select all

Public Function ShowDelta(ByVal strFile1 As String, ByVal strFile2 As String)
    While (Len(strFile1) > 0) And (Len(strFile2) > 0)
        If Left(strFile1, 1) <> Left(strFile2, 1) Then
            MsgBox strFile1 & vbCrLf & strFile2
            Stop
        Else
        End If
        strFile1 = Right(strFile1, Len(strFile1) - 1)
        strFile2 = Right(strFile2, Len(strFile2) - 1)
    Wend
'Sub TESTShowDelta()
'    Call ShowDelta("Bach - 16 BWV 268 Auf auf mein Herz und du mein ganzer Sinn", "Bach - 16 BWV 268 Auf auf mein Herz und du mein ganzer Sinn")
'End Sub
End Function
I edited copies of the two files with Notepad.exe and pasted the text string “Saturday” into both files.
My “Duplicates” application continues to report these two 1KB files as duplicates, and both files sit in the same folder “T:\Music\2018\201804\20180407\”.

I have appended “.TXT” to the names so that I can attach them to this post.

Your mission: Download the two text files to a folder and confirm that you are able to store two files with visibly the same name into a single folder.
We might then discuss options to resolve this strange issue.
I have been trying different things for six days now. Most recently half an hour ago, using PKZip2.5.exe to package the two files with MP3 extents (not allowed here!), but PKZip made a zip file with only ONE of the MP3 files in it, so PKZIP2.5 thinks that the two names are identical. Or else whatever PKZip2.5 uses to obtain the contents of a folder reports only one file in the folder.

P.S.
Untitled.png
In Preview mode here the hyphens appear to be different in elevation, and in Word2003, Insert Symbol I find Unicode for hyphens at 002D and 0335, so perhaps these are yet more foreign characters that Word2003/VBA ASC function chops down to 045 codes.


Yours in prayer :please:
Chris
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzle for a rainy day

Post by HansV »

I can store both in a folder:

S0279.png
The "old" Dir function doesn't see any difference between the file names, but Scripting.FileSystemObject does: the 6th character of one filename is character 45, the other is character 8208:

Code: Select all

Sub Test()
    Const strFolder = "C:\Users\javog\Documents\Test\"
    Dim strFile1 As String
    Dim strFile2 As String
    Dim fso As Object
    Dim fld As Object
    Dim fil As Object
    Dim i As Long
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.getfolder(strFolder)
    i = 0
    For Each fil In fld.Files
        i = i + 1
        If i = 1 Then
            strFile1 = fil.Name
        Else
            strFile2 = fil.Name
        End If
    Next fil
    Debug.Print Len(strFile1), Len(strFile2)
    For i = 1 To Len(strFile1)
        If AscW(Mid(strFile1, i, 1)) <> AscW(Mid(strFile2, i, 1)) Then
            Debug.Print i, AscW(Mid(strFile1, i, 1)), AscW(Mid(strFile2, i, 1))
        End If
    Next i
End Sub
Result:

Code: Select all

 67            67 
 6             45            8208
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Puzzle for a rainy day

Post by ChrisGreaves »

HansV wrote:
10 Apr 2021, 14:30
I can store both in a folder:
Hans, thanks for this confirmation. There are times when I think i am seeing double ...
The "old" Dir function doesn't see any difference between the file names, but Scripting.FileSystemObject does: ...
Thanks too for this, although I don't use the DIR function much at all nowadays.
My basic code looks like this

Code: Select all

Public Function Filer_GetFolderItems(cond As Conditions, strAr() As String, typCriteria() As Criteria, Optional blnFoldersOnly As Boolean)
    Dim FI As Shell32.FolderItem, i As Long
    Dim DicFolder As New Scripting.Dictionary
    With New Shell
        Application.StatusBar = UBound(strAr) & " " & cond.strRootPath
        'evaluate the namespece
        With .NameSpace(cond.strRootPath)
            For Each FI In .Items
                If Not (FI Is Nothing) Then
                    If FI.IsFolder Then
                        If cond.blnSubFolders Then
                            If blnFoldersOnly Then
which, for the longest time, has served me well. I suspect that you are about to tell me that this is NOT the FSO, so I shall pre-empt you and make use of the code you have supplied for using FSO (will probably take me a day or two to switch over).
There is a chance that this will resolve a great many, but not all, of my problems.
Cheers
Chris
An expensive day out: Wallet and Grimace

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Puzzle for a rainy day

Post by HansV »

ChrisGreaves wrote:
10 Apr 2021, 14:56
There is a chance that this will resolve a great many, but not all, of my problems.
If only... :evilgrin:
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Puzzle for a rainy day

Post by ChrisGreaves »

HansV wrote:
10 Apr 2021, 15:01
If only... :evilgrin:
:cranky: :cranky: :cranky:
An expensive day out: Wallet and Grimace

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Puzzle for a rainy day

Post by ChrisGreaves »

HansV wrote:
10 Apr 2021, 14:30
... Scripting.FileSystemObject does: the 6th character of one filename is character 45, the other is character 8208:

Code: Select all

... If AscW(Mid(strFile1, i, 1)) <> AscW(Mid(strFile2, i, 1)) Then
Thanks again, Hans. I have rewritten my "Public Function CreateRandomFileListGUI(strAr() As String)" to use FSO, and now that is working.
This morning's task is to splice in the ASCW call and tell the user form to highlight mis-matched characters.
Untitled.png
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Puzzle for a rainy day

Post by Doc.AElstein »

Hi Chris
( see TLDR towads the end if you're in a rush )

Its not raining just now, in fact it’s a very nice Sunny Sunday, but as a bit of light relief to another rain problem** of mine... , this is how I would have figured out your problem. Or rather its how I might have figured it out had I thought to check the difference seen by Dir and Scripting.FileSystemObject , which I doubt I would have…
But now Hans has solved it, I can give you my take on how I might have got there, had I thought of that … _

_ ... A few years back I finally had had enough of mysterious problems caused by text not quite being what it looked like at first glance. So I wrote a function to check out and list out what text characters I have in a text string, ( or text file, which is the same thing ). ( As I recall I originally was given it here from Lisa Green , and then I’ve modified it quite a lot as time has gone on )



In the meantime running this function has solved an awful lot of my nagging problems.
( It has not solved all my problems. - I still can’t stop my wife doing some really stupid things, and, for the life of me, I can’t figure out how the rain persistently finds its way into a corner of one of my building sheds** – its possibly getting into some windy hollow and being redirected a long way away from where its actually leaking in. I will probably have to re roof the whole thing to stop one small leak. :( )

So here is a demo of what I am talking about..
I am not doing here anything more substantial than what Hans has done. Its all based on the simple Mid(str, x, 1) way of looking at characters in a string. I am just doing it in my characteristically annoyingly more long winded over complicated way.
( By the way, both your text files download for me normally and can be seen normally looking to the naked eye as the same )

Demo
To simplify this demo I put your two text files in a Temporary Folder, Temp , and that Folder is in the same Folder as my two given Excel Files containing my macro below and the Function, WtchaGot_...

Code: Select all

 Option Explicit
'    https://eileenslounge.com/viewtopic.php?f=30&t=36397
Sub Testit()
Rem  Scripting.FileSystemObject
Dim strFolder As String: Let strFolder = "" & ThisWorkbook.Path & "\Temp"
Dim Fso As Object, Fld As Object, PhilLGreek As Object
Set Fso = CreateObject("Scripting.FileSystemObject"): Set Fld = Fso.getfolder(strFolder)
Dim Ey As Long
    For Each PhilLGreek In Fld.Files
    Dim strFile1 As String, strFile2 As String
     Let Ey = Ey + 1
        If Ey = 1 Then
         Let strFile1 = PhilLGreek.Name
        ElseIf Ey = 2 Then
         Let strFile2 = PhilLGreek.Name
        Else
        End If
    Next PhilLGreek
Debug.Print "Scripting.FileSystemObject"
 Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(strFile1, "FSO strFile1") '  (the string to analyse, an optional name for the textfile output of contents)
 Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(strFile2, "FSO strFile2")
Debug.Print
Rem  Dir
Dim DirStrFile As String: Let DirStrFile = Dir(Pathname:="" & ThisWorkbook.Path & "\Temp\*.txt", Attributes:=vbNormal)
 Let strFile1 = DirStrFile
 Let strFile2 = Dir ' ' Unqualified argument use of Dir looks again with last search critertia
                                                                                                            If Dir <> "" Then MsgBox Prompt:="Something went wrong, or maybe you have more than two files in the Temp folder"
Debug.Print "Dir"
 Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(strFile1, "Dir strFile1") '  (the string to analyse, an optional name for the textfile output of contents)
 Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(strFile2, "Dir strFile2")
Debug.Print

End Sub
( The Function, WtchaGot_... is a bit big to post, but its in both uploaded Excel files )

Amongst other things, my function gives you an output in the Immediate Window , which after running that macro above, looks like this.

Code: Select all

 Scripting.FileSystemObject
"Bach " & "-" & " 16 BWV 268 Auf auf mein Herz und du mein ganzer Sinn" & "." & "mp3" & "." & "txt"
"Bach " & ChrW(8208) & " 16 BWV 268 Auf auf mein Herz und du mein ganzer Sinn" & "." & "mp3" & "." & "txt"

Dir
"Bach " & "-" & " 16 BWV 268 Auf auf mein Herz und du mein ganzer Sinn" & "." & "mp3" & "." & "txt"
"Bach " & "-" & " 16 BWV 268 Auf auf mein Herz und du mein ganzer Sinn" & "." & "mp3" & "." & "txt"
So once again, you can see where the problem is

The Before.xls is the file with the macros in it before you run the macro.
The After.xls is the file after running that macro Sub Testit(). The after file has an extra worksheet or two in it that once again show you where the problem is
You will also see 4 text files appear containing that basic function output in it.

_._________________________

TLDR:- Just to clarify what you should do, if you feel the urge….
_ Put your two text files in a folder with the name Temp ( You will need to make that Folder )
_ Put that Folder and my Before.xls anywhere, ( as long as the Before.xls and Temp are in the same place. )
_ Now run Sub Testit() ( which is in the file Before.xls )

_ If all has gone well, then the Before.xls will end up with 2 extra worksheets and will look identical to After.xls


Alan
You do not have the required permissions to view the files attached to this post.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Puzzle for a rainy day

Post by ChrisGreaves »

Doc.AElstein wrote:
11 Apr 2021, 11:01
_ ... A few years back I finally had had enough of mysterious problems caused by text not quite being what it looked like at first glance. So I wrote a function to check out and list out what text characters I have in a text string, ( or text file, which is the same thing ). ( As I recall I originally was given it here from Lisa Green , and then I’ve modified it quite a lot as time has gone on )
Hi Alan, and thanks for the response.
If you look in my original post at the head of the thread :threadhead: you will see my crude function "ShowDelta" which is a stripped-down piece of code that I have employed in my larger application. I began examining character codes, but not very well, in Word6.0 when I started my document cleansing conversion code for WP5.1DOS suite.
Sadly, I have not kept my utility code up to date with the migration from Word6 to Word97 VBA!
Anyway, all appears to be working right now.
The full "ShowDelta" of course, has to present a display within the GUI form display so that the user can take the appropriate action:-
Untitled.png
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: Puzzle for a rainy day

Post by LisaGreen »

Doc.AElstein wrote:
11 Apr 2021, 11:01
As I recall I originally was given it here from Lisa Green , and then I’ve modified it quite a lot as time has gone on
Hi Alan,

Just come to this. I would be very interested in the modifications.

Hope you're OK in these C19 Times!!

TIA
Lisa

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Puzzle for a rainy day

Post by Doc.AElstein »

LisaGreen wrote:
16 Apr 2021, 06:14
Hi Alan,..........Just come to this. ...Hope you're OK in these C19 Times!!
Hi Lisa
Hope you are OK as well. I am/ was mostly away from the computer for a while, ( but always check out everything here at Eileen’s Lounge.. eventually.. :) )
C19 has been terrible recently in our town, Hof, - Recently it was the worst effected in the whole of Germany for most days over a couple of weeks. Just now it’s calmed down a bit
But me and the wife have the worst of it long behind us: It hit us and Petra at work especially bad around Xmas and around the end of last year.
But now personally we have the worst behind us. All is well by us 2 now, at least as far as C19 is concerned…
_.___________________________________________________________
LisaGreen wrote:
16 Apr 2021, 06:14
..... I would be very interested in the modifications.
There aren’t any modification of any great academic significance…._
_.... I think a very long time ago you gave me a code or two which looks along a string using that basic code line, Mid(str, x, 1) , to get at each character, then it used the Asc( ) Chr( ) stuff to do a list telling you all about what characters ya got there.

That is the basic info I learned from you. I don’t have much more useful than that basic stuff in my version.
But in the meantime my Function WtchaGot_... has mutated into a grotesque form characteristic of my stuff – its too big to either fit in any post or for anyone else to be much interested to have or to use.
I do find it very useful and it has saved the day for me and a few others quite a few times. **

The main modifications I done are
_a)(i) it gives the output in a lot of different forms, - Immediate window, worksheets, text files ( The text files should appear in the same folder as the Excel file in which you have the function).
and
_b) as time goes on , I keep correcting my own mistakes in it, as I notice them….. I will take a guess that I have come close to finding most of the Bugs in it in the meantime.
( _a)(ii) - The form in the immediate window and in one of the text files is perhaps something “new” ## )

My most recent function version would be some where about here, I think:
https://excelfox.com/forum/showthread.p ... #post15522
https://pastebin.com/HatYwAAD
But I need to sort that mess all out sometime, my code storing is all in a bit of a chaotic mess just now…. I have not got around to documenting it all too well, yet…

I also included a fairly recent Function version in the enclosed file, LisaExSampleFile.xlsm
I included a test routine in that file as well, Sub Testit()
After running that test routine, you should get a couple of extra worksheets and three text files. ( The form that you see in the Immediate window and in one of the text files is that form which you would paste into a VBA macro to produce that string ##. I personally like to see that form, )


Alan.

** P.S. slightly off topic, but it could be very worth knowing to anyone using / administrating a forum… Some other forums I post in got trashed recently. I helped a very small bit in tracking down the problem, by feeding a lot of the messed up text in my function , which revealed a lot of characters up at around the ChrW 8200 , region which should not have been there. ( So similar to Chris’s problem….** )
( BTW., It happened at one place shortly after I posted something of Chris’s there. The site owner, a friend of mine, told me it that was a coincidence, but I blame Chris, Lol ** :) , I am sure Chris won’t mind, Lol :) )

Apparent some automatic Back up and Restore done routinely and automatically by the hosting Server was updated and during the change there was some mismatch in the default charter set conventions used by some temporary text files used in the process. ( I don’t understand anything more than that about it, so don’t ask! :) )
You do not have the required permissions to view the files attached to this post.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also