Source language: Translate to:

Search and Replace text in a file

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Re: Search and Replace text in a file

Postby UltraVox » Wed Dec 04, 2013 2:17 am

Ok, npUtil is very good plugin! :wink:
I'll buy it quickly.

Here is my code (no time to translate comments into English, sorry...) :

Code: Select all
If "[Groupe_AddType]" "=" "Directory"
. Ouvrir une fenêtre de sélection de répertoire
  FolderBox "Select your images directory :" "[SelectedDir]"
. Générer la liste des éléments du répertoire et sauver dans une variable
  FileList "[SelectedDir]\[InputMaskConvert]" "Files+Folders" "[FilesinFolder]"
. Séparer la chaine en nombre
  StrParse "[FilesinFolder]" "[#13]" "[FilePaths]" "[FilesCount]"
. Calculer le nombre d'items présents dans la liste
  ListBoxSize "ZoneImagesOriginales" "[ListNbr]"
. Aditionner les items de la liste + le nombre de fichiers sélectionnés
  Math "[ListNbr]+[FilesCount]" "-1" "[TotalNbrList]"
  Loop "1" "[FilesCount]" "[I]"
. Extraire les noms de fichiers sélectionnés
  ExtractFileName "[FilePaths[I]]" "[FileName]"
. Faire une recherche d'existence dans la liste, et si la selection n'existe pas déjà, l'ajouter dans la liste
  ListBoxFindItem "ZoneImagesOriginales" "[SelectedDir]\[FilePaths[I]]" "[Result]"
. S'il n'y a pas de double
     If "[Result]" "=" "0"
. Ajouter les items dans la liste
     ListBoxAddItem "ZoneImagesOriginales" "0" "[SelectedDir]\[FilePaths[I]]"
. Si non (s'il y a des doubles)
     Else
. Soustraire de la somme totale d'éléments le nombre de doublons
     Math "[ListNbr]+[FilesCount]-[FilesCount]" "-1" "[TotalNbrList]"
     EndIf
  EndLoop
. S'il existe des doubles, créer une boite d'avertissement
       If "[Result]" "<>" "0"
       AlertBox "[AppTitle]" "You have selected [FilesCount] file(s) already in the list.|[AppTitle] will not add these files."
       EndIf
Else
EndIf


Thanks for help...
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby mishem » Wed Dec 04, 2013 2:19 am

I do not quite understand the question ...
Maybe so?

Code: Select all
SetVar "[Temp]" "[SelectedDir]"
FolderBox "Select your image directory :" "[Temp]"
If "[Temp]" "=" ""
  Return
EndIf

SetVar "[SelectedDir]" "[Temp]"
ClearVariables "[Temp]"
.............
mishem
 
Posts: 574
Joined: Mon Oct 08, 2012 1:51 pm

Re: Search and Replace text in a file

Postby dec » Wed Dec 04, 2013 2:27 am

Hello,

Maybe it's not a real problem, but, apparently the latest "Else" is no needed in your code. On the other hand, probably you need to test the result of the "FolderBox" action using something like that:

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
If "[Groupe_AddType]" "=" "Directory"
  . Ouvrir une fenêtre de sélection de répertoire
  FolderBox "Select your images directory :" "[SelectedDir]"

  . Test if the user really choose a directory
  If "[SelectedDir]" "=" ""
    . Inform to the user or just "cancel" the task...
    AlertBox "Warning" "Please, choose a valid directory"

  Else
    . Générer la liste des éléments du répertoire et sauver dans une variable
    FileList "[SelectedDir]\[InputMaskConvert]" "Files+Folders" "[FilesinFolder]"
    . Séparer la chaine en nombre
    StrParse "[FilesinFolder]" "[#13]" "[FilePaths]" "[FilesCount]"
    . Calculer le nombre d'items présents dans la liste
    ListBoxSize "ZoneImagesOriginales" "[ListNbr]"
    . Aditionner les items de la liste + le nombre de fichiers sélectionnés
    Math "[ListNbr]+[FilesCount]" "-1" "[TotalNbrList]"
    Loop "1" "[FilesCount]" "[I]"
      . Extraire les noms de fichiers sélectionnés
      ExtractFileName "[FilePaths[I]]" "[FileName]"
      . Faire une recherche d'
existence dans la liste, et si la selection n'existe pas déjà, l'ajouter dans la liste
      ListBoxFindItem "ZoneImagesOriginales" "[SelectedDir]\[FilePaths[I]]" "[Result]"
      . S'il n'y a pas de double
      If "[Result]" "=" "0"
        . Ajouter les items dans la liste
        ListBoxAddItem "ZoneImagesOriginales" "0" "[SelectedDir]\[FilePaths[I]]"
      . Si non (s'il y a des doubles)
      Else
        . Soustraire de la somme totale d'
éléments le nombre de doublons
        Math "[ListNbr]+[FilesCount]-[FilesCount]" "-1" "[TotalNbrList]"
      EndIf
    EndLoop
    . S'il existe des doubles, créer une boite d'avertissement
    If "[Result]" "<>" "0"
      AlertBox "[AppTitle]" "You have selected [FilesCount] file(s) already in the list.|[AppTitle] will not add these files."
    EndIf
  EndIf
EndIf
 
Parsed in 0.009 seconds, using GeSHi 1.0.8.10
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby UltraVox » Wed Dec 04, 2013 2:37 am

Oh yes indeed, it works much better!!!

Thanks David and mishem!

Question for David :
What software do you use to present your video plugins ?

Thanks.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dec » Wed Dec 04, 2013 3:01 am

Hello,

Sometimes I use Screen-O-Matic and sometimes CamStudio.
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby UltraVox » Wed Dec 04, 2013 3:46 am

Thank you David.

David, in the code you gave me, the "FolderBox" window does not open.
The script avoids the absence of selection works, but the window does not open.

I do a copy / paste the code on the forum, and I do not understand why it does not open.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby UltraVox » Wed Dec 04, 2013 4:01 am

Ok that's good, I forgot a third EndIf in the previous script.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby UltraVox » Wed Dec 04, 2013 5:42 pm

Are you ready for a headache ? Let's go.
Any help would be appreciated.

Note that my application is not a simple image converter.
Basically it has no connection. The converter is just a feature.

Watch this small portion of my application :
http://imageshack.com/a/img59/606/j955.png

The list contains full paths to image files.
The selected images are stored in [ImageToConvert]

Below there are the available conversion formats.
Stored in [Ext]

On the right, a big button "Convert Now" in which this is :

Code: Select all
StrParse "[ImageToConvert]" "[#13]" "[TableImageToConvert]" "[NumberImageToConvert]"
Loop "[TableImageToConvert]" "[NumberImageToConvert]" "[I]"
npImgConvert "[TableImageToConvert[I]]" "[ConvertionDirectory]\[FileNameToConvert][Ext]" "[ConvertResult]"
EndLoop


Based on this button "Convert Now", I need to find how to integrate in this Loop, all selected files in the List (only selected files).
You understand that [FileNameToConvert] is supposed to contain the names of files. But how ...?

The objective is to convert the selected items in the list. The problem does not arise when it comes to converting a single element...

If you have a solution, I'm interested.
npImgs is an excellent plugin make by David Esperalta : http://neoplugins.com/?plugin/npimgs

Thanks for help ! :mrgreen:
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dec » Thu Dec 05, 2013 2:31 am

Hello,

Maybe I can't understand very well, but, basically you need to iterate over the selected items in the ListBox? If so, you can do using the ListBox associated variable since this store the selected items separated by carriage returns. So you can iterate over this items and since everyone represent a source image file path, you can use as the first argument for npImgConvert action.

In principle your code appear good if "[TableImageToConvert]" is the variable associated with the ListBox. On the other hand I am not very sure about the other variables used in your code. But the code part that iterate the ListBox appear good...
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby UltraVox » Thu Dec 05, 2013 3:06 am

I do not know how, is to transform [FileNameToConvert] in file names, those selected from the list.

The variable for the selected items in the list is [ImageToConvert].

Currently, I just get one file named ".BMP". No name for the file, just extension... and a error message from npImgs : Missing source image file ""
So my problem is that I do not know what variable to use to find the Files Names of output.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby UltraVox » Thu Dec 05, 2013 4:14 am

The problem is that the converter.pub supplied with npImgs plugin converts only 1 image..., using windows file selection. One for the selection (In), and then for conversion (Out). In this case, obviously the list of formats at the bottom of the two windows.

I want to do otherwise.
A list of files with multiple selection. My problem is that I do not know how to give two important things to npImgs plugin :

1/ The names of the original files (without extension, to avoid image.jpg.BMP to output)

2/ How to give the extension (convert format) selected by the user, for npImgs ?
(see my picture to understand : http://imageshack.com/a/img59/606/j955.png)

The command NpImgConvert contains "Image target".
The problem is that I have nothing to indicate the conversion format chosen by the user.

So, in "Image target" I insert the destination directory...
But I do not understand how npImgs will produce something, if not filenames or extension (conversion format) selected by the user ?
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dec » Thu Dec 05, 2013 4:50 am

Hello,

Various things here. The npImgConvert action requires three arguments:

1º The source image, which must be an image file path, for example: C:\MyImage.bmp

2º The target image, which must be an image file path also,for example C:\MyImage.jpg

3º The result variable, which store the result of the action, "True" if no errors.

Since the action based their work in the file extensions, they know you want to convert a BMP file to a JPG file.

Then you cannot provide a directory as a valid second argument. You need to provide a complete image file path (which can exists or not), of course including the file extension. So one thing is what you shows to the user: files without extensions, only the names, etc. (To do this you can use NeoBook actions like "ExtractFileExt" and/or "ExtractFileName") and other thing is the argument you need to provide to npImgConvert.

Maybe later I have some time in order to prepare a "multiple files conversion" sample. ;)
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby UltraVox » Thu Dec 05, 2013 5:18 am

David,

Yes ! It would be very kind of you. I'm really sorry !
Please, made ​​an example of a multiple-selection list...

Something that looks a lot like the picture I showed you :
http://imageshack.com/a/img59/606/j955.png

Thank you very much...
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dec » Thu Dec 05, 2013 6:47 am

Hello,

Ok. Maybe it's not exactly what you wanted, but, in the bellow sample you can found a publication that:

1º Shows a list of images files from a source directory

2º Convert one or more of these files to GIF into the target directory

http://www.neoplugins.com/?download/npimgconvert.zip

Hope this can help you in some manner.
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby UltraVox » Thu Dec 05, 2013 7:20 am

David,

Yes it helps me a lot, because I better understand the process.
You should incorporate this example in your plugin :)

Convert one file is easy, but convert several at once is less easy...

Merci !
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

PreviousNext

Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest