Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Win/Batch: How to get the folder name from Var %1  (Read 8547 times)

0 Members and 1 Guest are viewing this topic.

JPRock22

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    Win/Batch: How to get the folder name from Var %1
    « on: September 18, 2020, 05:51:22 PM »
    Ive been cracking my head the past few hours trying to figure out how to pull only the folder name from a path passed on by a varible.

    %1 = C:/documents/spreadsheetNAME/filename.ext

    I need only "spreadsheetNAME/filename.ext"

    I can pull the filename and extension with %~nx1

    But I can figure out how to pull the foldername

    Thanks
    JPRock

    Hackoo



      Hopeful
    • Thanked: 42
    • Experience: Expert
    • OS: Windows 10
    Re: Win/Batch: How to get the folder name from Var %1
    « Reply #1 on: September 19, 2020, 10:30:28 AM »
    Hi   :)
    What about like this code  ;)
    Code: [Select]
    @echo off
    Set Var=%1
    for %%I in (.) do set CurrDirName=%%~nxI
    for %%I in (%Var%) do Set FileName=%~nx1
    echo CurrDirName\FileName = %CurrDirName%\%FileName%
    pause

    JPRock22

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Unknown
      Re: Win/Batch: How to get the folder name from Var %1
      « Reply #2 on: September 19, 2020, 06:11:10 PM »
      Thanks that seemed to work.