Environment: Windows 10
Question: If possible - how do we set the name of the top-most folder on a drive as a variable?
We receive a disc from a third-party that contains updates to a system we use - on the disc is a folder with the current version's title (e.g.
blahblahSystemblah-2018October-finalblah) and it contains all of the data in that version. After we put the disc in the system we use robocopy to update the server with the changes, and then users who run the system after that are updated by the server. Our current issues are that we have to set the folder name manually since robocopy can't (to my knowledge) use a wildcard in it's source, the folder name is important elsewhere so we cannot simply get them to put the contents directly on the disc, and ideally we'd like to not have to move the batch file before running it (using current directory would be easy, but as I said: the folder name is important, and we're trying to keep any manual input/effort from users to a bare minimum).
The relevant part of the script would look like this:
@echo off for (however you can get the top folder name automatically) do (set VRSN=however) robocopy "D:\VRSN" "C:\local\directory" /e /mir /r:0 /w:0 /log:"C:\log\directory.txt"
The closest thing I could find to getting there is this piece of script, where "knownfile" is the name of a file that will always be in the folder:
setlocal enabledelayedexpansion cd /d "D:\" for /R %%G in (knownfile) do ( set "var1=%%~dpG" set "var1=!var1:%CD%=!" if not "!var1!"=="!prev!" ( if "!var1!"=="\" (echo .\) else echo(!var1:~1,-1! ) set "prev=!var1!" )
-- but this script spits out more than just the folder with that known file, and it also clips the first character of the folder name. I'll be the first to admit that I do not fully understand the syntax or where it's going wrong, so if anyone could point me in a better direction or help me refine the above code to only return that one folder, it would be very much appreciated.