Solved

Script for directory creation

Posted on 2014-01-08
7
312 Views
Last Modified: 2014-01-08
Hi There!

I need to create our 2014 folders in 2 folders of every client in our client folder.

The directory structure is h:\clients\alphabet number (A, B, C etc)\client name\correspondence and create 2014 at this level

Second Dir Structure is the same but under h:\clients\alphabet number (A, B, C etc)\client name\documentation and create 2014 at this level.

I guess the logic would be, go through directory structure and when you find documentation or correspondence in the directory name, create a 2014 folder under it.

Ideally it might create a list of the folders it had created in a log and where so if it goes wrong we can reverse it :)
0
Comment
Question by:networkn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 39766394
Plain batch; it's currently in test mode and will only display the "md" commands it would normally run. Remove the uppercase ECHO in line 14 to run it for real (and delete the log file after the trial runs):
@echo off
setlocal enabledelayedexpansion
set SourceFolder=H:\Clients
set LogFile=Folders2014.log
set TargetFolderList="Correspondence" "Documentation"
set AddFolder=2014
for /d %%a in ("%SourceFolder%\*.*") do (
	echo Processing '%%~nxa' ...
	for /d %%c in ("%%a\*.*") do (
		echo   Processing '%%~nxc' ...
		for %%f in (%TargetFolderList%) do (
			if exist "%%c\%%~f" (
				if not exist "%%c\%%~f\%AddFolder%" (
					ECHO md "%%c\%%~f\%AddFolder%"
					if not errorlevel 1 >>"%LogFile%" echo "%%c\%%~f\%AddFolder%"
				)
			)
		)
	)
)
echo Done.

Open in new window

0
 

Author Comment

by:networkn
ID: 39766544
Doesn't seem to recognise the second folder for some reason? Correspondence was created not documentation
0
 
LVL 85

Expert Comment

by:oBdA
ID: 39766559
Works fine here; do the "Documentation" folders exist already? The "2014" folders will only be created if the target folders exist already.
0
IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

 

Author Comment

by:networkn
ID: 39766574
Ugh, my fault, misread the email I was sent. All good thanks.
0
 

Author Closing Comment

by:networkn
ID: 39766676
Awesome!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39766736
A little simpler would be perhaps to use a specific dir command then use that to make the dirs, does this give the right dirs for you?

dir /b /ad /s *correspondence* *documentation*

If so then

@echo off
for /f "tokens=*" %%d in ('dir /b /ad /s *correspondence* *documentation*') do md "%%~d\2014" 2>NUL

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39766740
I delayed posting there seeing only the original post of course, would have built on above to log but you have solution anyway it seems.

Steve
0

Featured Post

Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question