MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 5th, 2002, 01:23 PM   #1
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

Hi,

I have 49 different excel files and my boss wants me to put them each into a different folder on windows e.g. Run_1.xls into folder Run_1 etc.

I don't really know how to create multiple folders automatically so right now I am creating new folders one by one manually changing Run number everytime - very laborious.

I apologise for this not being a pure excel question.

RET79
RET79 is offline   Reply With Quote
Old May 5th, 2002, 01:46 PM   #2
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

What OS are you using ie 98,NT4, 2000, ?
Nimrod is offline   Reply With Quote
Old May 5th, 2002, 02:16 PM   #3
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

I'm going to give you a batch file that I just wrote for you using W2K. This will work in W2k and probably nt4 . However the "for" command works differently in win9x and will not work if win9x is your OS.

Do the following to make this work:
1- Copy the following code
2- Paste code to notepad
3- Save the code to the directory that has all the xls files you want copied
4- MAKE SURE you save this file with the "bat" extention and not "txt".
5- if saved as txt then rename to "bat" IE MK_CP.bat
6- run the batch file by double clicking on it


::*************** copy following code to bat file***********

@echo off

:: make the directories to match file names
FOR /F "eol=# delims=. tokens=1,2*" %%1 IN ('dir /b *.xls') DO mkdir %%1

:: copy files to new directories
FOR /F "eol=# delims=. tokens=1,2*" %%1 IN ('dir /b *.xls') DO copy %%1.%%2 %%1


:: **************** end copy process here ***
Nimrod is offline   Reply With Quote
Old May 5th, 2002, 02:58 PM   #4
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

Nimrod,

It's Windows NT.

Thanks for your code, but I am not sure what it will do??

RET79
RET79 is offline   Reply With Quote
Old May 5th, 2002, 03:03 PM   #5
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

I'm almost sure the code will work on NT.
What will this code do ?
The first "for" statement will create a subdirectory for every xls file found in the same directory as the bat file.
For example if you put the bat file in a directory with num1.xls , num2.xls and num3.xls it will create 3 sub directories called num1,num2,num3.
The Second "for" statement will then copy Num1.xls to the Num1 directory... and do the same for num2.xls > num2 dir etc etc.

Do you need more help on how to take this code and save it to a bat file ?
Do you need more help on how to run a bat file ?
Nimrod is offline   Reply With Quote
Old May 5th, 2002, 03:06 PM   #6
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

Nimrod,

Many thanks, now I see what it does, great work! I'll let you know if I have any problems...

RET79
RET79 is offline   Reply With Quote
Old May 5th, 2002, 03:20 PM   #7
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

The "For" function in batch files allows you to parse an entire list or lines of data from another command and perform something with each line parsed.
It's kind of like array formulas in excel.

Lets take apart the following for command:
FOR /F "eol=# delims=. tokens=1,2*" %%1 IN ('dir /b *.xls') DO mkdir %%1

The section in brackets is where the for gets it list or array information from.
This could be a list in a file or a list generated by another command.
In this case we are using a dir command to generate a list of xls files in the current directory 'dir /b *.xls')

The delims=. tells the "for" statement to use periods in the incoming data as the data delimiter. This means the files name becomes variable #1 and the extention becomes Variable #2.

The "Do" section is followed by the command you want to execute , which is in this case a make directory command. i.e. Do mkdir %%1 , would tranlate into Do Mkdir Num1 , if there was a file called Num1.xls in the directory.


[ This Message was edited by: Nimrod on 2002-05-05 14:21 ]
Nimrod is offline   Reply With Quote
Old May 5th, 2002, 09:01 PM   #8
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

Hi Ret:
Did the script work for you ?
Nimrod is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 03:34 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes