Page 9 of 10

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 12:36 pm
by UltraVox
After installing hpwControl 1.43 and copy / paste your script in my sub-routine.
HpwControl error message : "Error : Listenindex überschreitet das Maximum (-1)"

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 1:13 pm
by mishem
It turns out that there was no single image file.
Corrected code that used the error appeared.
In variable [zmFindFilesCount] shows the number of files found.
Look in the debugger.
Now, if the files are not found, the cycle will not start.

Code: Select all
FolderBox "Select your images directory :" "[SelectedDir]"

If "[SelectedDir]" "=" ""
  AlertBox "[AppTitle]" "Please, choose a valid directory."
  Return
Else
SetVar "[InputMaskConvert]" "*.BMP;*.IMG;*.PBM;*.PAM;*.PFM;*.BSI;*.CIF;*.DAGSKY;*.DAGTEXTURE;*.DDS;*.GIF;*.JNG;*.JPG;*.JP2;*.MNG;*.PCX;*.PGM;*.PNG;*.PPM;*.PSD;*.TGA;*.TIF;*.XPM"
zmFindFiles "[InputMaskConvert]" "[SelectedDir]" "SubFolders" "" "[FilesinFolder]"

If "[zmFindFilesCount]" ">" "0"
 Loop "1" "[zmFindFilesCount]" "[I]"
 hpwLine "[FilesinFolder]" "[I]" "[FilePaths]"
   ListBoxFindItem "SourceImagesListBox" "[FilePaths]" "[Result]"
    If "[Result]" "=" "0"
       ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths]"
    EndIf
  EndLoop
EndIf
EndIf


Generally if the calculated search large numbers of files, you need to review the structure of the code. With this approach will be very long process.
If the list of 50 such lines, and files found in 1000, it is easier to search for and delete existing files found and add to the list of results.
I hope you understand what I'm saying.

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 1:24 pm
by UltraVox
The error disappeared, but nothing happens.
Yet there are 5000+ images in the directory.
Weird..

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 1:30 pm
by UltraVox
Ok i found the problem..

You forgot "Find" at the end :
zmFindFiles "[InputMaskConvert]" "[SelectedDir]" "SubFolders" "" "[FilesinFolder]" "Find"

The bad news, is that the problem is still there !
Windows sound is produced when the clicks in my application.
The files are in the list, but the problem is the same!

A simple NeoBook limit ?
Very weird...

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 1:53 pm
by mishem
A simple NeoBook limit ?

I do not know ...
I have this code load about 12,000 ways to images.
After I disabled. Was found 18650 images.
All this of course takes time.
And for such operations need to look for a more productive solution.

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 1:58 pm
by UltraVox
In this case, I create a new publication "test" and repeat the process. The problem is that small image directories pass without problem. As soon as the number of images is very important, it's panic!

It had to fall on me? ;)
Ok, Go Test.

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 2:07 pm
by UltraVox
Ok, it works very fine in a new app !
But not in mine... with the same script ...
I do other tests ...

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 2:37 pm
by UltraVox
I found the problem without being able to explain the following...

Mishem script does not work from a sub-routine. But it works perfectly from a button !

However, here are two script :
Sub-Routine Code
Code: Select all
:AddDir
FolderBox "Select your images directory :" "[SelectedDir]"

If "[SelectedDir]" "=" ""
  AlertBox "[AppTitle]" "Please, choose a valid directory."
  Return
Else
SetVar "[InputMaskConvertAddDir]" "*.BMP;*.IMG;*.PBM;*.PAM;*.PFM;*.BSI;*.CIF;*.DAGSKY;*.DAGTEXTURE;*.DDS;*.GIF;*.JNG;*.JPG;*.JP2;*.MNG;*.PCX;*.PGM;*.PNG;*.PPM;*.PSD;*.TGA;*.TIF;*.XPM"
zmFindFiles "[InputMaskConvertAddDir]" "[SelectedDir]" "SubFolders" "" "[FilesinFolder]" "Find"

If "[zmFindFilesCount]" ">" "0"
 Loop "1" "[zmFindFilesCount]" "[I]"
 hpwLine "[FilesinFolder]" "[I]" "[FilePaths]"
   ListBoxFindItem "SourceImagesListBox" "[FilePaths]" "[Result]"
    If "[Result]" "=" "0"
       ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths]"
    EndIf
  EndLoop
EndIf
EndIf
Return


The same script in the button :

Code: Select all
FolderBox "Select your images directory :" "[SourceImagesListBox]"

If "[SourceImagesListBox]" "=" ""
  AlertBox "[AppTitle]" "Please, choose a valid directory."
  Return
Else
SetVar "[InputMaskConvertAddDir]" "*.BMP;*.IMG;*.PBM;*.PAM;*.PFM;*.BSI;*.CIF;*.DAGSKY;*.DAGTEXTURE;*.DDS;*.GIF;*.JNG;*.JPG;*.JP2;*.MNG;*.PCX;*.PGM;*.PNG;*.PPM;*.PSD;*.TGA;*.TIF;*.XPM"
zmFindFiles "[InputMaskConvertAddDir]" "[SourceImagesListBox]" "SubFolders" "" "[FilesinFolder]" "Find"

If "[zmFindFilesCount]" ">" "0"
 Loop "1" "[zmFindFilesCount]" "[I]"
 hpwLine "[FilesinFolder]" "[I]" "[FilePaths]"
   ListBoxFindItem "SourceImagesListBox" "[FilePaths]" "[Result]"
    If "[Result]" "=" "0"
       ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths]"
    EndIf
  EndLoop
EndIf
EndIf


You see a difference ? Me, no.
However, the button works, but not the sub-routine !

Explanation ? I don't know !!!

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 3:08 pm
by dec
Hello,

I do not view some wrong... maybe the first "Return", which anyway is not needed, but, the code appear not wrong. Try to remove the first "Return" after the "If [SelectedDir]" but again I think probably this is not the problem...

Code: Select all
:AddDir
  FolderBox "Select your images directory :" "[SelectedDir]"

  If "[SelectedDir]" "=" ""
    AlertBox "[AppTitle]" "Please, choose a valid directory."
    Return
  Else
    SetVar "[InputMaskConvertAddDir]" "*.BMP;*.IMG;*.PBM;*.PAM;*.PFM;*.BSI;*.CIF;*.DAGSKY;*.DAGTEXTURE;*.DDS;*.GIF;*.JNG;*.JPG;*.JP2;*.MNG;*.PCX;*.PGM;*.PNG;*.PPM;*.PSD;*.TGA;*.TIF;*.XPM"
    zmFindFiles "[InputMaskConvertAddDir]" "[SelectedDir]" "SubFolders" "" "[FilesinFolder]" "Find"

    If "[zmFindFilesCount]" ">" "0"
      Loop "1" "[zmFindFilesCount]" "[I]"
        hpwLine "[FilesinFolder]" "[I]" "[FilePaths]"
        ListBoxFindItem "SourceImagesListBox" "[FilePaths]" "[Result]"
        If "[Result]" "=" "0"
          ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths]"
        EndIf
      EndLoop
    EndIf
  EndIf
Return

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 4:28 pm
by UltraVox
Thank you David

I tried but it does not change anything.
In addition, both ways work well in my new publication test... but not in my Main application.
Something is wrong... :(

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 4:44 pm
by dec
Hello,

Keep calm. Sometimes we cannot view the obvious. So don't worry too much, keep calm, relax and take the needed time to take a look at the code. At the least you have lucky: you know the code can work, so is just a question of time and patience you found the possible error and fix it. So keep calm. ;)

Re: Search and Replace text in a file

PostPosted: Mon Dec 09, 2013 8:54 pm
by mishem
Explanation ? I don't know !!!

To understand, we need the whole project.
Look for an error in the project.

maybe the first "Return", which anyway is not needed, but, the code appear not wrong.

"Return" I put to when the file is selected to stop processing code.
In this particular case the values ​​do not matter, but if the code lines 1000-10000, it is already noticeable.

Just when it's convenient looking through the debugger steps. Not have to click where the code does not work.
:)

Re: Search and Replace text in a file

PostPosted: Tue Dec 10, 2013 12:30 am
by UltraVox
Hello all,

I am perfectly calm David. But I lost a lot of time working on this script that works perfectly in a button, but not from a GoSub...

Very strange thing, even with the NB debugger, I can not click on my application. I can not even slow down the debugger, turn pause or stop the script. Windows sound is heard ... as usual. Only solution = Ctrl+Alt+Del.

Re: Search and Replace text in a file

PostPosted: Tue Dec 10, 2013 2:10 am
by UltraVox
I thought the problem was a potential "conflict" with other sub-routines.
I deleted all sub-routines, except the following :

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
:AddDir
FolderBox "Select your images directory :" "[SelectedDir]"

  If "[SelectedDir]" "=" ""
     AlertBox "[AppTitle]" "Please, choose a valid directory."
     Return
  Else
      SetVar "[InputMaskConvertAddDir]" "*.BMP;*.IMG;*.PBM;*.PAM;*.PFM;*.BSI;*.CIF;*.DAGSKY;*.DAGTEXTURE;*.DDS;*.GIF;*.JNG;*.JPG;*.JP2;*.MNG;*.PCX;*.PGM;*.PNG;*.PPM;*.PSD;*.TGA;*.TIF;*.XPM"
      zmFindFiles "[InputMaskConvertAddDir]" "[SelectedDir]" "SubFolders" "" "[FilesinFolder]" "Find"

    If "[zmFindFilesCount]" ">" "0"
      Loop "1" "[zmFindFilesCount]" "[I]"
        hpwLine "[FilesinFolder]" "[I]" "[FilePaths2]"
        ListBoxFindItem "SourceImagesListBox" "[FilePaths2]" "[Result]"
        If "[Result]" "=" "0"
          ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths2]"
        EndIf
      EndLoop
    EndIf
  EndIf
Return
 
Parsed in 0.008 seconds, using GeSHi 1.0.8.10


The problem is still there.
But now I know that there is no "conflict" with the sub-routines...

Re: Search and Replace text in a file

PostPosted: Tue Dec 10, 2013 4:44 am
by UltraVox
Hello all,

I identified the problem, but I find it extremely weird. I ask you to take the test, please.

Until now, I call my sub routine from a container that provides a choice (Radio button) between "Files" and "Directory".

Like this :

Code: Select all
. Close window
CloseCustomWindow "Conteneur11"

If "[Groupe_AddType]" "=" "Files"
   GoSub "AddFiles"
EndIf

If "[Groupe_AddType]" "=" "Directory"
   GoSub "AddDir"
EndIf

But as you know, it does not work...

But as soon as I change method (eg : button...), the sub-routine works perfectly !
I conclude that it is not possible to call a sub-routine with a radio button...

Can you please test it ?
Here is the suub-routine that must be tested with a radio button ...

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
:AddDir
FolderBox "Select your images directory :" "[List4]"

  If "[List4]" "=" ""
     AlertBox "[AppTitle]" "Please, choose a valid directory."
     Return
  Else
      SetVar "[InputMaskAddDir]" "*.BMP;*.IMG;*.PBM;*.PAM;*.PFM;*.BSI;*.CIF;*.DAGSKY;*.DAGTEXTURE;*.DDS;*.GIF;*.JNG;*.JPG;*.JP2;*.MNG;*.PCX;*.PGM;*.PNG;*.PPM;*.PSD;*.TGA;*.TIF;*.XPM"
      zmFindFiles "[InputMaskAddDir]" "[List4]" "SubFolders" "" "[FilesinFolder]" "Find"

    If "[zmFindFilesCount]" ">" "0"
      Loop "1" "[zmFindFilesCount]" "[I]"
        hpwLine "[FilesinFolder]" "[I]" "[FilePaths]"
        ListBoxFindItem "List4" "[FilePaths]" "[Result]"
        If "[Result]" "=" "0"
          ListBoxAddItem "List4" "0" "[FilePaths]"
        EndIf
      EndLoop
    EndIf
  EndIf
Return
 
Parsed in 0.007 seconds, using GeSHi 1.0.8.10


What's really weird is that the sub-routine work properly with directories containing some images. But as soon as there is a large number of images (5000 +) it works very badly. I can not explain it, I see it.

Thanks............