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 dec » Thu Nov 14, 2013 10:14 am

Hello,

Sorry for that. I am not an specialist in graphics and, to be honest, this is the first day I get known about DDS files, then supose what can I do. :roll:
.
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 » Fri Nov 15, 2013 11:15 am

Hello David,

I refer to my previous posts and I need a little help. I want to get the same as previously, except that this time, I allow the user to display a list of image from a selected directory.

Code: Select all
. For image directory, if the group is selected
If "[Groupe_AddType]" "=" "Images file directory"

. Open a window for selecting directory
  FolderBox "Select your images directory :" "[SelectedDir]"

. Count the elements in the directory and save them in a variable
  FileList "[SelectedDir]\[InputMask]" "Files+Folders" "[FilesinFolder]"

. Get the paths and the number
  StrParse "[FilesinFolder]" ";" "[FilePaths]" "[FilesCount]"

. Calculate the number of items already in the list
  ListBoxSize "ZoneImagesOriginales" "[ListNbr]"

. Addition the items list + the number of selected files
  Math "[ListNbr]+[FilesCount]" "-1" "[TotalNbrList]"
  Loop "1" "[FilesCount]" "[I]"

. Extract the selected file names
  ExtractFileName "[FilePaths[I]]" "[FileName]"

. And add them to the list
  ListBoxAddItem "ZoneImagesOriginales" "0" "[FileName]"
  EndLoop
EndIf


In a list named "ZoneImagesOriginales", I get the list of files on ONE line, they are not separated as in your previous code. File names appear on the same line, attached to each other without separation.

Like this: image1.jpgimage2.jpgimage3.jpg

So my code does not work (as usual) :cry:
Do you know where is the problem, please ?
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dec » Fri Nov 15, 2013 11:30 am

Hello,

The "FileList" action return the file paths separated by carriage returns, not by semicolons, so just change this action:

Code: Select all
StrParse "[FilesinFolder]" ";" "[FilePaths]" "[FilesCount]"


By this other one:

Code: Select all
StrParse "[FilesinFolder]" "[#13]" "[FilePaths]" "[FilesCount]"
.
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 » Fri Nov 15, 2013 12:02 pm

argh... yes, indeed!
Thanks David.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby UltraVox » Sat Nov 16, 2013 3:33 am

Hello all,

I continue to ask questions here to avoid polluting the forum ^^

Here is my question :

Code: Select all
StrReplace "[XContents]" "bottom.dds" "[BottomFileName]" "[XContents]" ""
StrReplace "[XContents]" "right.dds" "[RightFileName]" "[XContents]" ""
StrReplace "[XContents]" "front.dds" "[FrontFileName]" "[XContents]" ""
StrReplace "[XContents]" "top.dds" "[TopFileName]" "[XContents]" ""
StrReplace "[XContents]" "left.dds" "[LeftFileName]" "[XContents]" ""
StrReplace "[XContents]" "back.dds" "[BackFileName]" "[XContents]" ""


Is it possible to transform these six lines into one ?

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

Re: Search and Replace text in a file

Postby dec » Sat Nov 16, 2013 3:54 am

Hello,

The first impression is not. And, on the other hand, maybe it's not a good idea to place all the lines in one. Right now you can read and understand very well the code, so...
.
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 Gaev » Sat Nov 16, 2013 5:19 am

UltraVox:

If the reason for your asking about "transforming the six lines into one" was because you have these same six lines in many many code sections, you might consider making these six lines into a SubRoutine ... then you just have to do a GoSub (one line) to invoke the six lines.

Otherwise, I agree with dec that code readability is far more important than reducing a few lines of code.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby UltraVox » Sat Nov 16, 2013 5:36 am

@Dec
Thanks for your help!

@Gaev
This is already a SubRoutine!
The objective was to minimize the number of lines of code.

For readability of code, of course, you are both right. :)

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

Re: Search and Replace text in a file

Postby UltraVox » Mon Nov 18, 2013 4:39 am

Hello all,

I'm just trying to delete a directory created by my application :

Code: Select all
  FolderExists "[PubDir]Data\Temp\ImgSb" "[ImgSbExist]"
  If "[ImgSbExist]" "=" "True"
     RemoveFolder "[PubDir]Data\Temp\ImgSb"
  Else
  EndIf


I tried to add "\" after ImgSb, but it changes nothing. He refuses to delete the directory as long as there old files in it.
I want to delete this directory AND its contents. Is there a simple method, please ?

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

Re: Search and Replace text in a file

Postby dec » Mon Nov 18, 2013 6:57 am

Hello,

A possible way is to use the npFileOperation action from my npUtil plugin in this way:

Code: Select all
npFileOperation "FO_DELETE" "C:\Path\To\Directory" "" "" "FOF_NOCONFIRMATION" "[Result]"
.
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 Gaev » Mon Nov 18, 2013 8:11 am

UltraVox:

Alternately, you could Run the (DOS) command called rmdir (remove directory) ... syntax is ...

RMDIR [/S] [/Q] [drive:]path

where ...

/S says "remove sub directories as well"
/Q says "quiet mode" (i.e. do not prompt "are you sure ?")


If you do not have any subdirectories, you can use ...

- use FileList to get the list of files in the folder
- do a Loop/EndLoop block to FileErase each file in the List
- then do the RemoveFolder

Note that you can create a generic SubRoutine (e.g. RemoveThisFolder) that works its magic from a variable reserved/passed by you e.g. RemoveFolderName.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby UltraVox » Mon Nov 18, 2013 8:58 am

I try this :
Code: Select all
Run "rmdir /S /C" "[PubDir]Data\Temp\ImgSb" "Normal" "" ""


A message informs me that the directory does not exist...
But there! I'm sure my command is incorrect.
I've never worked with DOS. Sorry...
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby Gaev » Mon Nov 18, 2013 10:06 am

UltraVox:

First, try this ...
Code: Select all
Run "dir" "[PubDir]Data\Temp\ImgSb /s" "Normal" "" ""
... once/if it works, you can try ...
Code: Select all
Run "rmdir" "[PubDir]Data\Temp\ImgSb /s /c" "Normal" "" ""
... note that the combination of /s and /c can be very devastating if you don't pick the right folder.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby UltraVox » Mon Nov 18, 2013 10:10 am

Gaev,

lol yes, I am aware of the risk :D
I'll try that!

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

Re: Search and Replace text in a file

Postby UltraVox » Mon Nov 18, 2013 10:20 am

Well, I do not know if "dir" works because the DOS window launches and closes instantly...
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