This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 4701. |
Solve : Batch file delete file by file name? |
|
Answer» I'm trying to create a batch file that will delete files by a certain name. The files will all be similar to this. a20081010.txt or a20081011.txt or a20081012.txt... etc. Then if the files are older then 30 days for datemodified then I WANT to delete the file. Here is what I have so far. OBVIOUSLY, it doesn't work in it's current state. If I comment out the IF EXISTS it works if the file is older then 30 days. So I just need to work in the file name PART. Any help would be greatly appreciated! |
|
| 4702. |
Solve : Compilation? |
|
Answer» Hi, There is problem like that. Which is the best language to compile dos command with there.. like in C you use "System ("command") but some time like "/\^" this type of character junrate a problem on that so what is the SOLUTION.? Quote from: Deadly D on September 11, 2009, 09:48:58 PM Hi, There is problem like that. Which is the best language to compile dos command with there.. like in C you use LEARN proper C string escaping.Why not C# or Visual Basic? http://www.helium.com/items/1524872-making-use-of-escape-sequences-in-c-and-visual-basic Thanks for the replay. but C# need .net framework i think and all COMPUTER not use this THINGS so that's the problem any other way |
|
| 4703. |
Solve : Moving chaotic data ... looking for suggestions? |
|
Answer» A friend of mine came to me with her laptop that her whole family uses and data is scattered everywhere. She was wondering if I could help her get the data organized into folders for types of files such as music, pictures, documents etc. replication of a tree would be establishedYou get the idea. Make an abstract structure. Create a directory with a tree structure that makes sense. Populate the tree with shortcuts. Most application programs, in my experience, have no trouble using a shortcut to find the actual location of a file. The shortcuts take very little disk space ans allow you to use an alias name and an alternate icon. The are some programs that even do this for you. Some MP3 player software will organize your songs into play lists without the need to actually move the data. Also, photo album programs can do the same thing a deal with the problem of duplicated names. And you can even replace the Windows Explorer (Not Internte Explorer) with another program that does better job of organizing this. The advantage of using shortcuts is that you can move them, make new ones, delete them, modify them, rename them all without doing harm to the original file. And they are quick, very little system, overhead. Check this out: http://techblogs.wordpress.com/2009/01/31/15-windows-explorer-alternatives/ Hey thats cool ... I didnt even think about that. But the problem there would be when she wants to backup her data, it is still scattered.... so that I why I am thinking that the data has to physically move to a new path of C:\data\.... Maybe I should use more than batch, but a thumb drive as a cache to store the data, an intermediary bucket to move the data to, "but without the move command". An instruction that XCopys the matching data to thumb drive, then back to the C:\data\... then have a CLEANUP process after a verification that the files locates at C:\..."wherever they came from" matches the new location at C:\data\... I was thinking that this would fix the Cyclic Error issue with searching drive C and writing back to drive C and avoiding a loop. I suppose I could also use an exclusion, trying to figure out of the exclusion of path C:\data would work or if the thumb drive temporary file cache is a better idea. Thumb drive would likely slow down the process vs disk to disk without the USB communications bottleneck. What do you think? DaveLembke, You are smarter that you need to be. It does not have to be that difficult. The standard backup tools have all kinds of options that you can use to backup data and make special data sets with exceptions. You can even have the backup program detect files changed and make additional backups of just the files that have recently changed. Normally all the user data should be in the Documents and Settings area, if using Windows XP. Some application programs will put stuff in the Programs folder, which is annoying. But you can have the backup set selectively backup part of the programs folder. What I love about the backup program it can know where everything relay belongs. You only have to tell it to restore to original location and it will do just that. And if yo chose another location, it will duplicate the tree structure. Trying to do this in batch is a big chore. If you have another hard drive bailable you can transfer all of My Documents onto the spare drive and not ruin the My Documents link.Please read this: http://support.microsoft.com/kb/310147 My preference is to have My Documents of the main user on another partition. That way I can just backup all of the drive. Other users on not in the partition. Some files I do not use anymore I put into the documents of the other users. That is one case where I use the move. I do not need to do that very often. The are so many ways to backup it is hard to give a simple answer. But it is not realty hard. Just requires some fore thought. http://www.genie-soft.com/asp/community/KnowledgeArticle.asp?KBID=105 Hope this is of some help. And I am sure OTHERS here even more ideas about how they would take on this kind of project. |
|
| 4704. |
Solve : Good morning / Good afternoon display in BAT? |
|
Answer» Hello, Hello,for /f "delims=:" %A in ("%time%") do if %A LSS 12 (echo Good morning!) else (echo Good afternoon!)I just added this to the beginning of my BAT and it is not working. It simply closes the CMD windows very quickly. I added pause after it, but it will not stay open. Any ideas?Quote from: TheHoFL on May 28, 2009, 04:57:55 PM I just added this to the beginning of my BAT and it is not working. It simply closes the CMD windows very quickly. I added pause after it, but it will not stay open. Any ideas?Sorry...add space between "delims=:" and %A If that doesn't work, run CMD and drag the BATCH file to the window...press enter and see if it displays any messages.Works like a charm! Thank you for your assistance! You are very much appreciated right now! -HoFLQuote from: TheHoFL on May 28, 2009, 05:01:41 PM Works like a charm! Thank you for your assistance! You are very much appreciated right now!No problem! Feel free to stick around and help out other members, or get help if you need it!I am always looking for people to help. I am somewhat new to some of the commands used in BAT files. I pretty much used to make them when i needed them and then stop. I am trying to take the time to learn now though. Quote from: TheHoFL on May 28, 2009, 05:04:47 PM I am always looking for people to help. I am somewhat new to some of the commands used in BAT files. I pretty much used to make them when i needed them and then stop. I am trying to take the time to learn now though.That's great! Batch is extremely easy to learn, a bit difficult to master, but is so usefull for organizing files/folders or automating tasks!Check this out, you will find it awesome! ... Code: [Select]@echo off for /f "tokens=2*" %%a in ('net user "%Username%" /domain ^| find /i "Full Name"') do SET DisplayName=%%b for /f "delims=:" %%A in ("%time%") do if %%A LSS 12 (echo Good morning and welcome %DisplayName%) else (echo Good afternoon and welcome %DisplayName%) echo. ECHO You are currently signing on to %COMPUTERNAME% echo. ECHO Please wait while authenticating %username% with the %USERDOMAIN% domain. echo. pause echo on Very nice! I SAVED that one in my bat folder. I really like the idea too. Thanks for starting this topic, and thanks to Helpmeh for the solution. Quote from: TheHoFL on May 28, 2009, 05:11:02 PM Check this out, you will find it awesome! ...Quote System error 1355 has occurred.Note, %userdomain%==%computername% and %computername% NEQ %username%... Just putting that out there...Hmm... Are you connected to an AD domain? This seems to work for me... Quote from: TheHoFL on May 28, 2009, 05:20:20 PM Hmm... Are you connected to an AD domain? This seems to work for me...To an what?Just ran it right now. This is what i got. I changed the credentials and information, but this is what came up. Because i am joined to a domain the domain is not the PC name... fyi... Quote Good afternoon and welcome Michael LASTNAMEOh and AD is Active Directory. fyi...http://en.wikipedia.org/wiki/Active_Directory |
|
| 4705. |
Solve : Symbols like: ^|, ^/ and ^\? |
|
Answer» Hi, |
|
| 4706. |
Solve : DOS Batch Problem? |
|
Answer» I use DOS BATCH commands to FTP information from the IBM ISeries mainframe to a PC and then open that information using Excel. This works fine until a user has loaded about 4 big files. Then it does not download the information. That user has to restart their computer before they do more files. I have tried a memory manager with no luck. It sounds almost like a buffer problem. Is there a DOS command to clear the buffer or is there ANOTHER option someone can recommend I try? Thanks for any help.Could you post the batch?I have not USED excel. But excel has an import manager. |
|
| 4707. |
Solve : Moving files where filename contain characters from a list? |
|
Answer» I have a LARGE number of files in a directory but only want to MOVE over those that contain numbers that match any in a LIST of "ID's" that are in a text file. For instance, i have a file called test_111.wav and in the ID text file 111 is part of the list i want that file to be moved. If a file doesn't contain the specific number in the name then it doesn't get moved over. Does anyone have any suggestions or let me know if I am not explaining this clearly. |
|
| 4708. |
Solve : Verify the user entered value is correct.? |
|
Answer» Hi, there are other programming languages that are better suited for this task. Will this solution need to be strictly batch or can say VB or .NET be used? I agree with wbrost . But it could be done in batch as an exercise in learning more about batch. Is that what you want? As for me, it would take me about 10 to 20 minutes in a language I know well. But in batch it would be an all day project.It can be done with a for loop. I saw something when reading for /? but I can't remember the switch (if there is any). Hi everyone... I am new to this forum. Plz guide me how can i post the question. Thanx |
|
| 4709. |
Solve : create shortcuts using a batch file? |
|
Answer» My batch file moves a folder to "C:\example", but after it moves it, i want to make shorcuts to some files inside "C:\example". How would i do that?Quote i want to make shorcuts to some files inside "C:\example". How would i do that? What kind of files are these? Executables? File types associated with an application? Normally I would suggest a VBScript, but the NT Toolkit has a shortcut utility: Quote shortcut: [-? -h -f -c -r -s] [[-t] target [[-n] name]] [-d working directory] |
|
| 4710. |
Solve : how can we put space when i getmac? |
|
Answer» hello everyone, |
|
| 4711. |
Solve : net user command? |
|
Answer» i wanna display the NAME with NET user command can you help me PLEASE ? How should i do |
|
| 4712. |
Solve : IDE SATA conflict prevent boot cds..? |
|
Answer» HELLO all few days ago, i deleted an ntoskrnl.exe from system32 by mistake which TURNED out to be not the wisest of choices cuz it was required to boot the system..anyway,to avoid reformatting the whole system,am trying to MAKE a DOS boot cd from which i can copy the boot files that might have been deleted. So i went on to download and burnt a boot cd( http://www.bootdisk.com/bootdisk.htm) and then RESTARTED the PC *censored* the cd didnt boot (it gave me this error www.freeimagehosting.net/image.php?b47aaa1b02.jpg ) i have read somewhere in the internet that a mixture of IDE(my DVD writer) and SATA(my 80 gb hard disk) drives causes conflict and this was evident with my attempt to create a Norton Ghost 2003 image when I had to add a -NOIDE command befor building the image to avoid the conflict. The result ofcourse was that in DOS mode, Ghost couldnt see my DVD drive and was able to detect only SATA hard drive. So my question is, what should i do to create a working bootable DOS cd?What OS ? ? Do you have your Windows CD ? ? You need to get things running properly before Ghosting the drive or you will wind up with a useless image of things and still have the same issues. Do you have a previous Ghost image ? ?-it is win xp sp2 -yes i have one..but i need the boot cd to access DOS for a faster process. -i already have a working ghost image patio. No issues with that. The problem i had(which i luckily solved) was this ( http://www.techsupportforum.com/microsoft-support/windows-xp-support/230835-ghost-2003-boot-dvd-rw.html ) ..This is not though my problem. It is the creation of a boot cd that wouldnt produce the error in the pic and would allow me to use DOS FREELY .. |
|
| 4713. |
Solve : Else command? |
|
Answer» Quote from: Larssie111 on AUGUST 10, 2008, 12:18:31 PM That doesn't help me I know. Your picture shows that the two files being compared are not the same, and the differences are SHOWN. Then your code goes into a loop. I expect you have made an error of logic somewhere. Your code is very difficult to UNDERSTAND. Its structure is what programmers call "spaghetti code". FURTHERMORE, all the labels are named with cryptic letters and numbers, they all have similar names, the variables also, and it is not surprising that CONFUSION has resulted, and nobody wants to get a headache trying to unravel it. Quite apart from everything being in (single) Dutch! You should learn to write simple, readable, understandable code. But i'm Dutch The code is language independent, but I think you don't understand me. Oo But i have already made it in a couple of hours in Microsoft Office Excel |
|
| 4714. |
Solve : Calculating? |
|
Answer» How do you calculate in Dos Larssie111, he's got the answer to your question in his code. but %time% is not a number. I thought that "BATCH" might work with "time" as a number like some other PROGRAMS (eg. exel). I started a new thread for my question (Calculating using time). Frank |
|
| 4715. |
Solve : Only typing certain parts of a text file? |
|
Answer» HI all! I was wondering if it's possible - and if so, how? - to print only a certain part of a text file with the type COMMAND. e.g: Text file: Quote
How would i go about printing only say, the bit Quote chocolate? Thanks in advance, Kamak i also would like to know this. sorry I'm of no help.u cant us the type command alone to generate such an output put u can type out som lines of the file @echo off setlocal ENABLEDELAYEDEXPANSION set /a cont=1 for /f "delims=" %%i in (file.txt) do ( if "!count!" EQU "3" echo %%i set /a count=!count!+1 ) endlocal this code will print the 3rd line if u want it to print from the 3 to 5 row u have to do this @echo off setlocal ENABLEDELAYEDEXPANSION set /a count=1 set /a count2=3 for /f "delims=" %%i in (New.txt) do ( if "!count2!" GTR "5" set /a count2=0 if "!count!" EQU "!count2!" ( echo %%i set /a count2=!count2!+1 ) set /a count=!count!+1 ) endlocal pauseQuote from: .bat_man on June 12, 2008, 10:50:53 AM u cant us the type command alone to generate such an outputThank You welcom welcomWhat if you wanted only certain lines. Say lines 3, 5, 8, etc.?Think I got it. At least it is doing what I want. Anyone have a cleaner way to do this, post for all to enjoy. if EXIST File2 del file2 setlocal ENABLEDELAYEDEXPANSION set count=0 for /f %%v in (File1) do ( set /a count=!count!+1 echo !count! if !count!==3 echo %%v > File2 if !count!==5 echo %%v >> File2 if !count!==10 echo %%v >> File2 if !count!==70 echo %%v >> File2 if !count!==71 echo %%v >> File2 if !count!==72 echo %%v >> File2 ) |
|
| 4716. |
Solve : regsitering all dll files inside a folder? |
|
Answer» There are 100's of dll in a folder and I want to run regsvr32 on all those dlls. How can I do that? |
|
| 4717. |
Solve : graphic images or pictures? |
|
Answer» I still don't understand what you're saying ( and SINCE I'm trying to write in perl I switched to the perl forum) but what I want is to be able to run a perl program and open and manipulate a picture in perl or whatever. The "" is required if the path and the file name of the started file needs to be quoted. (ex: start "" "C:\Documents and Settings\Compaq_Owner\My Documents\Perl\us.jpg") Please, if the started file needs to be quoted then I was assume that this is some type of C (language) variable? And the unquoted started file but be an absolute? Thanks Diane I know nothing of C programming language. Quote from: dimilinowski on August 11, 2008, 11:00:57 AM And I assume Apple has their own version of cmd.exe also (or even the same one)? Apple doesnt have any thing that even remotely RELATES to Command Prompt or MS-DOS, because Command Prompt and MS-DOS were created by Microsoft which is were they got MS-DOS(Micro.Soft-Disk.Operating.System) but there is a emulator of Command Prompt for Mac OS X that you can download here.Quote from: dimilinowski on August 09, 2008, 06:29:59 AM what I want is to be able to run a perl program and open and manipulate a picture in perl or whatever. Here is a tutorial on opening files in Perl. |
|
| 4718. |
Solve : Show last line of text file? |
|
Answer» Hi |
|
| 4719. |
Solve : DOS 6.22 Clock Problem? |
|
Answer» I have a system that does not have windows on it and is running DOS 6.22. The date and time will not maintain which seems to be common according to the comments I have been reading. |
|
| 4720. |
Solve : delete file fast? |
|
Answer» like you know if you delete too much files it takes too much time anyway to delete this files in shortime ? What are you trying to delete? like you know if you delete too much files it takes too much time anyway to delete this files in shortime ? Can we have that again in English? Quote from: DIAS de verano on August 10, 2008, 07:14:57 AM Can we have that again in English? Did you ever consider that the original poster might not be used to the English language?Quote from: kpac on August 10, 2008, 09:51:41 AM Quote from: Dias de verano on August 10, 2008, 07:14:57 AMCan we have that again in English? Of course I did, and I felt that they should make a bit more effort, since their meaning was not clear, so I fed that back to them.Quote from: Carbon Dudeoxide on August 10, 2008, 05:56:21 AM What are you trying to delete? winXP_pro_sp2And: Quote What are you trying to delete?Quote from: kpac on August 10, 2008, 02:59:56 PM And: any filesQuote from: zodehala on August 11, 2008, 12:12:16 PM any files Is it pictures/text files/folders or programs?zodehala, deleting many files takes time. You cannot change this. If you are emptying a Flash DRIVE or Portable Hard Drive (completely get rid of everything on the drive, you can Format it very quickly. If you are deleting CERTAIN files, you can HOLD SHIFT while pressing Delete and it will delete it permanently without going to the Recycling Bin.a SCIRP like phpbb has more than 250 files (total 3-4mb) in unix server i can all files about 1-2 sec using cpanel. but in windows (my comp.) i can all files about 45-60sec whyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy?1. Effect of different filesystem: ext2fs vs FAT or NTFS 2. Only one letter 'y' in the word 'why'. Quote from: zodehala on August 12, 2008, 12:34:01 PM a scirp like phpbb has more than 250 files (total 3-4mb) in unix server i can all files about 1-2 sec using cpanel. but in windows (my comp.) i can all files about 45-60sec Quote from: Dias de verano on August 12, 2008, 12:38:18 PM Effect of different filesystem: ext2fs vs FAT or NTFS Basically: cPanel, and a website's files are on a web server, and your files are on your hard drive..... Obviously a web server's file-removal speed is going to be faster than your PC. |
|
| 4721. |
Solve : Batch Program Tip? |
| Answer» NEVERMIND, dont use CTRL+V to paste it in.. make SURE quickedit mode is on and then paste it in using the right MOUSE BUTTON | |
| 4722. |
Solve : i want to make a file name changer.? |
|
Answer» I have a lots of music, and lots of them have an underscore in lots of places eg. I have a lots of music, and lots of them have an underscore in lots of places eg. If you can read the hieroglyphics on the wall, you are WELCOME to try this. Note: This was literally tested with blabla_bla_-_blabla.mp3. Code: [Select]@echo off setlocal enabledelayedexpansion for %%V in (C:\temp\*.mp3) do ( set newname=%%~nxV set newname=!newname:_= ! ren "%%V" "!newname!" ) Be sure to point to your directory. Quote I also have a few game folders i with CD in the name that i want to remove eg. This can be accomplished by tweaking the posted code. If it's only a few game folders, doing it manually might be faster than writing code. Good luck. Quote from: Sidewinder on August 12, 2008, 05:18:46 AM QuoteI have a lots of music, and lots of them have an underscore in lots of places eg. Thank you very much, it helped but it doesn't make it in underfolders. :/ its above 300gig games so its quite a few dunno if this will work (i dont test it) change this Code: [Select]for %%V in (c:\temp\*.mp3) do (to Code: [Select]for /F %%V in ('dir /b /s *.mp3') do ( ofc YOR file must be in right folder |
|
| 4723. |
Solve : command prompt help? |
|
Answer» Hi... Code: [Select]echo.Hello how are you?Yeah but he said he didn't want the user to input anything Thanks for the prompt replies... You are right Carbon Dudeoxide ---> ----- "I want the batch file to interact with CMD Window?----- I think I am starting to get a vague idea of what you want..... So you start a batch file, it will ask 'How Are You?' and you want it to automatically reply and say 'fine'? Lol, is it just me or is anyone else getting confused? Actualy i m implenting a code from java which EXECUTES on command prompt but cmd prompt hangs and waits for an answer.. i want this answer to automatically reach cmd prompt..... any way HW can i do that....Anything you can show us or give an example?jsut an example for what i mean..... In Java : Process p = runtime.exec("cmd /c start xcopy c:\abc.txt c:\bin /m); at cmd prompt: c:\>xcopy c:\abc.txt c:\bin /m Does C:\bin specify a file name or DIRECTORY name on the target (F = file, D = directory)? _ --- here cmd prompt expects an input which I want to come automatically Quote from: MAKT on August 13, 2008, 04:55:11 AM Thanks for the prompt replies... lol, i didnt read it carefully |
|
| 4724. |
Solve : Parsing text file to get variables.? |
|
Answer» I'm trying to parse multiple text files to determine whether a dummy mac was used or not for a setup script. MAC is the 3rd field. I thought about looking for the first X# of characters but given that I don't know if the reserved IP is 1, 2, or 3 digits long, I need to figure out how to get it for all 3 conditions. (batch file will be run on W2k) |
|
| 4725. |
Solve : My DOS sytem finally failed? |
|
Answer» I have one PIECE of software which ran on a 386dx40. Today (14 years in) I finally got the "non sytem disk error". |
|
| 4726. |
Solve : Extract first characters from each line from a txt file? |
|
Answer» Who KNOWS how can i extract for example 10 characters from each line from a txt file. |
|
| 4727. |
Solve : Help!!! How Do I Delete All folder From A Directory? |
|
Answer» I have a problem deleting all folders in a directory.The only way i found is to use rd /s [NAME Of Folder],but i want to delete all folders at once... I tried rd /s *.* & rd /s * but that did not worked.The same with del command. SORRY For My Bad English Waiting for your help...TyCode: [Select] rd /s [Name Of Folder] but i want to delete all folders at once What result did you get? Note: Expect incorrect results if you're logged-in to any directory within the named folder tree structure. First of all i want to thank you,for replying in my post.Now if i have a folder named Folder1 i write rd /s Folder1.With this way i delete the folder and all the subfolders contains in it.My problem is if i have in a folder other 10 folders.How can i delete these 10 folders all at once???(I don't want to delete the first folder,i want to enter to first folder and then delete everything that is in it. Waiting....In order to GIVE you UNDERSTAND i'll give you an other example.If i want to delete all the files a folder contains i write del /q *.* .Now with rd what should i write instead of *.*?Quote I don't want to delete the first folder,i want to enter to first folder and then delete everything that is in it That was an important piece of information. Code: [Select]@echo off for /f "tokens=* delims=*" %%i in ('dir /s /b /a-d folder1') do ( del /f %%i ) for /f "tokens=* delims=*" %%i in ('dir /s /b /ad folder1') do ( rd /s /q %%i ) Note: You should use a fully qualified path to folder1. The code is written as a batch file to be run from the command prompt. I will look for what this loop does.Now i can't understand exactly.I will look for it and you will have my reply if i accomplished it. |
|
| 4728. |
Solve : Makedependen warnings? |
|
Answer» I am USING makedepend source downloaded from C:\makedepend\makedepend: warning: C:/Program Files/Microsoft Visual Studio/VC98/Include/winuser.h: non-portable WHITESPACE encountered at line 2444 Can any one help me out to slove this , while before using this CODE I was not getting this warning with makedepend . previously I use makedepende exe provided by someone , I dont have the source code of that one. Thanks for any help .makedepend utility always complains about whitespace before the '#' in preprocessor directives. if any one get this warnings the easiest way to avoid that , dump these warnings into a temp file and deleting this temp file at the end. |
|
| 4729. |
Solve : Search and Replace files in a folder? |
|
Answer» WOW! I mean I want to replace Q10,Q10_,Q10- into Q1. Should this pattern "\s[Qq]1\s" work on that scenario as well? I'm having a hard time deciphering your intent. If you want to replace Q1 with Q1,Q1_,Q1- then yes, the pattern posted should do it. If you want to replace Q1,Q1_,Q1- with Q1, then no, the pattern does not match the data. In the script, the input box is the replacement string and the pattern is what you're searching for (hardcoded into RegEx.Pattern). BASED on your test data, q1 q1 0q1 1q1 q1 0q10 q10 q100 q1, you don't need a regular expression to see that Q1,Q1_,Q1- is an incorrect pattern. Did you use the tool I suggested. It won't do the replacement, but it will indicate if the pattern matches the data. Always a good first step. Hey! How can we modify your latest vbscript to have a counter for those affected files only. 'Coz what I want is to show the number of files affected (texts changed) and what are those files thru a msgbox after the process is done. You can use the test method of the regular expression. Not sure what version of the script we're using so I used the last script posted. The new code has not been tested, you make have to tweak it a bit. Code: [Select]Const ForReading = 1 Const ForWriting = 2 strReplace = InputBox("Enter Replacement String: ","Text to replace!") Set RegEx = CreateObject("VBScript.RegExp") RegEx.Pattern = "(\bq1\b)" RegEx.IgnoreCase = True RegEx.Global = True Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder("C:\44444444\builder") 'use your directory Set fc = f.Files count = 0 For Each fs In fc If fso.GetExtensionName(fs) = "xml" Then Set fi = fso.OpenTextFile(fs.Path, ForReading) strContent = fi.ReadAll fi.Close Set fi = fso.OpenTextFile(fs.Path, ForWriting) retVal = RegEx.Test(strContent) If retVal Then newContent = RegEx.Replace(strContent, strReplace) fi.Writeline newContent count = count + 1 Else fi.WriteLine strContent End If fi.Close End if Next MsgBox "Done! There were " count " files affected" Happy trails. Thankz Bro! I'll check this code in a bit. Have a 'lil problem 'bout regex. Ex.: My text fiIe has the contents of "Q1", "Q1_1", "Q1_2", "Q10", "Q10_1" ... and I want to change Q1 only into something like "Q50", "Q50_1", "Q50_2" ... For that I'd used the pattern "q1\b|q1_" 'coz per this site -> "http://msdn.microsoft.com/en-us/library/1400241x(VS.85).aspx" => x|y -> Matches either x or y. For example, 'z|food' matches "z" or "food". '(z|f)ood' matches "zood" or "food". I'd tried it and it didn't WORKED for me, only "Q1" are affected. Any idea what's the cause? Is my pattern wrong? Quote Is my pattern wrong? Of course it's wrong, it's always the pattern. Try using \s for the white space instead of \b. You can try this: "(q1\s|q1_)" It would be helpful to let us see the first 10 or so records from the text FILE. Stringing it out makes it harder to visualize what the actual data looks like. Try to keep the pattern simple.Hey! It still won't work. For example: This is the content of my text file: "q1" "q1_1" "q1_2" 0q1 1q1 q1 0q10 q10 q100 q1 George Bush "q10" "q10_1" "q10_2" and I want to replace all occurrences of q1 like in "q1", "q1_1", "q1_2" and change them into "q50", "q50_1", and "q50_2". Also, "Q10" should not be affected neither "q10_1" or "q10_2". hey! Your code works but it replaces also the underscore in "Q1_1" or "Q1_2" and turned them into "Q501", "Q502" assuming I replaced Q1 by Q50. You have all the tools you need to get the script working. I'm thinking that regular expressions may not be a solution after all. There does not seem to be any pattern to the data, although I did find Waldo It's one thing to replace all the q1 with Q50, it's another to have leading quotes, leading spaces and leading numeric characters along with trailing quotes, trailing spaces and trailing characters with different rules as to when to make a replacement.. For example, if you use the double quotes in the pattern, you need to use them in the replacement string. This sounds simple enough until you find newly quoted strings that never had quotes in the original text. If you don't use quotes in the pattern, you run the risk of making replacements that shouldn't be made. It might be easier to parse each word and decide whether to make a replacement or not. In this manner you could change the pattern depending on the chunk of data you've parsed. Good luck. OK. I'll THINK about that. I'll look for some other solutions on this one. Thankz! |
|
| 4730. |
Solve : Multiple files on batch? |
|
Answer» Hey guys, |
|
| 4731. |
Solve : ping more than one ip? |
|
Answer» is it possbile to ping more than one IP WITHOUT any script or appalication or etc.How do you mean?You can run SOMETHING like this from the command prompt: You can run something like this from the command prompt: very very THANX u r perfect Lol, okay... Good Work Sidewinder |
|
| 4732. |
Solve : Boot CD + menu? |
|
Answer» Hi, I want to make a Bootable CD that has a menu appear giving options to auto run such utilities as "spinrite" "ghost" "Partition Recovery" etc. |
|
| 4733. |
Solve : if error occurss??? |
|
Answer» Hello everyone , %HOMEPATH%\DesktopHOMEPATH doesn't have a drive. Use %userprofile% homedrive and path together. Don't replace the RED with the variables. Try using this as the path. "%userprofile%\Desktop\%nameset%.bat" |
|
| 4734. |
Solve : how to uninstall the password protected software?? |
|
Answer» in my pc i have installed "blue coat K9 web protection software" |
|
| 4735. |
Solve : cmd mac address print into file ???? |
|
Answer» HELLO everyone , How can i PRINT MAC address of the computer to txt file and create file on desktop as default lacation for the local area network THANKS try getmac |
|
| 4736. |
Solve : CPU usage during batch execution? |
|
Answer» If I write a batch to loop constantly in order to check a change in VALUE, it will DRIVE the CPU usage up to 100%. Other than using AT or SLEEP, can I make it a less intensive PROCESS? How does AT work without visible CPU usage anyhow?The AT command works with your SYSTEM's Scheduled Tasks, by adding whatever to the list of Tasks to do. |
|
| 4737. |
Solve : Using Findstr /x can't find exact match.? |
|
Answer» When using: C:\Temp>echo X>>file.txt Quote The echo places a space and newline character after the "X" How do you know that? I suspect it inserts carriage-return and LINE-feed characters. What version of the command PROMPT are you using? OK having tried to go through this step by step logically i can't see what's going on... maybe it's something to do with having more than one string in the file my actual code looks like this: Code: [Select] findstr /x /i %comm% %CD%\users\current\software.dat >num.dat where %comm% is a user defined variable and the file software contains: "help list telnet account bbs cracker " when i write a test script to find out what's wrong it sometimes works and sometimes doesn't I suspect your right it's probably a carriage return and line-feed and i don't know what version, im using Vista so i guess the latest?I suspect the lines it doesn't work for are the first and last lines. You only have one word per line. Why even use the /x switch? The /i switch makes it case insensitive, which is not an exact match anyway. Code: [Select]@echo off set comm=help findstr /i "%comm%" %CD%\users\current\software.dat >num.dat |
|
| 4738. |
Solve : Find and Copy files in dos from undefied path? |
|
Answer» Hi all, I am new to this FORUM, kindly help me to find out the things. |
|
| 4739. |
Solve : How to pipe or redirect STDOUT into an EXISTING Console application's STDIN? |
|
Answer» HI, I want to launch and read the output of a DOS .bat process from WITHIN another programming language (LabVIEW.) if I launch both the DOS-command and my app this way: MyBat.bat | MyApp.exe Then MyApp's STDIN does receive the STDOUT of MyBat - MyBat is a .bat file that loops indefinately and updates the CONSOLE (or STDOUT) once a second. ... the trouble is, I need to launch MyBat from within MyApp - which I can do - but how to pipe/redirect MyBat's STDOUT so MyApp can read it? It's not acceptable to write-to/read-from a disk-file! Can I use MyBat > ? or MyBat | ? to write to MyApp's STDIN? - If so, how? I don't understand the nature of the arguments to the pipe and redirect operators, but wonder if, perhaps, a DEVICE can be defined such that MyBat could pipe or redirect to MyDEVICE, and MyApp could read from it? Any help is appreciated, Cheers! Maybe it would help if you could tell us what is the piratical use. Batch files are just that. Batch files. They have limited ability to respond to events. They normally do a sequence of stuff as fast as they can and then quit. Sometimes an application needs data from the DOS command line. The application can start a 'shell' process that invokes a DOS command and then closes the shell. But if you have something that returns once a second, maybe it should be a device. The serial port on modern computers can store up to 16 bytes of data without overflow. So you would not need a ISR or DMA if the data were LESS that 16 bytes each time. |
|
| 4740. |
Solve : how to put space between echos??? |
|
Answer» Hello , |
|
| 4741. |
Solve : Remote Shutdown Command? |
|
Answer» okay, this: HTTP://support.microsoft.com/kb/919216 article was used......I didnt already have a restrictremoteusers key value, so i created ONE, and set the value to '0'. I also disabled "Restrictions for Unauthenticated RPC Clients" in the Group Policy Object Editor. Yet, I am still DENIED access for remote shutdown. http://blogs.msdn.com/aaron_margosis/archive/2006/01/27/518214.aspxQuote from: Dias de verano on August 18, 2008, 11:24:21 AM http://blogs.msdn.com/aaron_margosis/archive/2006/01/27/518214.aspx I added INTERACTIVE to the list, but i am still told access denied |
|
| 4742. |
Solve : How do I copy text in a text file to another file using batch file?? |
|
Answer» Hi All, |
|
| 4743. |
Solve : please help me it is an emergency? |
|
Answer» I have a FAILING drive and need to copy it using x copy I think it is finding the failing drive as drive F: Not sure if this is appropriate, but if you try to copy a file >4Gb to a FAT formatted drive, you get just that error message (not enough space) if he's running Vista from a 250GB C: drive, I doubt it's FAT Quote from: ALAN_BR on June 08, 2009, 09:19:43 AM I recommend Teracopy from http://www.codesector.com/teracopy.php XCOPY can do the very same thing. /C can be used to continue copying if an error occurs. Also, since there is the option to only copy files that already exist, as well as a way to output files that would be copied, one can redirect the output from that display of possible files with the switch to only show those that already exist in the destination, and, on a subsequent use that list of files that do exist in the destination as the /EXCLUDE: parameter. It takes a little thought but the same functionality that "teracopy" offers is reproducable via XCOPY, thanks to it's large number of options. I agree xcopy can do this sort of thing I like the fact that if Teracopy has a problem getting a good copy, it will automatically make several repeated attempts before moving on, with no manual intervention Additionally it checksums each source file and each destination copy, and compares the results, and gives a nice summary of the failures. Regards Alan |
|
| 4744. |
Solve : help please ECHO PROBLEM it doesnt write into text file? |
|
Answer» hello |
|
| 4745. |
Solve : Make batch react to buttons? |
|
Answer» Dias, this interests me the most. 1. Your code only works for lowercase letters of the alphabet 'a' to 'z'.Would the use of /I make uppercase and lowercase the same?Quote from: Sky Ninja on October 11, 2008, 10:06:52 AM Would the use of /I make uppercase and lowercase the same? The use where? Nevermind, it wouldn't. I meant in the if's. Anyway, I figured out how to get new errorlevel settings. Code: [Select]set key=%errorlevel% [b]echo %errorlevel% >C:\errorlevel.txt[/b] REM ASCII value of key is contained in %Key% Press a known key, then press an unknown key, and if it's different from the known key, you've got a new errorlevel. Code: [Select]If %Key%==48 echo 0 [%Key%] If %Key%==49 echo 1 [%Key%] If %Key%==50 echo 2 [%Key%] If %Key%==51 echo 3 [%Key%] If %Key%==52 echo 4 [%Key%] If %Key%==53 echo 5 [%Key%] If %Key%==54 echo 6 [%Key%] If %Key%==55 echo 7 [%Key%] If %Key%==56 echo 8 [%Key%] If %Key%==57 echo 9 [%Key%] ::---------------------------------------------------------- If %Key%==13 echo ENTER [%Key%] ::---------------------------------------------------------- If %Key%==27 echo Escape [%Key%]Without wishing to be horrible, I will point out that code which contains a zillion lines like this: Code: [Select]IF X = 1 goto one IF X = 2 goto two [...] IF X = 254 goto twofivefour IF X = 255 goto twofivefive (etc) ... is generally the mark of the beginning coder. Sometimes it cannot be avoided, but it is much better to find a more compact SOLUTION, which I already have shown. Hey, this is just an addition to Jacob's code. |
|
| 4746. |
Solve : Please Help!!!!? |
|
Answer» A COMPANY gave me a compaq 800 and when it boots up it reads DISK ERROR....but when I put in Windows xp it installs half way then reads the same thing and RESTARTS....How do i get to the Bios and DOS Command from here, or should i just replace the hard drive???Seems like the hdd has failed but it's always worth confirming by using the hdd manufacturer's diagnostics from here.. |
|
| 4747. |
Solve : Verifying the content of the read string from input file? |
|
Answer» Hello, |
|
| 4748. |
Solve : How can I identify dynamic environment variables - SET does not help? |
|
Answer» gh0std0g74 - thanks for dropping in. cause AFAIK, %DATE% , %TIME% or %RANDOM% are little things that cmd.exe gives you out of convenience, they are not environment variables. The Set command Help display (set/?) names these as "dynamic environment variables". AFAIK the placeholder does not contain a value, the value is computed when the dynamic environment variable is expanded. Not containing a value means that the dyn env var cannot be displayed using Set, there simply isn't anything to display. Regards D.What ghostdog means is, they are not "really" environment variables, in that they do not reside in the environment block (which is basically what "set" shows.) Also- applications can only change the environment block- including acronis. I would imagine that they documented what variables they define.Quote from: BC_Programmer on June 07, 2009, 10:04:16 PM What ghostdog means is, they are not "really" environment variables, in that they do not reside in the environment block (which is basically what "set" shows.)that's right. Dusty When I first saw you jpeg I could not read it until I clicked and it enlarged. When enlarged I saw " %cmdcmd line% ". I now realize my tired eyes misplaced the space, it now LOOKS like %cmdcmdl ine%, but when I greatly magnify the image I realize the "space" is an artifact due to "DOS" not using proportional spacing. Thank you for your explanation. The world makes a little more sense now. Thank you for the link to "The uses of Setlocal Enabledelayedexpansion", and also for pointing me BACK to the use of "SET /?" - previously I never read through to the end because my problems were usually resolved halfway through ! ! Thanks to everyone who recently posted. If Acronis created a variable "acronis_in_variable" I would be O.K. with "set acro=%acronis_in_variable%". Unfortunately I do not know the name(s) of any variables they may create, and do not even know if they create any at all. n.b. My interest is in ANY sort of variable that Acronis may use or influence, not just fixed and dynamic, but also other sorts (I vaguely remember last year I encountered at least two other sorts, including "dynamic"). Regards Alan I think, what your seeing as "dynamic" variables, are merely variables Acronis adds before running your script. See, when a program executes another program, it can pass a new environment block to that program. Acronis, for example, is possibly adding new variables to it's environment block and passing that as the environment of the script. Havey you tried using "SET" from within your script? perhaps redirecting it to a file? This will reveal such variables. I still believe that Acronis would have this type of stuff documented somewhere.Hi No, we have a misunderstanding. I have never seen any sort of variable that looked as though it was RELATED to Acronis. I merely hoped that there was such a variable that might give me a clue upon what it was doing. I have ALREADY tried Code: [Select]ECHO CMDCMDLINE == %CMDCMDLINE% >> C:\Utils\CMD\ToBak.txt SET >> C:\Utils\CMD\ToBak.txt The first item shows me command issued by Acronis, which was CMDCMDLINE == cmd /c ""C:\Utils\CMD\ToBak.cmd" A B C D" I had been hoping to learn of other dynamic/volatile/special variables, such as %CMDCMDLINE%, which SET does not display, but which are displayed with a suitable Code: [Select]ECHO %whatever% to give me a further insight. I have already inspected several MBytes of Acronis documentation without success, and have also posted queries on the Acronis support forum looking for specific guidance. I have lost hope of finding any useful Acronis variable of any sort, and think they probably have not created any such thing, so I am giving up on this and will use a totally different approach to meeting my requirements. My thanks to everyone who has responded to this thread. I have gained extra useful knowledge, even though my original quest has failed Regards Alan it's also possible, that they are passing some items via command-line arguments to your batch file.Yes, my script captures CMDCMDLINE == cmd /c ""C:\Utils\CMD\ToBak.cmd" A B C D" The TRAILING "A B C D" are the only arguments that I receive, and they do not help me either ! Regards Alan |
|
| 4749. |
Solve : Possible?? |
|
Answer» Is it possible to create a batch file on one computer (my PC) that will tell it to shutdown, but leave (SOMETHING?) on so that a command could be run on my laptop and transmitted to my USB network adapter in the PC to tell it to start up? Am I crazy Simply, nope. thought notIf the computer supports Wake On LAN (WOL) then you can do it. You computer (NIC and BIOS) need to support WOL, and make SURE it is enabled in the BIOS. Then you can USE a program like http://www.wakecomputer.com/WOL/index.aspx or http://www.matcode.com/wol.htm to send a "MAGIC packet" to turn the computer back on. Your laptop can have a USB NIC, but the PC will need to have a hard-wired NIC that supports the WOL.Wake On LAN If the computer supports Wake On LAN (WOL) then you can do it. You computer (NIC and BIOS) need to support WOL, and make sure it is enabled in the BIOS. Then you can use a program like http://www.wakecomputer.com/WOL/index.aspx or http://www.matcode.com/wol.htm to send a "magic packet" to turn the computer back on. Your laptop can have a USB NIC, but the PC will need to have a hard-wired NIC that supports the WOL.I will look into this |
|
| 4750. |
Solve : Build a better Batch file (for changing zip -> 7zip)? |
|
Answer» I have tons of zip files, and I've been trying to recompress them into 7zip to get some disk space back and I wrote two batch files with for loops to first extract from .zip then when it finishes, it deletes all the zips and does the next for loop for the extracted files into 7zip like so: |
|