braindedd Posted December 22, 2006 Share Posted December 22, 2006 Hi guys,Trying to get a batch file to set the current directory name only to a variable ... best I've come up with is this:@ECHO OFFset Test2=%CD%cd ..set Test1=%CD%set Test1=%Test1%\cd %Test2% ECHO @echo off >"%Temp%\Test2.bat"ECHO Set Test=%%CD:%Test1%=%% >>"%Temp%\Test2.bat"rem ECHO echo %%test%% >>"%Temp%\Test2.bat"call "%Temp%\Test2.bat"del "%Temp%\Test2.bat"echo %Test%Must be an easier way to do it ... anyone? Link to comment Share on other sites More sharing options...
jftuga Posted December 22, 2006 Share Posted December 22, 2006 (edited) echo %CD% | mawk -F\\ "{print $NF}" > cwd.tmpset /p CWD=<cwd.tmpdel cwd.tmpecho %CWD%http://www.klabaster.com/freeware.htm#mawk(if you don't mind using an external program)Also, run:call /?This might help you, if you can figure out a way to use the special %~ variables.-John Edited December 22, 2006 by jftuga Link to comment Share on other sites More sharing options...
Yzöwl Posted December 22, 2006 Share Posted December 22, 2006 Will this help@IF %~D0\ EQU %~DP0 @ECHO/%~NX0 is at root level &GOTO :EOF@FOR /F "DELIMS=" %%? IN ("%CD%") DO @ECHO/The `Parent Folder` is %%~N? Link to comment Share on other sites More sharing options...
braindedd Posted December 26, 2006 Author Share Posted December 26, 2006 Thanks guys.Yzöwl, your script looks good, just have to find a way that it works if run from a different directory? Link to comment Share on other sites More sharing options...
Yzöwl Posted December 26, 2006 Share Posted December 26, 2006 My command which performs the task you require would still be the same, just the first line, (error trapping), would change.@IF %CD:*:=% EQU \ @ECHO/The current directory is at root level &GOTO :EOF@FOR /F "DELIMS=" %%? IN ("%CD%") DO @ECHO/The `Parent Folder` is %%~N? Link to comment Share on other sites More sharing options...
gunsmokingman Posted December 27, 2006 Share Posted December 27, 2006 (edited) This VBS script does the same but uses VBS to pass the Folder and Path varibles back to Cmd PromtSave As LastFolder.vbsDim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim Act : Set Act = CreateObject("Wscript.Shell") Dim File,Folder,StrF StrF = Fso.GetFolder(Fso.GetParentFolderName(WScript.ScriptFullName)) Set Folder = Fso.GetFolder(StrF) Act.Run("%Comspec% /c @Echo Off && CLS && Color F9 && Mode 75,5 && Title Folder Path && Echo. && " &_ "Echo -^> The Last Folder : "&Folder.Name&" && Echo -^> The Folder Path : " &StrF& " && Pause"),1,TrueThis Script will pass all the Varibles from an Array to the Cmd Promt Screen.This will show the Last Folder Name , Start Folder Path, Start Folder Date Created, Start Folder Last Aceess Date, Start Folder Size, this will then be dispalyed in CmdPromt, each with it own text color and Cmd Bar Title. Save As LastFolderV1.vbsDim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Folder : Set Folder = Fso.GetFolder(Fso.GetParentFolderName(WScript.ScriptFullName))'/-> Array To Build The Cmd Promt Output Dim VAR : VAR = Array(_ " && ","CLS && Echo.","ping -n 3 127.0.0.1>nul","ping -n 4 127.0.0.1>nul",_ Int(1024 * 1024),Int(1024 * 1024 * 1024),Folder.Size,_ "CLS && Color F9 && Mode 45,3 && Title Last Folder && Echo. ",_ "CLS && Color F4 && Mode 85,3 && Title Folder Path && Echo. ",_ "CLS && Color F2 && Mode 50,3 && Title Date Created && Echo. ",_ "CLS && Color F5 && Mode 55,3 && Title Date Last Modified && Echo. ",_ "CLS && Color F8 && Mode 35,3 && Title Folder Size && Echo. ",_ " && Echo -^> Processing Folder "," && Echo -^> ","Path Last Name",_ "Path","Created Date","Last Modified Date","Total Size")'/-> Converts Folder Size To MB Or GB If VAR(6) > VAR(5) Then VAR(6) = Left(Folder.Size /VAR(5),4) & " GB" Else VAR(6) = Left(Folder.Size /VAR(4),4) & " MB" End If '/-> Pass All The Varibles To Cmd Promt Act.Run("%Comspec% /c @Echo Off && " & VAR(7) &_ VAR(12) & VAR(14) & VAR(0) & VAR(2) & VAR(0) & VAR(1) &_ VAR(13) & VAR(14) & " : " & Folder.Name & VAR(0) & VAR(3) & VAR(0) & VAR(8) &_ VAR(12) & VAR(15) & VAR(0) & VAR(2) & VAR(0) & VAR(1) &_ VAR(13) & VAR(15) & " : " & Folder.Path & VAR(0) & VAR(3) & VAR(0) & VAR(9) &_ VAR(12) & VAR(16) & VAR(0) & VAR(2) & VAR(0) & VAR(1) &_ VAR(13) & VAR(16) & " : " & Folder.DateCreated & VAR(0) & VAR(3) & VAR(0) & VAR(10) &_ VAR(12) & VAR(17) & VAR(0) & VAR(2) & VAR(0) & VAR(1) &_ VAR(13) & VAR(17) & " : " & Folder.DateLastModified & VAR(0) & VAR(3) & VAR(0) & VAR(11) &_ VAR(12) & VAR(18) & VAR(0) & VAR(2) & VAR(0) & VAR(1) & VAR(13) & VAR(18) & " : " & VAR(6) &_ VAR(0) & VAR(3)),1,True Edited December 27, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now