Hi, hope you can help me with this... hopefully should be an easy one!
I'm trying to write a batch file but I'm having problem trying to use the VALUE of a Variable in a 'Trim' function.
I have variable "BackupDir" which needs right-trimming by x amount. Amount x is defined by a variable "Length".
To do it by a fixed amount (trim 2 from the left and x from the right) I'd do:
%BackupDir:~2,-x%
But... how do I trim it by the value of "Length" ? An example below... but in reality the value of Length will change.
Set Length=11
Set BackupDir=%BackupDir:~2,- [%Length%] %
- I want this to do: BackupDir=%BackupDir:~2,-11%
Any ideas?
Using a Variable to trim another variable?
Moderator: DosItHelp
Re: Using a Variable to trim another variable?
You could try this:
Call Set BackupDir=%%BackupDir:~2,-%Length%%%
Regards
aGerman
Call Set BackupDir=%%BackupDir:~2,-%Length%%%
Regards
aGerman
Re: Using a Variable to trim another variable?
Excellent, had to take off a % from each end and it worked fine!
Thanks for that!
Thanks for that!
Re: Using a Variable to trim another variable?
ian2000t wrote:[...]had to take off a % from each end[...]
Realy? That would never work for me, because the Call command expands %Length% to the value and removes one % from each end.
Regards
aGerman