Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script for directory creation

Posted on 2014-01-08
7
Medium Priority
?
313 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 2000 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

670 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