Page 1 of 1

Help needed with string manipulation - PAOLO - Italy

Posted: 17 Sep 2007 02:49
by dostipsradar
Parameter %1 is provided by doubleclicking on a file name in the directory C:\ESITOCHK an can be in the form:
"C:\ESITOCHK\xxxxxxxx.Nyy.PDF.P7M" or
"C:\ESITOCHK\xxxxxxxx.Xyy.P7M

I must create an output file (by program sbusta.bat) with the same name but without the P7M extension and:
if the first extension starts witx "N" i must create the corresponding xxxxxxxx.Nyy.PDF file
if the first extension starts witx "X" i must create the corresponding xxxxxxxx.Xyy file

This program works only if the parameter 1% is in the form "C:\ESITOCHK\xxxxxxxx.Nyy.PDF.P7M" and then
the variable "stringa" is "N";

The sbusta.bat wants two parameters: 1-input file path; 2-output file path

If "stringa" is "X", it seems that the sbusta.bat is not called since the output file is not in the output file path.
Can anyone explain to me why ? Please help me and thanks a lot in advance.
Paolo


@echo off
cls

set X=X
set N=N

set nomefile=%1
set fileinput=%nomefile%
set stringa=%nomefile%
set stringa=%stringa:~22,1%

set outpdf=%nomefile%
set outstd=%nomefile%

echo %fileinput%
set fileinput=%fileinput:~13,20%

set outpdf=%outpdf:~13,16%
set outstd=%outstd:~13,12%

echo fileinut %fileinput%
echo outpdf %outpdf%
echo outstd %outstd%
echo stringa %stringa%
pause

if %stringa% == X set outfile=%outstd%
if %stringa% == N set outfile=%outpdf%
echo outfile %outfile%
pause

call sbusta.bat %fileinput% c:\firmav~1\verifi~1\%outfile%

echo. End Program
pause

Posted: 19 Sep 2007 07:28
by DosItHelp
If filename is in %1 and you want to eliminate the extension use:
%~dpn1

Dos it help?

Posted: 19 Sep 2007 20:11
by DosItHelp
Paolo,

Try this one liner:

Code: Select all

call sbusta.bat "%1" "c:\firmav~1\verifi~1\%~n1"

This is how it works:
if "%1" is "C:\ESITOCHK\xxxxxxxx.Nyy.PDF.P7M"
then:
"%~n1" will be "xxxxxxxx.Nyy.PDF"
"%~x1" will be ".P7M"
"%~nx1" will be "xxxxxxxx.Nyy.PDF.P7M"
"%~p1" will be "\ESITOCHK\"
"%~d1" will be "C:"
"%~dp1" will be "C:\ESITOCHK\"
"%~dpn1" will be "C:\ESITOCHK\xxxxxxxx.Nyy.PDF"

d is drive
p is path
n is name
x is extension

To get the filename without extension use "%~n1".

DOS IT HELP? :wink: