Saved Bookmarks
| 1. |
Solve : I'm not crazy? |
|
Answer» HI there, Using Google I have been trying to create a simple batch program. I'm not a programer and I know I'm not crazy either. But I think what I'm trying to accomplish can't be impossible - it's just beyond my abilities. So I'm asking for help - before I go crazy and throw myself off a bridge. I've spent the past 5 hours trying to make a batch file that will copy a .jpg to another directory and give it a new name. That part is EASY. There are variables though. The original .jpgs are pictures of people using numbers as the name. What I need is to have the picture copied to another folder with the ability to enter the persons proper name. Wait! It gets more complicated - People, for some silly reason, sometimes have more than a first and a last name. *censored* I was able to write seperate batch files for two, three and even four names and they work. But what I really want is to do it all from one batch script, select the number of names I need (2, 3, or 4), enter the original .jpg file, then enter the proper names, PRESS enter and end up back at the 'select how many names' option. Here's what I've got so far: :BEGIN @echo off set choice= set /p choice=Enter the number of names for the pictured user to continue... if '%choice%'=='2' GOTO COPY2 if '%choice%'=='3' GOTO COPY3 if '%choice%'=='4' GOTO COPY4 :COPY2 CLS set /p choice=Enter picture number: if '%choice%'=='%5.jpg' set choice=%5 set /p choice=Enter first name: if '%choice%'=='%6' set choice=%6 set /p choice=Enter last name: if '%choice%'=='%7' set choice=%7 CLS COPY %5 "C:\Den\Destination\%6 %7.jpg" etc. for the 3 names, and 4 names options. Now, the above doesnt work. It asks the questions and looks the way I want, but it won't copy the picture. It says it can't find the picture. I have no clue why, but I'm hoping someone out there does and can tell me how to fix it, please. TIA Regards, "Insane in Waterloo"KISS should be every coder's anthem. %5, %6, %7 (actually %0-%9) are command line parameters. Unless you passed them on the command line when you ran your file, they have no value whatsoever. The set /p statement takes everything input at the prompt literally. Whether someone's name is Cher or John Doe, or Edgar Allan Poe the variable takes on the value of every character typed up to the return key. In your case there is no reason to know whether someone has 1, 2 or 3 names, the variable will contain Cher, or John Doe or Edgar Allan Poe and if they are the Artist Formerly Known As Prince, well, that will all be in the variable too. 8-)Based on the reply I have modified it thustly: :BEGIN @echo off set /p choice=Enter badge number: if '%choice%'=='%1' set choice=%1 set /p choice=Enter user name: if '%choice%'=='%2' set choice=%2 COPY %1 "C:\Den\Destination\%2.jpg" GOTO BEGIN Here's how I understand the above - The first set /p choice is to ask me what the file I'm looking for is called. For example I enter 564658.jpg which will be REPRESENTED as the variable %1 The second set /p choice is to provide the new name of the file. For example I enter Jean Luc Picard which is represented as the variable %2 The final command is to copy %1 to the new folder and rename it %2 and go back to start the cycle again. I know this is obvious to people except me but this doesnt work. Anyone care to help??? Well, it's simpler but think short story instead of NOVEL: Code: [Select]:BEGIN @echo off set /p badge=Enter badge number: set /p user=Enter user name: COPY %badge% "C:\Den\Destination\%user%.jpg" GOTO BEGIN The %0-%9 variables have special meaning in batch files and cannot be used in the context you were using them. 8-)That'll work.. Thanks for making my life simple again. |
|