Source language: Translate to:

fmFileListToVar without file Extensions

Questions about our File Management and Internet FTP plug-in

fmFileListToVar without file Extensions

Postby Dudus » Thu Oct 19, 2017 12:42 pm

Hi,

is it possibly to make a list of the remote files with a fmFileListToVar function but without file Extensions?

Thank you!
Dudus
User avatar
Dudus
 
Posts: 117
Joined: Wed Sep 07, 2005 12:15 pm
Location: Hungary, Budapest

Re: fmFileListToVar without file Extensions

Postby Gaev » Thu Oct 19, 2017 3:07 pm

Dudus:

Dudus:

is it possibly to make a list of the remote files with a fmFileListToVar function but without file Extensions?

This is a very generic question ... so the answer is that "while it is possible to remove file extensions via script, the results may not be desirable at times" e.g. ...

a) if you have files like abc.txt and abc.dat, you will end up with two entries with the value of "abc"

b) if there are files like abc.def.txt (where file name is "abc.def" and file extension is ".txt"), you may only get a value of "abc"

Also, this command acts on the current file selection (which may be set via script or by a user); fewer/no erroneous situations would arise if the selection was only set via script.

To answer your question, the process of removing file extensions from a (semi-colon) separated list is possible ... native NeoBook commands would be used to ...

a) StrParse the contents into an arrayed variable
b) Loop/EndLoop to iterate through each item in the array
c) StrParse (or StrReplace) each item to locate (and remove) the file extension

So, you need to be specific about what you want to achieve e.g. you want to get names of all files with extension of .txt, without the extensions .
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: fmFileListToVar without file Extensions

Postby Dudus » Fri Oct 20, 2017 12:59 am

Hi,

i have list.txt, which conatins file list like:
1.txt
2.txt
3.txt

and i need to delete the .txt extension.
The result should be:
1
2
3

Thats All!
Dududs
User avatar
Dudus
 
Posts: 117
Joined: Wed Sep 07, 2005 12:15 pm
Location: Hungary, Budapest

Re: fmFileListToVar without file Extensions

Postby Gaev » Fri Oct 20, 2017 5:51 am

Dudus:
i have list.txt, which conatins file list like:
1.txt
2.txt
3.txt

and i need to delete the .txt extension.
The result should be:
1
2
3

This requirement is diffrerent from your enquiry in the first post ... do you want to ...

1) change the contents of a file named list.txt ?

OR

2) remove the .txt extensions from a list (in a variable) populated by fmFileListToVar

If the answer is (1), all you need to do is ...

- read each line of list.txt
- StrReplace ".txt" with ""
- write the line back

If the answer is (2), take a look at this code (not verified by me) ... and modify as necessary ...
Code: Select all
... fetch matching file list
fmConnectRemote "myRemote" "host" "properties" ... fill in host and properties as appropriate
fmHideFileBrowser "myRemote"
fmChangeDir "myRemote" "/path1/path2/etc"  ... set as appropriate
fmSelectSome "myRemote" "!*.txt" "IncludeFiles=Yes;IncludeFolders=No;ScrollIntoView=No"
fmSetDelimiter "[#13]" ... default is semi-colon
fmFileListToVar "myRemote" "FullPath=Nos;IncludeFiles=Yes;IncludeFolders=No;SelectedOnly=Yes" "[myFiles]"

... now remove the extensions

If "[myFiles]" "<>" ""
   ... add trailing [#13]
   SetVar "[myFiles]" "[myFiles][#13]"
   ... replace .txt[#13] with [#13]
   StrReplace
   StrReplace "[myFiles]" "!.txt[#13]" "![#13]" "[myFilesNoExt]" ""
   ... remove trailing [#13] added earlier
   StrLen "[myFilesNoExt]" "[myFilesNoExtLen]"
   SubStr "[myFilesNoExt]" "1" "[myFilesNoExtLen]-1" "[myFilesNoExt]"
Else
   SetVar "[myFilesNoExt]" ""
EndIf

... [myFilesNoExt] can now be viewed in a ListBox or using AlertBox command
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: fmFileListToVar without file Extensions

Postby virger » Fri Oct 20, 2017 12:37 pm

Try this like a Function (Not_Ext)
Intenta esto como una funcion (Not_Ext)

Code: Select all
{NeoBook Function}
Version=5,80
Language=JScript
Param=[%str]|Variable|Text To Replace
Param=[%ret]|Variable|Return Result
{End}
var str = nbGetVar("[%str]");
var rg = /\.[0-9a-zA-Z]{0,4}/gi;
nbSetVar("[%ret]", str.replace(rg,'') );


Gracias por leerme
Thanks for reading me
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: fmFileListToVar without file Extensions

Postby Dudus » Fri Nov 10, 2017 3:53 am

Hi Gave,

thank you for the code:

If "[myFiles]" "<>" ""
... add trailing [#13]
SetVar "[myFiles]" "[myFiles][#13]"
... replace .txt[#13] with [#13]
StrReplace
StrReplace "[myFiles]" "!.txt[#13]" "![#13]" "[myFilesNoExt]" ""
... remove trailing [#13] added earlier
StrLen "[myFilesNoExt]" "[myFilesNoExtLen]"
SubStr "[myFilesNoExt]" "1" "[myFilesNoExtLen]-1" "[myFilesNoExt]"
Else
SetVar "[myFilesNoExt]" ""
EndIf

But how to modify it, because i have
1.txt
2.txt
3.txt

and the result after your code is 1|2|3 and not with <br>
1
2
3

Thank you!
Dudus
User avatar
Dudus
 
Posts: 117
Joined: Wed Sep 07, 2005 12:15 pm
Location: Hungary, Budapest

Re: fmFileListToVar without file Extensions

Postby Gaev » Fri Nov 10, 2017 6:08 am

Dudus:

Post the result of ...
Code: Select all
AlertBox "Result" "[myFiles]" ... [myFilesNoExt]"

.. right after the EndIf command

P.S. In my earlier code, there was an extraneous StrReplace command (without parameters); hope you deleted it.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to NeoBookFM/FTP

Who is online

Users browsing this forum: No registered users and 1 guest

cron