| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 22327 | 2002-07-18 03:28:00 | Generate multiple copies of a file, with specific names. | micheal (1099) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 63277 | 2002-07-18 03:28:00 | I'd like to get my hands software or a batch script that will make multiple of a file. More than that I want the generated files to have names generated based on list. This would be very helpful in my role as a teacher. I often need to create multiple copies of a file for kids. Any ideas how this can be done? Thanks Micheal |
micheal (1099) | ||
| 63278 | 2002-07-18 05:34:00 | This is the sort of thing that the DOS for statement is for". :D for NM in name1,name2,name3, ... , namen do thisname=bas+%NM+".ext" copy Thefile.ext %thisname next is probably totally wrong syntax.;-) I haven't got a book close, but that's the sort of nasty thing. I never used it --- it was easier for me to write a Pascal programme to do anything like that. You probably want "modern Windows" type filenames, rather than the 8.3 that DOS will make. It is probably not too difficult to do in a macro in Word or something: create a text file with each line starting with a say, 'xcopy "the original file.etx" ' then appending a name from a file which has one name per line. (xcopy will handle the new style filenames if quoted) .Then export it as text, and run it as a batch file. Haven't you got any bright kids in your class? I'd bet there's at least one in every class who could do it blindfolded. |
Graham L (2) | ||
| 63279 | 2002-07-18 05:57:00 | I just had a look at google for a use of "for". It's worse than I remember. In one batch file you would have for %%NM in (name1 name2 name3 name4 ) do call copyit %NM In another called "copyit.bat" have @echo off set newname="base"+%%1+".ext" xcopy thefile.ext %%newname Isn't it horrible? |
Graham L (2) | ||
| 63280 | 2002-07-18 08:35:00 | You could Exlporer to ctrl-drag the file, one into two, two into four, four into eight, etc. Then use something like multiple rename to rename to filename1, filename2, filename3. But that means they are just numerical names, not sure if that is okay. Gee, I even looked in my Dos 6 Technical Reference Manual (never noticed the choice command before). It is easy to turn ten different source files into one destination. How about this? Create a batch file called bigcopy.bat with this: copy %1% fred.* copy %1% john.* copy %1% deidre.* etc Bit of work the first time but when you type: bigcopy zaphod.doc It will create the little files. Put some subdirectory into the batch file to keep the results separate from the input file. Not 100% sure abiout the * but should probably work. Can't test as my machine's command prompt has gone stupid, can't type anything in. Happens now and again, no idea why, restarting fixes it. Good luck robo. |
robo (205) | ||
| 63281 | 2002-07-18 11:29:00 | Hi Michael, I'm learning VBA so this was a good exercise for me :-) If you have Excel, then you can use the following code to create copies of a file, with the name of the copies determined by what you enter in column A of the spreadsheet. First, enter the students names in column A (cells A1 downwards) and in cell B1 enter the number of students you have in this list Next, open visual basic editor (tools-macro-visula basic editor) then paste the following code in ... Private Sub FileCopy() Dim lastrow As Integer Dim count As Integer Dim kidsname As String Dim destinationfile As Variant Dim sourcefile As Variant Dim drive As Variant Dim extension As Variant Dim row As String Range("a1").Select drive = "c:\" 'enter full path preceding name extension = ".txt" 'replace extension with what you require lastrow = Range("b1").Value sourcefile = "c:\test.txt" 'replace this with the file you want to copy For count = 1 To lastrow row = "a" & count Range([row]).Select kidsname = ActiveCell.Value destinationfile = drive & kidsname & extension FileCopy sourcefile, destinationfile Next count End Sub Close Visual Basic Editor. To make this work create the file you want to distribute to your students and save it. In the above code I have called my source file test, located under c:\, so you can replace this code with your filename and path or just call your file test.txt and save it under c:\. Also, the destination path can be changed also for all the student files that will be created. Just make sure you enter your students names in A1 downwards and enter the number of rows in b1 and it should all be sweet. Btw, this was coded in Excel2000 so hope this works for other versions. cheers Parry |
parry (27) | ||
| 63282 | 2002-07-18 11:37:00 | ooops, forgot to say that to run the code select Tools - Macro-Macros, select the FileCopy macro and select the Run button. Parry |
parry (27) | ||
| 63283 | 2002-07-18 21:35:00 | Have you tried doing a mail merge in Word? Maybe this is not what you were looking for. Just a suggestion. | Pauline (641) | ||
| 63284 | 2002-07-19 03:45:00 | Tried out what you had in there on the generating copies with a batch script. Seemed to work ok. I'm a bit hazy on batch scripts. I just used the syntax that you gave me. The script just keeps repeating.... the lines rolling over and over in the command prompt. Even so, it still created the copies. Can you help me tidy up the script? Or point me in the right direction. | micheal (1099) | ||
| 63285 | 2002-07-19 03:50:00 | tried it... couldn't get it to work. not entirely sure where... what and how... Thanks anyway. |
micheal (1099) | ||
| 63286 | 2002-07-19 04:22:00 | It's all horrible. ;-) That's why I always wrote a Pascal programme to do anything like that. These days I would use a bash script in Linux using xargs (... or write a Pascal programme). You could use Basic. I believe that QBasic is still on the W9x CDs. |
Graham L (2) | ||
| 1 2 | |||||