Hi,
is it possibly to make a list of the remote files with a fmFileListToVar function but without file Extensions?
Thank you!
Dudus
fmFileListToVar without file Extensions
Re: fmFileListToVar without file Extensions
Dudus:
Dudus:
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 .
Dudus:
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. ...is it possibly to make a list of the remote files with a fmFileListToVar function but without file Extensions?
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 .
Re: fmFileListToVar without file Extensions
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
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
Re: fmFileListToVar without file Extensions
Dudus:
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 ...
This requirement is diffrerent from your enquiry in the first post ... do you want to ...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
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
Re: fmFileListToVar without file Extensions
Try this like a Function (Not_Ext)
Intenta esto como una funcion (Not_Ext)
Gracias por leerme
Thanks for reading me
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,'') );
Thanks for reading me
COSTA RICA
PURA VIDA
PURA VIDA
Re: fmFileListToVar without file Extensions
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
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
Re: fmFileListToVar without file Extensions
Dudus:
Post the result of ...
.. right after the EndIf command
P.S. In my earlier code, there was an extraneous StrReplace command (without parameters); hope you deleted it.
Post the result of ...
Code: Select all
AlertBox "Result" "[myFiles]" ... [myFilesNoExt]"
P.S. In my earlier code, there was an extraneous StrReplace command (without parameters); hope you deleted it.