| 1. |
Solve : How to search a certain file and repeat until found? |
|
Answer» Hello, I am new to the forums and thanks everyone for your help. Here is how to increment in batch: Something along those lines. I was exploring a solution for this thread with that particular construct but realized that it would be more difficult than that: the numbers would need to have an appropriate number of zero's prepended. the bleeding obvious VB equivalent, Code: [Select]strnewname= "mx one " & String(4 - Len(Trim(Str(Number))), "0") + Trim(Number) & ".exe" doesn't work in batch. Oh... heh, I could always write a little script, I suppose; I'm not certain what the desired result is; that is, what "newfilename" is to be (?) Making a good batch file can be a lot of fun. But a person is better motivated to do a good job if they have a good reason. Looking over your original post, I don't see a very good reason for doing this. Pardon me, but that freeware program you're REFERRING to works very well just the way it is. So I don't get the point. You already know that it's going to give itself another name and delete the prior version. So what's wrong with that? But, if you insist, it's quite easy to find a file that has a certain name or has some ambiguity in the name. Now the question would be; Suppose to found 100 files that have ambiguous names. Do you want to delete them all? You want to rename the mall? Or just rename the last one and delete all the others? You objective is either not clear or in unreasonable. Remember, Reason must precede logic.Quote from: Geek-9pm on December 30, 2009, 02:18:47 PM Making a good batch file can be a lot of fun. But a person is better motivated to do a good job if they have a good reason. Thanks for the help. The purpose of this batch file, is that when the common box dialog that Autorun launches, it calls this batch file. I was creating the ability for the user to open the program every time it clicks on the desired option of the Autorun Select Option Dialog. As I said, I can do this everytime I want if the file I'm looking for is named Mx One 0001, for example, as I said. But when I do want to execute it, via the command line, in order for it to be called, executable files cannot have spaces in their names, so that's why I have to rename Mx?One?0001.exe to MxOne_Antivirus.exe, that is a valid executable file name at Command prompt. The reason I'm doing, is for a school project, hehe sorry to not mention that. My logic behind this, is to look the file name with an Index, as BC_Programmer stated with a VB Script instead of a Batch file; first I rename it (obviously a command prompt shows up as usual) and then, it renames Mx One 0001.exe IF Found IF NOT EXIST, then I have to look over the removable drive (only at its root) for the *.exe name containg at Least Mx One+an Index over it, then again, IF FOUND, rename that file to MxOne_Antivirus.exe that is a valid executable filename and last, launch it via command prompt (batch file), repeating this operation several times with a limit. (similar to search until found, obviously this limit has to be a little bigger). If this is more complex, and there's another portable, or practical solution like C, C++ or Java, or another programming language, please suggest Thanks PD With an Index I mean that the file has an ambiguity in its name, following your advice. This ambiguity is that the file deletes itself when you update, and changes its version that follows a sequence. So I do want to look up for the filename with an Index over its String name, and if found rename... bla.. Quote from: BC_Programmer on December 30, 2009, 01:47:51 PM Something along those lines. The new filename to be is, as my previous reply with a valid name, in order to be executed. It searches for Mx One 0001.exe, IF Found it renames this *.exe file for MxOne_Antivirus.exe, then it launches MxOne_Antivirus.exe that is the new Filename prior to the last one that was Mx One 0001.exe. This obviously, always works due that it only has to look for Mx One 0001.exe, but when you update it, a new filename with the next sequential version creates, deleting the previous one and leaving only the new one. So as I firstly explained: Mx One 0001.exe no longer exists, and Mx One 0002.exe is created instead. This is the UPDATED filename, with the newest deffinitions. I want to look over this ambiguity, leaving the ability for it to be an Auto-Execute option, that is called from my Modified Autorun.inf file, that calls this particular batch file. Thanks for any further help If I understand correctly, your filenames are in the form: "Mx One 0001.exe" with different 4 character numbers on the end or what have you. you can rename them ALL at once! I just remembered our good friend, the ? wildcard: Code: [Select]ren "?? ??? ????.exe" "??_???_????.exe" of course, if for some reason you have other exe files with 2 characters, a space, three characters, a space, and four characters, it will rename these, as well. But that seems unlikely.Quote from: BC_Programmer on December 30, 2009, 05:09:51 PM If I understand correctly, your filenames are in the form: Yes, that was exactly I was looking for, didn't know MS-DOS had that pattern . Ok, one last issue and it is minor. Obviously anyone who gets into their USB and launches my particular option I created with Autorun it will open a Command prompt window. I want it to be hidden, or show Up, but when the Antivirus program is called, I mean when this sentence is completed succesfully, close it immediately by itself, but leaves the Antivirus program opened. Can this be done? I've heard something about hstart execute file you have download, but it has a lot of features and more complex than I want to do.Not sure I understand, but you can use Exit in a batchfile to close it; programs it started will still execute.Quote from: Helpmeh on December 30, 2009, 01:27:17 PM Here is how to increment in batch:FYI: That way would only work if the OS he ran the batch on was NT or later. But BC's method is more methodical(and never knew about the ? wildcard ) |
|