space in the end of a name of a folder - c#-3.0

how can i remove the space in the end of a name of a folder

String.Trim()
See: .NET Reference - String.Trim Method ()

Related

Why `run, explore` doesn't work with expression syntax?

Why run, explore doesn't work with expression syntax?
Any ideas? Big thanks in advance.
dir := "C:\Users\"
; Works
run explore %dir%
; Doesn't work. Why?
run explore % dir
This demonstrates run using expression syntax:
run % "explorer " dir
Because the percent-space prefix for forcing an expression must be used at the beginning of any parameter and nowhere else.
To the Run command, explore %dir% or explore % dir is just a single parameter, where you can't put the prefix in the middle of it.
In DOS batch file this is the way to access variables - %VARIABLE_NAME%
So %dir% is a valid variable that has values defined in your script, while % and dir with a space in between does not reference to dir you have defined.
[https://support.microsoft.com/en-ca/help/121170/how-to-access-environment-variables-in-an-ms-dos-batch-file]

How to delete a file whose name is given by a character array?

I want to delete a file with variables in the file name. But MATLAB doesn't seem to recognize the file name when using delete. Can anyone help me?
ratio=1;
a=2;
nameoffile3=['r' num2str(ratio) '_a' num2str(a) '.txt'];
delete nameoffile3
To delete a file whose name is given by a character array, use delete with parenthesis () i.e.
delete(nameoffile3)

check file existance in progress 4GL

How to check existance of particular file by use of code.
Eg.
def var a as character.
a = "abc.p"
run value(a).
---> here first i want to check if abc.p exist in workspace or not.
You can use the SEARCH function. Directly from the online manual:
SEARCH function
Searches the directories and libraries defined in the PROPATH environment variable for a file. The SEARCH function returns the full pathname of the file unless it is found in your current working directory. If SEARCH does not find the file, it returns the Unknown value (?).
Syntax
SEARCH ( opsys-file )
opsys-file
A character expression whose value is the name of the file you want to find. The name can include a complete or partial directory path. If opsys-file is a constant string, you must enclose it in quotation marks (" "). The value of opsys-file must be no more than 255 characters long.
Example:
DEFINE VARIABLE cPgm AS CHARACTER NO-UNDO.
cPgm = "test.p".
IF SEARCH(cPgm) <> ? THEN
RUN VALUE(cPgm).
If you provide a fully qualified pathname, SEARCH checks if the file exists. In this case, SEARCH does not search directories on the PROPATH.
If you do not want to use the propath you can use the FILE-INFO system handle.
After setting FILE-NAME, you can check the FILE-TYPE if it exists. See also the Progress Help for FILE-INFO.
FILE-INFO:FILE-NAME = a.
IF FILE-INFO:FILE-TYPE MATCHES "*F*"
THEN RUN VALUE(FILE-INFO:FULL-PATHNAME).

uigetfile not pulling entire file name

I'm using uigetfile to upload my data. I've time stamped my data with a date. So a file I want to upload looks like Data-Dec01_11/45/35.txt The problem is uigetfile reads till the first "/" and then assumes that that is the end of the file name. Thus it pulls the file name Data-Dec01_11. But of course when I load that file it doesn't exist. How do I force uigetfile to pull the entire file name?
You cannot use slashes or backslashes in your file names, as they can be mistaken with the file separator, as in your case.
You can use ´regexpr´ to rename your files so they do not contain illegal characters, as explained in this trhead.
I copy here the code they suggest for your convenience (I've just added a slash and a backslash to the example string so you can see the results):
% these characters are allowed
legalchars = 'a-zA-Z0-9\-\ \_\.' ;
% illegal filename
A = 'Some#charac\ters$are(not&allowed/.txt'
% replace every other character with an underscore
B = regexprep(A,['[^' legalchars ']'],'_')

how to check if given file lies anywhere under given directory by command line in windows xp?

So for example i need to check if file C:\windows\system32\whatever.dll lies in c:\windows. Is it possible in a manner like if not exists ..., but here if %file% lies in %directory% ?
edit: I know the path to the file I'm looking for. The problem boils down to comparing strings, that is checking if path to the directory is contained at the beginning in a path to the file.
you can do something like
if not exists %directory%\%file%
in this way you create a full file-pathname like "c:\myfolder\yourfolder\myfile.txt" and check for it's existence
Update
this should works (but it's not tested)
:: starting folder
set RootPath=c:\myfolder\yourfolder\
::check all subfolder
for /R "%RootPath%" %%d IN (.) DO (
echo %%d
:: check all file in each subfolder
for %%f IN ("%%~d\*.*") DO (
:: check if your file exist
IF "%%~nxf"=="filenameImLookingFor.txt" (
echo Found file here "%%~f"
)
)
)
%%~nxf will expand to filname with extension, without the path
the "~" make also sure that the expanded variable will never contain
prefix/postfix doublequte, so that you can add your own without
having unexpected double-doublequote (that will obviously mess things
up)
Here is a list of useful syntax for FOR variables (from the help of the FOR command)
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line