Reputation: 514
I have my source folder that contains many, many folders that are named like this:
What I am trying to do is essentially create new, empty folders with those exact names.
This could be done is 2 ways I think:
or
I have never written a batch file. I was able to get this far, listing the directories though:
@echo
setlocal
FOR /D %%G in ("*") DO echo We found %%~nxG
endlocal
Does anyone know how to take the name found in the FOR statement, and create a folder in a specific directory?
Thanks! The syntax here sure is different!
Upvotes: 1
Views: 767
Reputation: 16266
Another way, if you wanted to use PowerShell. Works exactly the same on Mac and Linux.
Get-ChildItem -Directory -Path './srcdir' | ForEach-Object { Copy-Item -Path $_.FullName -Destination './destdir' }
Upvotes: 1
Reputation: 38719
I would suggest an easier method involving robocopy:
RoboCopy "SourceDir" "TargetDir" /E /Lev:2 /Create /XF *>NUL
Obviously you'd replace SourceDir
with the directory location holding your date named directories, and TargetDir
would be the directory location where you're wanting to replicate those names.
You can use just .
for the current directory if it is the source or target.
M
ake D
irectory command, MkDir
|MD
:
For /D %%A In ("SourceDir\*")Do MD "TargetDir\%%~nxA"
If the current directory is either SourceDir
or TargetDir
, you can remove it and it's trailing backslash.
Upvotes: 1