Page 1 of 1

%~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 03:32
by nnnmmm

Code: Select all

run it like AA.BAT "M:\11 11\22 22\33 33\A B C D.TXT"

AA.BAT has
SET FFF0=%1
SET FFF1=%~f1
SET FFF2=%~d1
SET FFF3=%~p1
SET FFF4=%~n1
SET FFF5=%~x1
SET FFF6=the name of current directory you are at

echo 0=%FFF0%
ECHO.
echo 1=%FFF1%
echo 2=%FFF2%
echo 3=%FFF3%
echo 4=%FFF4%
echo 5=%FFF5%
echo 6=%FFF6%
pause
GOTO :EOF


Code: Select all

I would like
%FFF1% is what i want, so this is ok
%FFF2% to be M and not M:
%FFF3% \11 11\22 22\33 33 and not \11 11\22 22\33 33\
%FFF4%  is what i want, so this is ok
%FFF5% to be TXT and not .TXT
%FFF6% to be 33 33 and not \33 33 nor 33 33\


this will sync with my softwares.
could you help?

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 04:48
by trebor68
I've changed your code. Please try to understand these steps before you put them into another batch file.

Code: Select all

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET FFF0=%1
SET FFF1=%~f1

SET FFF2=%~d1
set FFF2=%FFF2:~0,1%

SET FFF3=%~p1
set FFF3=%FFF3:~0,-1%

SET FFF4=%~n1

SET FFF5=%~x1
set FFF5=%FFF5:~1%

SET FFF6=%~p1
:next1
for /f "tokens=1* delims=\" %%a in ("%FFF6%") do set help=%%b
if "%help%" neq "" (set FFF6=%help%) & goto :next1
set FFF6=%FFF6:~0,-1%

SET FFF7=%cd%

ECHO.
echo 0=%FFF0%
ECHO.
echo 1=%FFF1%
echo 2=%FFF2%
echo 3=%FFF3%
echo 4=%FFF4%
echo 5=%FFF5%
echo 6=%FFF6%
rem echo 7=%FFF7%
GOTO :EOF

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 05:24
by penpen
This might also help you:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

SET "FFF0=%1"
SET "FFF1=%~f1"
for /f "delims=:" %%a in ("%~d1") do set "FFF2=%%~a"
SET "FFF3=%~p1"
if not "%FFF3:~1%" == "" set "FFF3=%FFF3:~0,-1%"
SET FFF4=%~n1
for /f "delims=." %%a in ("%~x1") do set "FFF5=%%~a"
for %%a in ("%FFF3%") do set "FFF6=%%~nxa"


echo 0=%FFF0%
ECHO.
echo 1=%FFF1%
echo 2=%FFF2%
echo 3=%FFF3%
echo 4=%FFF4%
echo 5=%FFF5%
echo 6=%FFF6%
pause
GOTO :EOF


penpen

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 07:03
by nnnmmm
thanks it worked greatly

how do you define directory?
if dir then set ppp=1

I can define
IF "%FFF3%"=="\" IF "%FFF4%"==""
as a drive.

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 08:18
by nnnmmm

Code: Select all

for %%a in ("%FFF3%") do set "FFF6=%%~nxa"


I think i know what you did
%~nxI says that just a filename and its extension in FOR /?
you used the last dir name as a filename, i wouldnt guess this easily

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 11:51
by Squashman
nnnmmm wrote:could you help?

I would suggest you look over all the examples we have on the main DosTips website before asking any more questions.
http://www.dostips.com/

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 18:37
by nnnmmm
http://www.dostips.com/

it seems that the link is broken.

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 19:16
by ShadowThief
nnnmmm wrote:http://www.dostips.com/

it seems that the link is broken.

Image
It works fine?

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 03 Sep 2017 21:26
by nnnmmm
i didnt find what i was looking for in the guideline

how do i test if the input is a directory?

"M:\11 11\22 22\33 33" could also means a file name with no ext.

AA.BAT "M:\11 11\22 22\33 33"

Re: %~f1 %~f1 %~p1 %~n1 variable fixing and slightly redefining to sync with other soft.

Posted: 04 Sep 2017 10:12
by aGerman
I remember that the following was posted similarly here at DosTips even if I don't remember the topic.

Code: Select all

@echo off &setlocal

REM examples:
set "f=%cd%" &REM current directory
:: set "f=%~f0" &REM full name of this batch script
:: set "f=%cd%\nul" &REM no such path

for %%i in ("%f%") do if "%%~ai" geq "d" (
  echo it's a directory
) else if "%%~ai" geq "-" (
  echo it's a file
) else (
  echo no such path
)

for %%i in ("%f%") do if "%%~ai" lss "d" (
  echo no directory
)

for %%i in ("%f%") do if "%%~ai" lss "-" (
  echo no such path
)

pause

Steffen

EDIT Found the thread
viewtopic.php?t=6222