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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

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

#1 Post by nnnmmm » 03 Sep 2017 03:32

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?

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

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

#2 Post by trebor68 » 03 Sep 2017 04:48

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

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

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

#3 Post by penpen » 03 Sep 2017 05:24

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

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

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

#4 Post by nnnmmm » 03 Sep 2017 07:03

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.

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

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

#5 Post by nnnmmm » 03 Sep 2017 08:18

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

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

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

#6 Post by Squashman » 03 Sep 2017 11:51

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/


ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

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

#8 Post by ShadowThief » 03 Sep 2017 19:16

nnnmmm wrote:http://www.dostips.com/

it seems that the link is broken.

Image
It works fine?

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

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

#9 Post by nnnmmm » 03 Sep 2017 21:26

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"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#10 Post by aGerman » 04 Sep 2017 10:12

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

Post Reply