Martin Rezyne
Martin Rezyne

Reputation: 445

Windows CMD command: Get subfolder name

I want to make a script which copies some files from different locations.

I have the next folder: C:\Test\FILES\< RANDOM_NAME >\< many_files > . In this folder, I have many files which I need later.

I copy the entire directory < RANDOM_NAME > to my working directory. But later, in my script i need the exact name of < RANDOM_NAME > folder. How can i get it?

Upvotes: 0

Views: 5458

Answers (1)

MC ND
MC ND

Reputation: 70923

for /d %%a in (*) do set "folderName=%%a"

Under the assumption that the required folder is the only one inside the current directory.

The for /d will enumerate the matching (*) folders inside the current active directory and the name of the folder is assigned to the %folderName% variable.

Upvotes: 2

Related Questions