| 1. |
Solve : Elegant Batch File to Make Folder and Copy 2 Specific file into? |
|
Answer» Hi Folks What is the rule that decides which files get moved to which folder? Hi and thanks for getting back to me. Currently I've a very large Excel file (1200 lines) which I'd like to edit and then save a a txt file, so I can use this as the basis of my batch. Each line of the xls file currently has, 2 columns Column1 is name Name of the Folder and Column 2 is the name of the of file, all files are unique and the folders are usually referenced twice, as most folders should end up with 2 files moved in. Hope I'm making myseld clear. Thanks Biscuit Please show a sample of the Excel file. Hi Thanks for getting back to me Here is a sample of the spreadsheet (which could end up being over 2000 lines long). Currently all the files are in a single folder, so all file names will be unique. Folder names are defined and will usually be referenced 2-3 times in the spreadsheet as each is ASSOCIATED with 2-3 drawings. Looking for a nice script that will both generate the folder and move each file into it's RESPECTIVE folder. Thanks BiscuitYou can make the lines of a batch script in Excel itself; I often do this. Have Notepad open. Step 1. Create commands to make the folders if they don't already exist (you can skip this if each folder does already exist, but it won't do any harm if you run it) I am using the letters for the columns, and numbers for the rows, as they are in your example spreadsheet. I hope you can see the formula in cell D3. Copy this down so it is in column D all the way down. Duplicated folder names won't matter. Highlight the cells in Column D that have the formula and paste into Notepad first. Step 2. make the commands to move the files Again, I hope you can see the formulas Highlight and copy the formulas in Column E into Notepad, below the commands you did in step (1) above. Finally, in Notepad, save the TEXT as a .bat file in the folder where the .dwg files are located, and run it. If you don't want to see the commands scroll past, put echo off as the first line of the batch. If you want the batch window to stay open until you press a key, put pause as the last line of the batch. The other alternative is to save the columns with the .dwg filenames and the folder names, from Excel, as a .csv file and make a batch to process that. Let me know if that is preferable. Quote from: Salmon Trout on March 29, 2019, 12:29:47 PM The other alternative is to save the columns with the .dwg filenames and the folder names, from Excel, as a .csv file and make a batch to process that. CSV file looks like this (I called it MyFile.csv for this exercise): Code: [Select]FOLDER,DRAWING Product 0021,765-245.dwg Product 0107,963-541.dwg Product 0956,524-890.dwg Product 0584,769-527.dwg Product 0022,835-245.dwg Product 0096,963-523.dwg Product 0021,192-879.dwg Product 1584,769-524.dwg Batch file Code: [Select]echo off for /f "skip=1 tokens=1-2 delims=," %%A in ('type MyFile.csv') do ( if not exist "%%A" md "%%A" echo Moving file "%%B" to folder "%%A" move "%%B" "%%A" ) echo Finished pause A third possibility is to use Visual Basic Script (which is on all Windows) to directly extract the data from the Excel spreadsheet, and I have been working on that, but as this thread has gone silent, I am not inclined to spend any more time on it. A fourth would be a VBA macro, (but likewise). Many Many Thanks for your response looks very interesting Sorry I didn't reply earlier I took "She Who Must be Obeyed" away for a long weekend with strict instructions to leave the laptop begind Anyway will try tonight Thanks Alot BiscuitMany thanks Salmon Trout Yes that works fine, thanks alot, just think it's a shame that the MOVE command doesn't have an option to generate a folder if it doesn't exist. Your EFFORTS much appreciatedd Biscuit |
|