简体   繁体   中英

How can I get the name directory in a variable- batch programming

I'm trying to use the name of a directory, but I can't get the name in a variable. Here's my current script:

MKDIR "D:\Documents\testbatch\temp"  
SET TEMPDossier="D:\Documents\testbatch\temp"  
:Check  
CD /D D:\Documents\testbatch  
FOR /D %%x in (*_C_* ) do (  
CALL :fct_log_Texte INFO  " dossier disponible %%x"  
setlocal enabledelayedexpansion   
SET VarDossier= %%x  
ECHO !VarDossier!  
SET rename=!VarDossier!  
echo %rename%  
:: Quote the variable and remove the !  
Set rename="%rename:!=%"  

I can't understand your code but if you want to get the directory name from full path of it, you can use call command with variable like this:

@echo off
set fullpath="D:\Documents\testbatch\temp temp"
call :show %fullpath%
pause
goto :eof
:show
echo %~n1

If you run above batch file, it will print temp temp on the screen.No quotes, no !. This is just example. I think you can modify for yourself. I hope it is useful for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM