| 1. |
Solve : I need some batch file help!? |
|
Answer» Friends, I need some help. I need a batch file that will read through a directory structure such as A-E which has folders inside with client name such Apple, Brass, Cotton. I need the batch file to search for a directory call 2012 in every folder if it's not there make it and make two more directories inside it called This Year and Last Year. If it does find a directory called 2012 it should continue to the next folder. This may work. Did you try it? I suspect not, because you used the undocumented, unofficial, UNSUPPORTED (as in "wrong") double-colon comment starters instead of REMs. Double colons (which are in fact broken labels) break PARENTHETICAL structures. Quote from: Bigwil on October 28, 2011, 12:51:06 PM Friends, I need some help. I need a batch file that will read through a directory structure such as A-E which has folders inside with client name such Apple, Brass, Cotton. I need the batch file to search for a directory call 2012 in every folder if it's not there make it and make two more directories inside it called This Year and Last Year.Why don't you post the file you have already. Show us you've done at least a little work on it Yes, it was tested, not extensively - but it worked. The double colons are a minor issue, just replace them with REMs or eliminate them altogether. There appears to be no shortage of bad manners on this board. A response to a help request, even one containing errors, isn't justification for a smear attack by multiple board members. I'm sure that isn't anything you don't already know, and I'm just as sure that you really enjoy it. Quote from: pathe3 on October 30, 2011, 11:48:55 AM smear attack Smear attack? Where? Do you know what "smear attack" means? Quote by multiple board members Multiple? Where? Quote from: pathe3 on October 30, 2011, 11:48:55 AM Yes, it was tested, not extensively - but it worked. It can't have worked with those double colons. We want working code here. Raven19528, your answer is yes. They are in Y:\Int. Quantos, as I mentioned I have virtually no skills with batch programming. Besides countless internet searches on how to create batch files, I had no clue as to how to start this project hence the call for help. I had nothing to show you. Pathe3, I will try your solution and report back. Salmon Trout, lets keep things positive ok. I appreciate that someone even took the time to respond. I'll keep you posted. Thanks again my peers! BigwilAlright, so try the following. Very similar to pathe3's solution, but a little simpler, which also helps to troubleshoot if needed. Code: [Select]echo off setlocal enabledelayedexpansion for /f "delims=" %%A in ('dir Y:\Int /b') do ( for /f "delims=" %%B in ('dir %%A /b') do ( set path=%%dpB if not exist "!path!\2012" ( md "!path!\2012" md "!path!\2012\This Year" md "!path!\2012\Last Year" ) ) )Considering the solution had already been posted, I'm surprised this thread is still alive. Must be the spirits of Halloween. The Pathe3 entry won't win any BLUE ribbons at the state fair, and probably wont get a medal from Microsoft Best Practices, but the fact is that it works as advertised and to the OP specs. Quote from: Raven19528 on October 31, 2011, 11:06:34 AM Alright, so try the following. Very similar to pathe3's solution, but a little simpler, which also helps to troubleshoot if needed. Good thing. There is a typo which prevents it from working properly. The lesson here is to troubleshoot the snippet before posting. Gotta go now and extort some candy from my neighbor! Happy Hunting sidewinder... Quote from: Sidewinder on October 31, 2011, 12:41:08 PM Good thing. There is a typo which prevents it from working properly. The lesson here is to troubleshoot the snippet before posting. *grumble, grumble* stupid ~ *grumble, grumble* Edit: Code: [Select]... set path=%%~dpB ... Quote I was working in the lab late one night This appears to have been created in a lab, but it goes along with my sense of proportion. Code: [Select]echo off for /f "delims=" %%A in ('dir Y:\Int /a:d /b') do ( if not exist "%%~dpnA\2012" ( md "%%~dpnA\2012\This Year" md "%%~dpnA\2012\Last Year" ) ) The MD command will create an entire tree structure if necessary. Back to the dungeon 'till next year. Hey Raven19528, thanks so much! We had to make some minor changes but your direction put me 95% on my way. Problem solved, mission accomplished. The solution ended up looking almost exactly like Sidewinder's submission. Thanks again. |
|