Discussion:
add asterisk to end of variable
(too old to reply)
Mezlo
2011-03-28 17:10:42 UTC
Permalink
OK, I've done Google searches and also searched this group but haven't
come up with a solution yet. I'm using 4NT 5.0 under Win 7 and am
trying to add an asterisk to the end of an environment variable.
Specifically I'm trying to do something like the following:

if not "%@RIGHT[1,%P]%"=="*" set %P=%P*

I've confirmed the IF test is working correctly, I just can't get the
variable modified. I've tried string functions like @INSERT, @SUBSTR,
and @LEFT but I'm obviously missing something.

Here is what I'm ultimately trying to accomplish. I will have a user-
created input text file similar to the following:

2GE10\0214
2GE11\0301
2GE11\0317

This is a list of possible folders. However, the actual folder names
will be something like "2GE11\0214-082.002". The user won't know the
last part of the folder name, just the start. Somehow I need to take
the input text file and end up with an output text file with the
actual folder names (there may be more than 1 folder matching each
input string). I was planning to use "DIR /B" which is why I need the
asterisk on the end. I will then take that ouput file and use it in a
FOR loop to copy the included folders to another drive.

I would appreciate any help you can provide. I can handle most of the
actual batch file. I'm just stuck on this one part.

Mez
E. S. Fabian
2011-03-28 19:15:41 UTC
Permalink
Mezlo:

|| OK, I've done Google searches and also searched this group but
|| haven't come up with a solution yet. I'm using 4NT 5.0 under Win 7
|| and am trying to add an asterisk to the end of an environment
|| variable. Specifically I'm trying to do something like the following:
||
|| if not "%@RIGHT[1,%P]%"=="*" set %P=%P*
||
|| I've confirmed the IF test is working correctly, I just can't get the
|| variable modified. I've tried string functions like @INSERT, @SUBSTR,
|| and @LEFT but I'm obviously missing something.
||
|| Here is what I'm ultimately trying to accomplish. I will have a user-
|| created input text file similar to the following:
||
|| 2GE10\0214
|| 2GE11\0301
|| 2GE11\0317
||
|| This is a list of possible folders. However, the actual folder names
|| will be something like "2GE11\0214-082.002". The user won't know the
|| last part of the folder name, just the start. Somehow I need to take
|| the input text file and end up with an output text file with the
|| actual folder names (there may be more than 1 folder matching each
|| input string). I was planning to use "DIR /B" which is why I need the
|| asterisk on the end. I will then take that ouput file and use it in a
|| FOR loop to copy the included folders to another drive.
||
|| I would appreciate any help you can provide. I can handle most of the
|| actual batch file. I'm just stuck on this one part.

If I understand correctly, you have a variable P, and you want to append an
asterisk * character to the end of its value. This will do it:

set p=%[p]*

Note that in your SET command you try to use the VALUE of P as the variable
to be SET (set %p=%p*). In all likelihood the simple command

set p=%p*

would also work.

Look at the %@EXPAND function - it might just do what you wanted to do with
DIR/B. Furthermore, you might just use the expansion capability of the FOR
command itself.

Note that 4DOS and its successors do not require trailing percent signs % to
evaluate variables, and should not have one following the right bracket ]
character terminating the parameters of a variable function.
--
HTH, Steve
Mezlo
2011-03-28 20:05:30 UTC
Permalink
Post by E. S. Fabian
|| OK, I've done Google searches and also searched this group but
|| haven't come up with a solution yet. I'm using 4NT 5.0 under Win 7
|| and am trying to add an asterisk to the end of an environment
||
||
|| I've confirmed the IF test is working correctly, I just can't get the
||
|| Here is what I'm ultimately trying to accomplish. I will have a user-
||
|| 2GE10\0214
|| 2GE11\0301
|| 2GE11\0317
||
|| This is a list of possible folders. However, the actual folder names
|| will be something like "2GE11\0214-082.002". The user won't know the
|| last part of the folder name, just the start. Somehow I need to take
|| the input text file and end up with an output text file with the
|| actual folder names (there may be more than 1 folder matching each
|| input string). I was planning to use "DIR /B" which is why I need the
|| asterisk on the end. I will then take that ouput file and use it in a
|| FOR loop to copy the included folders to another drive.
||
|| I would appreciate any help you can provide. I can handle most of the
|| actual batch file. I'm just stuck on this one part.
If I understand correctly, you have a variable P, and you want to append an
    set p=%[p]*
Note that in your SET command you try to use the VALUE of P as the variable
to be SET (set %p=%p*). In all likelihood the simple command
    set p=%p*
would also work.
DIR/B. Furthermore, you might just use the expansion capability of the FOR
command itself.
Note that 4DOS and its successors do not require trailing percent signs % to
evaluate variables, and should not have one following the right bracket ]
character terminating the parameters of a variable function.
--
HTH, Steve
Thanks for the reply. I tried your suggestion and it works from the
command line but not in a batch file. However, if I use a different
variable (set Q=%P*) it does work in the batch file. This is
acceptable so again thanks. I looked at EXPAND but could not get it to
do what I want.

Now I have a different issue. Redirection doesn't seem to work. From
the command line "dir /b aa > bb.txt" works, but from the batch file
it just creates an empty file bb.txt. I think this may be a
compatibilty issue between 4NT 5.0 and Win 7 because if I do a
"cmd.exe /C dir /b aa > bb.txt" in the batch file it works correctly.

Mez
E. S. Fabian
2011-03-28 23:22:12 UTC
Permalink
Mezlo:

| Thanks for the reply. I tried your suggestion and it works from the
| command line but not in a batch file. However, if I use a different
| variable (set Q=%P*) it does work in the batch file. This is
| acceptable so again thanks. I looked at EXPAND but could not get it to
| do what I want.

Was P the control variable of a FOR command? That would explain your
original problem, too - it cannot be modified with SET!


| Now I have a different issue. Redirection doesn't seem to work. From
| the command line "dir /b aa > bb.txt" works, but from the batch file
| it just creates an empty file bb.txt. I think this may be a
| compatibilty issue between 4NT 5.0 and Win 7 because if I do a
| "cmd.exe /C dir /b aa > bb.txt" in the batch file it works correctly.

I do not have Win7 installed anywhere, only WinXP, but I am aware that it
has much stricter rules about where a program may write. I suspect that the
issue is one of permissions. Try to run 4NT as an administrator and check if
it still has a problem.
--
HTH, Steve
Mezlo
2011-03-29 18:33:03 UTC
Permalink
Post by E. S. Fabian
| Thanks for the reply. I tried your suggestion and it works from the
| command line but not in a batch file. However, if I use a different
| variable (set Q=%P*) it does work in the batch file. This is
| acceptable so again thanks. I looked at EXPAND but could not get it to
| do what I want.
Was P the control variable of a FOR command? That would explain your
original problem, too - it cannot be modified with SET!
| Now I have a different issue. Redirection doesn't seem to work. From
| the command line "dir /b aa > bb.txt" works, but from the batch file
| it just creates an empty file bb.txt. I think this may be a
| compatibilty issue between 4NT 5.0 and Win 7 because if I do a
| "cmd.exe /C dir /b aa > bb.txt" in the batch file it works correctly.
I do not have Win7 installed anywhere, only WinXP, but I am aware that it
has much stricter rules about where a program may write. I suspect that the
issue is one of permissions. Try to run 4NT as an administrator and check if
it still has a problem.
--
HTH, Steve
Thanks again for your time and help. It's not a permission issue
because if I call cmd.exe it creates the file correctly. I think it's
just running an 8 year old program on a new OS.

Anyway, I have one final question. After the copy completes (I'm using
robocopy) I want to verify the source and destination folders are
identical. Right now I'm using "DIR /N /-P /S /K /U2" on each folder
which gives me results similar to below:

w:\1ge11>DIR /N /-P /S /K /U2 0328-083.800

Total for: W:\1GE11\0328-083.800\*
126,946,776 bytes in 18 files and 6 dirs 127,000,576 bytes
allocated
154,693,206,016 bytes free

Is there a way inside the batch file to parse that output and only
show part of it without piping it through FIND? When I pipe it through
FIND I have the same issue of the output not being written to the
file.
E. S. Fabian
2011-03-29 22:26:50 UTC
Permalink
---- Original Message ----
From: Mezlo
| Thanks again for your time and help. It's not a permission issue
| because if I call cmd.exe it creates the file correctly. I think it's
| just running an 8 year old program on a new OS.

I can think of another reason why results are not written to a file (also
applicable to the FFIND issue below). When you use a PIPE, a separate
instance of 4NT is started to execute the command on the right side of the
pipe; that instance executes your 4START.BTM. If 4START does not detect that
it is running in a pipe (using internal variable _PIPE, which has value 1 in
a PIPE, otherwise 0), AND it performs a CD or CDD to a directory other than
the one in which the batch file is running, any redirection without full
path will write to a file in that directory, not the one where you expect
it. I would set the directive NOCLOBBER=YES and make sure I use the
redirection without the "ignore noclobber state" flag (exclamation mark !);
that would report an error the second time you run the batch file.

| Anyway, I have one final question. After the copy completes (I'm using
| robocopy) I want to verify the source and destination folders are
| identical. Right now I'm using "DIR /N /-P /S /K /U2" on each folder
| which gives me results similar to below:
|
| w:\1ge11>DIR /N /-P /S /K /U2 0328-083.800
|
| Total for: W:\1GE11\0328-083.800\*
| 126,946,776 bytes in 18 files and 6 dirs 127,000,576 bytes
| allocated
| 154,693,206,016 bytes free
|
| Is there a way inside the batch file to parse that output and only
| show part of it without piping it through FIND? When I pipe it through
| FIND I have the same issue of the output not being written to the
| file.

What you need to do depends on the degree of matching desired. You can
make full content comparison, compare CRCs, compare directory entries (date
and size), filenames, or just file counts and total size of all files. If
you want to compare file contents, I would recommend upgrading to the
current version, which has the variable function @compare that returns 1 if
the contents of two are identical, 0 otherwise. OTOH your DIR command
implies you just want to compare number of files, subdirectories, and
diskspace used. In a more current version of the command processor @FILES
and @FILESIZE could be used for a whole directory tree.
To analyze the output of the DIR command, you can redirect it to the
clipboard (clip:). @clip[2] to contains the line giving the summary ot the
directory tree. You can parse the line using %@WORD. To make sure the commas
in the file size do not interfere with the parsing, you could use @STRIP.
--
HTH, Steve
Loading...