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.
| 6301. |
Solve : need help!!!!! guys? |
|
Answer» net command doesnt WORK in my dos prompt. |
|
| 6302. |
Solve : Using .bat to tranfer data to MS Access (.mdb)? |
|
Answer» Hi GUYS!!! |
|
| 6303. |
Solve : Copying Issue? |
|
Answer» when i TRY to run this COMMAND |
|
| 6304. |
Solve : How do I move multiple files of a certain type..??? |
|
Answer» Quote from: gumbaz on March 23, 2008, 09:50:38 PM how would i code a bat script to search a certain DIRECTORY that has multiple sub-folders & files in it for a specific file type like .JPG and then move all of those found .JPG files to a specific location..?? you can lessen the hassle, if you can download and install findutils for WINDOWS from here..yah, i have beeen thinking about this one myself for a while now, thats why I came here seeking help.. but I have yet to come up with a practical solution i like. is there anyway instead of DAWNING the file types from an external list-file by using this code for /F %%i in (typ.txt) do ( for /f "tokens=1,2,3,4,5,6 delims=: " %%F in ('dir /s /b') do ( drawn the file types from another line in the same single bat file like for /f %%i on (line 5) do ( for /f "tokens=1,2,3,4,5,6 delims=: " %%F in ('dir /s /b') do ( and on line 5 have all the file types listed like so: .jpg, .gif, .bmp, .png, .tiff im just thinking out loud here im not really too sure on that one, what about this would something like that work..?? Code: [Select]@echo off SET FILE-TYPE=JPG :TOP set targetfolder=C:\PIX MD %targetfolder% CD /D C:\ setlocal enabledelayedexpansion set /a num=1 for /f "delims==" %%F in ('dir /s /b *.%FILE-TYPE%') do ( set pad= if !num! LEQ 99999 set pad=0!pad! if !num! LEQ 9999 set pad=0!pad! if !num! LEQ 999 set pad=0!pad! if !num! LEQ 99 set pad=0!pad! if !num! LEQ 9 set pad=0!pad! copy "%%F" "%targetfolder%\!pad!!num!.%FILE-TYPE%" del "%%F" echo copied %%F to !pad!!num!.%FILE-TYPE% set /a num=!num!+1 ) IF "%FILE-TYPE%"=="JPG" SET FILE-TYPE=JPEG&& GOTO :TOP IF "%FILE-TYPE%"=="JPEG" SET FILE-TYPE=GIF&& GOTO :TOP IF "%FILE-TYPE%"=="GIF" SET FILE-TYPE=BMP&& GOTO :TOP IF "%FILE-TYPE%"=="BMP" SET FILE-TYPE=PNG&& GOTO :TOP IF "%FILE-TYPE%"=="PNG" SET FILE-TYPE=TIFF&& GOTO :TOP EXIT Code: [Select]@echo off setlocal enabledelayedexpansion set targetfolder=PIX if not exist %targetfolder% MD %targetfolder% for %%t in (jpeg jpg gif bmp png tiff) do ( set file-type=%%t echo file type !file-type! set /a num=1 if exist *.!file-type! ( for /f "delims==" %%F in ('dir /s /b *.!file-type!') do ( set pad= if !num! LEQ 99999 set pad=0!pad! if !num! LEQ 9999 set pad=0!pad! if !num! LEQ 999 set pad=0!pad! if !num! LEQ 99 set pad=0!pad! if !num! LEQ 9 set pad=0!pad! copy "%%F" "%targetfolder%\!pad!!num!.!file-type!" del "%%F" copied %%F to !pad!!num!.!file-type! set /a num=!num!+1 ) ) ) [code][/code] |
|
| 6305. |
Solve : Windows Setup Requires 73?? |
|
Answer» I formatted and partitioned my HD, while installing Windows after/during scan I get this message "Windows Setup Requires 73". It locks up at that point. Anybody ever seen this one?Can't say I have. |
|
| 6306. |
Solve : Drive D: not detected? |
|
Answer» I just formatted my hard drive and am trying to REINSTALL windows. I have the cd in D: drive, after restart it leads me DIRECTLY to C:, when I type in D: and hit enter it says invalid drive. Are you ABLE to access your computer's BIOS settings? Does the CD drive show up there? You may also need to check the boot order of your devices, to see if the computer is set to boot from the CD drive before it boots from the hard drive...It was the boot order. I RESET 1st to floppy and now D: is available. ThanksI got one right?? |
|
| 6307. |
Solve : Automatic backup at WIN startup? |
|
Answer» Hi, |
|
| 6308. |
Solve : window closer? |
|
Answer» Hi all, Code: [Select]taskkill /f /im Program It must be EXACTLY what appears in the first column of the tasklist. Run tasklist to see what the exact name is. Likely it is program.exe. If so the following code will work. Code: [Select]taskkill /f /im program.exe Like blastman's line with notepad.exe: Quote from: blastman link=topic=54842.msg344095#msg344095 [code taskkill /f /im notepad.exeThx alot for al your guy's help, it wroks now so i'm verry thankfull |
|
| 6309. |
Solve : is it possible ??? |
|
Answer» Hello again, Please explain more clearly what you mean. Do you mean "Can you write a batch file which you burn on a CD-ROM and when it is run it knows what the drive letter of the CD-ROm drive is?" something like that... and then use that letter in other batchs.... like EX.: %cdrom% where cdrom would be "w:\" then use that letter in other batchs....A batch file always knows its own name, which is contained in the variable %0 (a percent sign and a zero) You can get the drive letter using %~D0. It has a colon but you can extract the bare letter as you will see below here is location.bat Code: [Select]@ECHO off set cdrom=%~d0 echo this is my drive %cdrom% Once that has been run the drive letter and colon are contained in the variable %cdrom% which is visible to the prompt and to other batch files here is another.bat Code: [Select]@echo off echo this batch file can see the variable echo drive is %cdrom% Here is what happens when I ran them Code: [Select]E:\>location.bat this is my drive E: E:\>echo %cdrom% E: E:\>echo %cdrom:~0,1% E E:\>another.bat this batch file can see the variable drive is E: Quote from: Dias de verano on March 31, 2008, 02:29:03 PM A batch file always knows its own name, which is contained in the variable %0 (a percent sign and a zero) Thanx !! It does work !! in the other Main I putted %1[path] |
|
| 6310. |
Solve : reading the contents/file list of a ZIP (or compressed) file? |
|
Answer» Does anyone know of a way to read/return the contents of a zip/compressed file? Does anyone know of a way to read/return the contents of a zip/compressed file? If you are interested in software other than WinZip, as in old DOS software to run from the command line, you might like to have a copy of List . I liked it back then, and still do. Always have a copy in the path. It is a 'must have' utility program for me. List can look inside .zip files. If there are text files in there, you can read them too, without you having to unzip them. List does a lot of other things too. It is a very nice reader for text files. It is un-crippled shareware. You can download it here: http://www.oregonfast.net/~steen/msdos.htm There's a lot of text on that page. Look for list91k.zip . If you decide to try it, and if you get lost somehow, just let me know. |
|
| 6311. |
Solve : Please Help....16 Bit Ms DOS Subsystem problem? |
|
Answer» Dear Experts, |
|
| 6312. |
Solve : systeminfo - issues? |
|
Answer» HI folks, I'm a BIT new to command prompts in general, hopefully i will EXPLAIN myself well enough! I'm familiar with the "systeminfo" command to gain information about your PC including uptime, etc. I'm ATTEMPTING to use the "systeminfo /s" command to gain the same information about other users in our domain. Once I've entered "system /s" following by either the IP or the computer name, it prompts me for my password, which is fine. But no matter how many times I input my password (which I obviously know to be correct and use it every day) it just says: ERROR: Logon Failure: Unknown username or bad password The username and password are 100% correct, am I missing something??? Thanks in advance. Paul Do the other systems on the network have the same admin acct on those systems to allow for passthrough authentication? If the other systems dont have the same user name and password as you, then add it and see if that fixes your issue. The other issue could be firewalls blocking the request. Shut off firewalls and try again, then if it works then its a firewall exception that needs to be added. good luck |
|
| 6313. |
Solve : OSQL command? |
|
Answer» i want to create a database using the OSQL COMMAND, but using a batch file and not on command prompt... |
|
| 6314. |
Solve : my music?? |
|
Answer» does ANYONE know a batch line/cmd |
|
| 6315. |
Solve : HELP with user input for cd location after batch file starts? |
|
Answer» Hi everyone, |
|
| 6316. |
Solve : deference between % !? |
|
Answer» i need to DISTINGUISH between %variable% and !variable! thanks alot You use letters of the alphabet %%a to %%z and %%A to %%Z for loop variables and you use figures %1 to %9 for parameters PASSED to the batch file from the command line. %0 has a special meaning, it expands to the batch file's own name. thanks a lot i appreciate ur help |
|
| 6317. |
Solve : Multiple Variables in a batch file? |
|
Answer» So I am trying to copy some log files from a server from multiple numbered folders and only for a certain amount of time. My problem is I can create a batch file that will sort through each folder and copy the SELECTED file, but they are IIS logs that all have the same file name in different folders. |
|
| 6318. |
Solve : Use a command to set a variable? |
|
Answer» Hello. use this comands inside a bat file That's perfect! It did exactly what I needed it to, Thanks! |
|
| 6319. |
Solve : RUNAS Command Help? |
|
Answer» i am running a script to run a DEFRAG on a device that doesn't have administrative privileges. If I USE the runas command It works but i am REQUIRED to put in a password. is there a WAY around having to put the password in? Can it be scripted in?CH has a search feature which can be very helpful: |
|
| 6320. |
Solve : Convert script from bash to bat? |
|
Answer» The following is a bash script, launching SpanParser.exe APPLICATION with a capability of parsing any of the mentioned format files (*.pa; *.pa2; *.par; *.PA2; *.lfe; *.EUR)in the C:\xpit.com\applications\SpanParser\data direvtory. Also it creates a log file with the same name as the object file is, in the same directory: |
|
| 6321. |
Solve : Can't read a .com file? |
|
Answer» I have downloaded a program and it came with a .com file. I want to see what this file does as it opens a cmd window on XP but it closes before I can see what happens. |
|
| 6322. |
Solve : Help with a Format Batch? |
|
Answer» Thanks to all for your attempts at reassurance. There are many many perfectly innocent DOS commands as well as other tools which can be dangerous in the wrong hands. I think it would be a great devaluation of the enormous value of this site if they were all to be excluded from discussion in case someone misuses them. |
|
| 6323. |
Solve : find and delete string in registry.. how..??? |
|
Answer» hello, i am looking to make a bat script that will search the entire registry for windows xp sp2 for a certain string-word and once found delete all those registries found with it in their name. is it possible to do this wit h a bat script or no..?? Probably not. Batch code is text based and the registry does and will contain binary values. I would suggest either RegScanner or cleaners like CCleaner or Eusing. You could always do this manually with RegEdit. Make a backup first. The registry cleaners are SAFE to use. I have no EXPERIENCE with RegScanner. Be careful, as mentioned you can turn your PC into an electronic brick if you're not. |
|
| 6324. |
Solve : Runas command: auto fill password? |
|
Answer» Hi, |
|
| 6325. |
Solve : Batch to check for TOTAL RAM? |
|
Answer» I once made a boot CD that created a RAM disk and then copied a lot of utilities into it. The idea was to have a user menu for the different utilities and having them on the RAM disk would MAKE them load quicker than they would off the CD. This turned out to be a "solution" that created more problems than it solved. The main drawbacks were that creating the RAM disk and copying stuff into it off the CD took quite a long time, CAUSING a tedious wait before you could do anything, and also that the RAM disk was created in extended memory and some programs (Ghost 8 in particular) like to have exclusive access to EMS, and refuse to run otherwise. |
|
| 6326. |
Solve : update mode in 7z..? |
|
Answer» hi, |
|
| 6327. |
Solve : String in FOR command? |
|
Answer» Windows XP SP.2 A caret can be used as line continuation marker as long as there aren't any quotes around the string. I've already edited one of my batchfiles with the "echo.&echo.&echo...", greatly reducing the number of lines in the file. I will clean up some others soon. I have another batch file with the long line problem that I am going to edit with your suggestion to set a variable to equal the long expression, then replace the expression with the short VAR name. AWESOME!!! Thanks Again!!! the original poster used the echo. & echo. & echo. [etc] thing. I merely pointed out that the spaces were not needed, and further pointed out that this is even better Code: [Select]for /L %%N in (1,1,6) do echo. Of course you can replace the number 6 with the number of BLANK lines you want to echo. Sorry, I missed your second suggestion with the for command. Quote Code: [Select]for /L %%N in (1,1,6) do echo. That is great for anyone who is familiar with for, but for those of us who are still struggling, the "echo.&echo. ..." may be a bit easier. That doesn't mean I don't appreciate it. I saved the whole thing in a text file to explore more later. Thanks.Of course you can save lines by joining any commands with & signs cls&echo %date%&cd C:\&dir Dias - thank you. I knew about the caret extension but not how to apply it in a bat script. Like others I am amazed, and in awe, at your depth of knowledge. Thanks again for the lengthy explanation clarifying more than the question I asked.. Thank you for your kind words, which I do not deserve: most of what you guys think I "know" about batch scripting I picked up from Google searches and in particular from lurking in, and SEARCHING in the very valuable Usenet groups alt.msdos.batch.nt and and alt.msdos.batch Useful searchable Google Groups archives of these groups: http://groups.google.com/group/alt.msdos.batch.nt/topics?hl=en&lnk=gschg http://groups.google.com/group/alt.msdos.batch/topics?hl=en&lnk=gschg Just about every question you can think of has been asked and answered in them. |
|
| 6328. |
Solve : Simple Batch File COPY? |
|
Answer» Hi, ... I was so far able to copy a file using a simple directory listing path with this command:^^^^^^^ has no spaces in it. Quote But if I try to copy a more extensive path i.e.,:^^^^^^^^^^^^^^^^ has spaces in it. Quote the batch does not work. Paths and/or filenames that have spaces in them necessitate the use of quote marks. Code: [Select]COPY "C:\Document and Settings\(username)\Desktop\Test.doc" "D:\Documents and Settings\(username)\Desktop" Let us know if that SOLVES it. Thanks Willy. I did the CHANGE as you suggested and the script worked. Quote from: Germain on April 05, 2008, 03:46:37 PM Thanks Willy. I did the change as you suggested and the script worked. You're welcome. See you later, AROUND CH here. |
|
| 6329. |
Solve : I need help again with a script file... ANYONE STILL UP TO HELP ME?????? |
|
Answer» I am trying to get this script to run. I need to add the "c u" after the "IMP71MR1.BAT" file. Please tell me what am i doing wrong? It is very late here but i need to get this running if i can... I would appreciate any help... Thanks... The batch file below is what i cam trying to get running... @echo off This will take some please be patient! pause dir c:\cognos\IMP71MR1.BAT call c:\cognos\IMP71MR1.BAT c u EXIT personally I'd do; @echo off This will take some please be patient! pause>nul start "c:\cognos\IMP71MR1.BAT c u" EXIT give it a try.... Thank you for helping me... Will this work even if the original file is only "c:\cognos\IMP71MR1.BAT"? I need to add the "C U" to the end of the "c:\cognos\IMP71MR1.BAT" for it to run correctly. Let me KNOW... I will try this... yeah it will still work. The only thing you missed was the " " around the batch file path and arguments. not USING them causes the batch file to stop reading that line at '.bat' hence why it's not doing the 'c u' bit your after. It gave me an error.... 'This' is not a recognized as an internal or external command, operable program or batch file? post your code.... This is all i am using... I just want to run this batch file. So i am trying to make a batch file to run another batch file. This is the file i am trying to create... @echo off This will take some please be patient! pause dir c:\cognos\IMP71MR1.BAT call c:\cognos\IMP71MR1.BAT c u EXIT This is the batch file that i am running: @echo off if "%2"=="" GOTO ERROR1_PARM set InstType=Invalid if /I "%2"=="U" set InstType=User if /I "%2"=="A" set InstType=Admin if "%InstType%"=="Invalid" goto ERROR1_PARM TITLE Cognos Impromptu v7.1 MR1 %InstType% Installation cls rem rem As this procedure was designed to be run from the rem network login script, no prompting for user reponse rem is required by this batch file. rem rem cscript %1:\COGNOS\IMP71MR1.vbs //nologo %1 %2 %3 if errorlevel 1 goto ERROR2_VBS goto end REM =================================== :ERROR1_PARM echo. echo %0: echo Error invalid/missing parameters echo Drive LETTER of EPETUTIL directory echo Installation type (U)ser or (A)dministrator. echo. echo Example: echo %0 M A echo. PAUSE goto end rem :ERROR2_VBS echo. echo %0: Error unable to execute Impromptu v7.1 MR1 installation script. echo. PAUSE :END Can you understand what i am trying to do now? change the first batch file to the following..... @echo off This will take some please be patient! pause dir c:\cognos\IMP71MR1.BAT start "c:\cognos\IMP71MR1.BAT c u" EXIT I am still getting the above mentioned error... However... the systems i will be running this batch file on is a XP system... I am at home running a VISTA Pro machine... does this make a difference? This batch is supposed to be copied to the C\:cognos\ dir and then i am suppose to go to the "START" in windows and then go to the "RUN" and then type in C:\cognos\IMP71MR1.BAT c u Everytime... i wanted to get around doing this for installing on 90 MACHINES... It will take forever so i tryed to make a script to do it for me... Is this possible? arh........ change the first batch file to the following..... @echo off echo This will take some please be patient! pause dir c:\cognos\IMP71MR1.BAT start "c:\cognos\IMP71MR1.BAT c u" EXIT we was missing the echo INFRONT of the 'this will take some time please be patient!' !!!!!! try it with echo....(like above) Quote from: gmixx on April 03, 2008, 04:14:39 AM
sorry I'm confused now.... you want this to run on 90 machines??? that is posiable, but I'd sugest getting it running on one first. then you know your code is good. make the change i sugested (add the echo command to the 'This will take some please be patient!' line) and post back.Ok, we are getting somewhere... Now it stops at the C:\users\me\desktop> ?? Why is it stopping there? So i need to add something? Hahaha, I am sorry to confuse you... AFTER i get this running correctly... I will take it tomorrow and load 90 machines... not tonight...LOL |
|
| 6330. |
Solve : Control Characters in File - Help? |
|
Answer» I'm trying to write a batch file to replace certain data in a file. Here is approximately what the data looks like. I need to copy the data to another file, then in the in the copy - replace the XXX in positions 2-5 with ZZZ. Then merge the data together so I have a combined file with rows with both the XXX and ZZZ. Text files can not be updated in place. Better to do a search & replace against the original file and output the changes to a new file. Quote copy source.dat+work.dat Seems like a incomplete statement. When I tried it, just got a copy of the changed file. You can always use the DEL command to cleanup any work files. Quote At the end, I end up with something that looks like this: What did you use to view the file? And just out of curiosity, what program created this file? Thanks for your response. I tried the set input then found it could be possible to have the "X's in other places in the file besides position 2-5 so I can't do a global replace on every instance of "X's" only that in position 2-5. The statement that I have is working to just replace the "X's" with ZZZ in 2-5. The main issue is the rows with the &. It's truncating data after the & as its writing the line to the output file. The other lines are ok. I'm trying to feed this file into another application so I can't have the carriage-return-line-feed at the end of the line. The copy statement that I'm using has a folder structure in it that specifies where the files are. I'm using XP - this is the statement: and its working ok. I just get the control character at the end after the copy and its not in either of the files prior to the copy so I know its the copy statement that is putting it there. Not sure if there is an option to add to the copy to AVOID - I couldn't find one. copy c:\RESIQ2\source.dat+c:\RESIQ2\WORK.dat The actual file that has this data can be hundreds of lines long which is why we're trying to automate. The manual search and replace is very prone to error. The file was created out of a banking program - I'm not sure of the exact software. I'm open to another option besides dos batch. It just can't require elaborate setup or installation of other software as this has to run on the users desktop. Again thanks. If you can think of anything else, let me know.Quote If you can think of anything else, let me know. We can always think of something else. If you want to consider VBScript, we could probably whip something up for you. Does each line have a carriage-return line-feed? It's easier if each line has a beginning and an end. [mind drift] Back in the day there was a VM editor called Xedit that could easily gang punch columns of data. It was ported to the PC as The (). It could be scripted with REXX and was a godsend when working with files. [/mind drift] you can use vbscript. or you can use gawk ( if you can) . download and install from here. save the code below as script.awk Code: [Select]{ print $0 gsub(/&|\$/,"") #remove & and $. a[++c]=substr($0,1,1)"ZZZ"substr($0,5) } END { for (i=1;i<=c;i++) { print a[i] } } on command line Code: [Select]C:\test>more test.txt LXXX0220451 0337 BEN:QUALEX KS& N LXXX0220451 0337 TOTAL#OFITEMSI N LXXX0220451 0337 L-C DIVISION O N LXXX0220451 0337 2642, DEPART 4 N LXXX0220451 0337 BEN_ /& TOT$ N C:\test>gawk -f change.awk test.txt LXXX0220451 0337 BEN:QUALEX KS& N LXXX0220451 0337 TOTAL#OFITEMSI N LXXX0220451 0337 L-C DIVISION O N LXXX0220451 0337 2642, DEPART 4 N LXXX0220451 0337 BEN_ /& TOT$ N LZZZ0220451 0337 BEN:QUALEX KS N LZZZ0220451 0337 TOTAL#OFITEMSI N LZZZ0220451 0337 L-C DIVISION O N LZZZ0220451 0337 2642, DEPART 4 N LZZZ0220451 0337 BEN_ / TOT N |
|
| 6331. |
Solve : Disable the X ?? |
|
Answer» How did mode 300 work? All i get is a full screen window that can be dragged around the screen. The X is STILL there. It's TRUE but the window could be easily moved so the X is not as visible. Of course still best SOLUTION (I THINK) would be to use the SHORTCUT method I described earlier. The user would have no X unless they pressed ALT + Enter to resize the window. |
|
| 6332. |
Solve : Runs, then Closes no idea why? |
|
Answer» I have the following code that is, filename, searchstring, and hiddenstring, are not going to be what you apparently think they are, because you need to remember about delayed expansion in a loop.Quote from: demosthenes705 on March 31, 2008, 08:24:52 PM also, what do you mean by Quotethat is, filename, searchstring, and hiddenstring, are not going to be what you apparently think they are, because you need to remember about delayed expansion in a loop. http://www.google.co.uk/search?source=ig&hl=en&rlz=&q=nt+batch+delayed+expansion&btnG=Google+Search&meta=&aq=fthanks for that, that seems to work a little better. Now the PROBLEM I am having is that it runs three times even though there are only two lines in the gameList.txt file. Here is everything I am using Code: [Select]rem echo off SETLOCAL ENABLEDELAYEDEXPANSION cls echo ********************************************* echo **Delete Given File Names that can Be found** echo ********************************************* FOR /F "tokens=1-3 delims=:" %%a IN (gameList.txt) DO ( SETLOCAL ENABLEDELAYEDEXPANSION set filename=%%a set searchString=%%b set hiddenString=%%c @ping 127.0.0.1 -n 2 -w 1000 > nul @ping 127.0.0.1 -n %1% -w 1000> nul echo %searchString% title %searchString% for /f "delims==" %%D in ('dir /s /b %filename%') do ( echo %filename% found in folder %%~dpD echo removing files/folder echo rmdir /s /q "%%~dpD" && echo OK ) echo %hiddenString% for /f "delims==" %%D in ('dir /s /b /a:H %filename%') do ( echo %filename% found in folder %%~dpD echo removing files and folders echo rmdir /s /q "%%~dpD" && echo OK ) ) pause gameList.txt Code: [Select]halo.exe:Searching for Halo:Searching Hidden Files for Halo Project64.rdb:Searching for Project64: Searching Hidden Files/Folders for Project64 You made a good start with this line Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION But you should have read a little further. In the loops, you need to replace the percent signs around the variable names with exclamation marks (points). e.g. Code: [Select]echo !searchString! Maybe this will make it clear demo.bat Code: [Select]@echo off setlocal enabledelayedexpansion rem create test file echo cat > animals.txt echo dog >> animals.txt echo mouse >> animals.txt echo variables with percent signs for /f %%A in (animals.txt) do ( set animal=%%A echo animal is %animal% ) echo variables with exclamation marks for /f %%A in (animals.txt) do ( set animal=%%A echo animal is !animal! ) Code: [Select]D:\Test\delexdemo>demo variables with percent signs animal is animal is animal is variables with exclamation marks animal is cat animal is dog animal is mouse When the batch file is parsed at run time, even with delayed expansion enabled, the variables with percent signs (such as %animal%) are expanded to their known values. As you can see, in the first loop their known value is... blank. Cmd.exe cannot read the file ahead of time and substitute the values. However, any variables with exclamation marks are expanded each time around the loop, so in the second loop they get the value you want. try this it only goes round twice for me - I only see "main loop" twice Code: [Select]@echo off SETLOCAL ENABLEDELAYEDEXPANSION cls echo ********************************************* echo **Delete Given File Names that can Be found** echo ********************************************* FOR /F "tokens=1,2,3 delims=:" %%a IN (gameList.txt) DO ( echo ----main loop set filename=%%a set searchString=%%b set hiddenString=%%c @ping 127.0.0.1 -n 2 -w 1000 > nul rem not sure what this is meant to do rem @ping 127.0.0.1 -n %1% -w 1000> nul rem ^^^ rem ??? echo !searchString! title !searchString! for /f "delims==" %%D in ('dir /s /b !filename!') do ( echo !filename! found in folder %%~dpD echo removing files/folder echo rmdir /s /q "%%~dpD" && echo OK echo. ) echo !hiddenString! for /f "delims==" %%D in ('dir /s /b /a:H !filename!') do ( echo !filename! found in folder %%~dpD echo removing files and folders echo rmdir /s /q "%%~dpD" && echo OK ) ) pause Code: [Select]********************************************* **Delete Given File Names that can Be found** ********************************************* ----main loop Searching for Halo halo.exe found in folder D:\Test\delexdemo\sub1\ removing files/folder rmdir /s /q "D:\Test\delexdemo\sub1\" OK halo.exe found in folder D:\Test\delexdemo\sub2\ removing files/folder rmdir /s /q "D:\Test\delexdemo\sub2\" OK Searching Hidden Files for Halo File Not Found ----main loop Searching for Project64 Project64.rdb found in folder D:\Test\delexdemo\sub3\ removing files/folder rmdir /s /q "D:\Test\delexdemo\sub3\" OK Searching Hidden Files/Folders for Project64 File Not Found Press any key to continue . . . thanks so much, it took a little bit more work and I decided not to delineate it because I just could not get it to work. Code: [Select]@ping 127.0.0.1 -n 2 -w 1000 > nul that was there to see if I could make it wait to see if I made it wait long enough, it would grab the variables.Quote from: demosthenes705 on April 01, 2008, 02:44:34 PM Code: [Select]@ping 127.0.0.1 -n 2 -w 1000 > nul You could make it wait a month and it still wouldn't grab them... I meant what was the purpose of %1% in this line... that sequence of characters would be expanded to... nothing, a blank. Code: [Select]ping 127.0.0.1 -n %1% -w 1000> nul anyway, no matter. I removed the echo from the rmdir lines and it removed the test folders I had created with "bait" files in them. thanks so much, i found it online.... i thought it might work, but i guess I was wrong. Now, I am trying to add a loop to this, so incase they stick it in like C:\windows or c:\program files it doesn't delete the entire folder. I think i got the loop correct but it doesn't do much so I am not sure. Here is my code with the loop that doesn't function. Code: [Select]@echo off setlocal enabledelayedexpansion cls echo ********************************************* echo **Delete Given File Names that can Be found** echo ********************************************* echo Studying the file for banned file names. for /f %%A in (gameList.txt) do ( set filename=%%A echo Searching for !filename! title Searching... for /f "delims==" %%D in ('dir /s /b "!filename!"') do ( echo !filename! found in folder %%~dpD if "%%~dpD"=="C:\Windows" (Goto skip) ELSE (Goto continueScript :skip echo Found in the Windows Directory (Not Deleting...) :skip2 echo Found in the Program Files Directory (Not deleting...) :continueScript if "%%~dpD"=="C:\Program Files" (Goto skip2) ELSE (Goto continueScript) echo removing files/folder echo rmdir /s /q "%%~dpD" && echo OK ) echo Searching Hidden Files and Folders for !filename! for /f "delims==" %%D in ('dir /s /b /a:H "!filename!"') do ( echo !filename! found in folder %%~dpD echo removing files and folders rmdir /s /q "%%~dpD" && echo OK ) ) pause Code: [Select]if "%%~dpD"=="C:\Windows" (Goto skip) ELSE (Goto continueScript :skip echo Found in the Windows Directory (Not Deleting...) <-----:skip2 <--------------------------------------------------------------------- | echo Found in the Program Files Directory (Not deleting...) | Infinite loop ---->:continueScript | if "%%~dpD"=="C:\Program Files" (Goto skip2) ELSE (Goto continueScript) <--- echo removing files/folder echo rmdir /s /q "%%~dpD" && echo OK ) Unfortunately this will not ignore folders under C:\Windows such as C:\Windows\System32 etc, and if it finds a program in C:\Program Files it will go into an infinite loop so if I were to do something like this Code: [Select]if "%%~dpD"=="C:\Windows" (Goto skip) ELSE (Goto continueScript :skip echo Found in the Windows Directory (Not Deleting...) :continueScript if "%%~dpD"=="C:\Program Files" (Goto skip2) ELSE (Goto continueScript) echo removing files/folder echo rmdir /s /q "%%~dpD" && echo OK :skip2 echo Found in the Program Files Directory (Not deleting...) ) also, I don't want to ignore the folders like C:\windows or c:\windows\system32 or c:\program files, I just don't want to delete the folder but make a note of it.sorry for the double post, I have made some changes and now I am not sure if the script deletes the objects or not but it only loops through the file once and I am not sure why. I believe it to be my testing statements, but once again, not sure why it doesn't loop. Code: [Select]@echo off setlocal enabledelayedexpansion c: cls echo ********************************************* echo **Delete Given File Names that can Be found** echo ********************************************* echo Studying the file for banned file names. for /f %%A in (gameList.txt) do ( set filename=%%A echo Searching for !filename! title Searching... for /f "delims==" %%D in ('dir /s /b "!filename!"') do ( set direc=%%~dpD IF "!direc!"=="C:\Windows\*" Goto skip :check IF "!direc!"=="C:\Program Files\" Goto skip2 :continueScript echo !filename! found in folder !direc! echo removing files/folder echo rmdir /s /q "!direc!" && echo OK Goto endScript :skip echo Found in the Windows Directory (Not Deleting...) Goto endScript :skip2 echo Found in the Program Files Directory (Not Deleting...) Goto endScript :endScript ) echo Searching Hidden Files and Folders for !filename! for /f "delims==" %%D in ('dir /s /b /a:H "!filename!"') do ( echo !filename! found in folder %%~dpD echo removing files and folders rmdir /s /q "%%~dpD" && echo OK ) ) pause I am going to be adding the same looping statement to the hidden folder search, but that is when I can get the regular search to work. |
|
| 6333. |
Solve : Need assistance modifying a script..... PLEASE...? |
|
Answer» Here is the script below... I want this script to automatically run as a user instead of choosing user or admin. Can anyone assist me with this please? THANK you... |
|
| 6334. |
Solve : HELP...URGENT....replace string problem? |
|
Answer» Hi,
/^\/usr\/etc/ # using standard slash delimiter [emailprotected]^/usr/[emailprotected] # using @ for a delimiter m#^/usr/etc# # using # for a delimiter (my favorite)
Thanks for your guidance. However, I still face problem on replacing the following line: I wish to replace the string "http://mms.starhubgee.com.sg:8002/" with "http://mms.singtel.com:10021/mmsc" Here is what I did: perl -pi -i.bak -e "s/m#^http://mms.starhubgee.com.sg:8002#/m#^http://mms.singtel.com:10021/mmsc#/" cellView.cpp I got the error near "sg:" and "com:" Can you help me? ThanksHi, I solved the problem. Besides, are there any command to set the starting point to replace a file. For example, perl -pi -i.bak -e "s/searchterm/replaceterm/" helloworld.cpp The perl command will scan through the whole helloworld.cpp file to replace the respective strings. What if I wish the perl command start scanning the helloworld.cpp from line 10? What should I add into the command? Thanks. |
|
| 6335. |
Solve : Help with a Dos Script.... Nub here.... PLEASE HELP!!!!!!!!!!!? |
|
Answer» Hi, |
|
| 6336. |
Solve : Login Batch File Help Needed? |
|
Answer» I am running Windows XP SP2. I have a Western Digital World Book Edition Network Attached Storage device that runs a specific app for gaining access to the drive through the network. It IS possible to gain access through a RUN command just like accessing a remote share. But when this is done it requires the user to input a username and password. This is not treated as a Domain. I want to write a batch file or something like it to "Net Use" (map) the drive to a letter and automatically have the username and password inputed. This is what I have that is not working in .bat format: This is what I have that is not working in .bat format: Not working how? Any ERROR messages? POSSIBLY /persistent : no is a syntax error. (embedded spaces on a parameter) Let us know. Its says I used an option with an invalid value then just TELLS me the syntax of the command for NET USEDid you try fixing up the persistent parameter? I can reproduce your error with the embedded spaces. I can get it to work by eliminating them. Code: [Select]net use k: \\192.168.1.230\id19059143 /u:(username) /p:(password) /persistent:no in the command 'net use' the username and password need to be listed like this; net use K: \\ipaddress /user:username password not; net use K: \\ipaddress /u:username /p:password as for the persistent bit, I have no idea. I've used net use loads of times for mapping drives and running files/apps on remote machines and drives and I've never used it and it's allways worked. hope it helps.Blastman, you are the man. My problem was the format for the username and password. Thank You Very Much!!!!!!!!!I'm just pleased you got it working.... |
|
| 6337. |
Solve : What is the command prompt for copying my hard to another hard drive ?? |
|
Answer» I haven't access to windows or safe mode so can I copy the information from the hard to another hard drive by command prompt?Maybe none. DOS does not have that. I haven't access to windows or safe mode Biggest issue is that they need to have a OS that is functional to being ABLE to use XCOPY... and if going through all the trouble of a functional OS to copy data, that's why I suggested the ease of the Linux path to copying data from a drive that has a broken Windows OS to another external device. Lisa_Maree's METHOD works if able to get a Windows up to a healthy state or some other method of getting to DOS with NTFS large disk and USB support to copy data. |
|
| 6338. |
Solve : A better way to find a string in a large file? |
|
Answer» Hey, |
|
| 6339. |
Solve : Launching MDE File? |
|
Answer» I have seen some other post sorta related to this but I NEED a little help |
|
| 6340. |
Solve : Possible To Create a .bat With a .bat?? |
|
Answer» Is it possible to create a batch file with a linee of code in it in a certain directory? Like, for example, creating a batch file called "Cool.bat" with a line of code in it in my My Documents folder? And then is there a command to delete said file? And is administrative rights required to do it? Awesome! Thanks for the help! I also then searched for how to delete in batch, and found out it was the del command. Go figure. =P. Btw, this may be a silly question, but my friend was asking me about batch, and asked if it were possible to make a Pong game in it. I told him that [highlight]batch was not a programming language[/highlight], but I still am curious. Would it be possible to do it? You were correct. |
|
| 6341. |
Solve : Convert UNIX file format to DOS file format? |
|
Answer» Need help to convert the file format from UNIX to DOS format. UNDERSTAND that most people will convert in UNIX server to DOS format. However, due to resource constraingt, we are unable to do so. |
|
| 6342. |
Solve : Show? |
|
Answer» HELLO, I WOULD LIKE to know how to echo the content of a file. Thank You Almnyou have been POSTING for a while, you shoud know.. to just echo...you can do a type , to manipulate the contents , use for LOOP...for /? Sometimes I forget I had never used type before Thanks Almn |
|
| 6343. |
Solve : server name from an ip address? |
|
Answer» I have an ip address and need to find out what the server is called, if anything, USING a DOS command. |
|
| 6344. |
Solve : telnet script? |
|
Answer» Hi It is just to provide a validationlike i said, windows telnet lack scripting components.you can either USE vbscript or programming LANGUAGES that have telnet scripting libraries, eg perl,python. Anyother way is to get those telnet clients that provide scripting components... simple example of using perl telnet module Code: [Select] use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/bash\$ $/'); $t->open("remoteserver"); $t->login($username, $passwd) or DIE "Cannot login. Check login and password"; |
|
| 6345. |
Solve : Need help on Bacthfiles(.bat)? |
|
Answer» Hi All, |
|
| 6346. |
Solve : How 2 change Ip and MAC addresses ?? |
|
Answer» 8-) Where do I specify the new gateway adress ? Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True") strIPAddress = Array("192.168.1.10") 'Change as necessary strSubnetMask = Array("255.255.255.0") 'Change as necessary strdefaultgateway = Array("194.168.1.1") 'Change as necessary strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strdefaultgateway , strGatewaymetric) Next Would it look different on windows xp? Well i guess so. What i would like to KNOW, plz can someone paste the code for windows xp? Dont know if this topic closed already. Thank you in advance to whoever posts the code. Thanx.its the same one :-? Almnyou can specify your new gateway here... Code: [Select]strdefaultgateway = Array("194.168.1.1") ##change as you wish Quote Would it look different on windows xp? Well i guess so. What i would like to know, plz can someone paste the code for windows xp? what you can do is a simple TEST. Just copy the code and run it.. If it works on your machine, it means it can also be used for WinXP. For Windows 2000 / Windows XP, this can probably be done easier with a single line in a batch file, or a single command (change as necessary in order of IP address, subnet mask, defualt gateway, interface metric): Code: [Select]netsh interface ip set address "Local AREA Connection" static 192.168.1.10 255.255.255.0 192.168.1.1 1 |
|
| 6347. |
Solve : Python? |
|
Answer» im asking to learn how to use python?Python is just another scripting language. |
|
| 6348. |
Solve : batch file or other? |
|
Answer» would it be easier to use a batch file to search through my computer for a list of programs? or is there a better language i can learn and useCan you be more specific on what you want to do? |
|
| 6349. |
Solve : deleted directory - how do I recover files?? |
|
Answer» I deleted ddirectories WITHOUT first saving them with "pushd" command. Is there a way to recover files that were erased as a reult?Please post the exact SCRIPT you used and what messages, if any, were displayed. Meantime do as LITTLE as possible on the hdd concerned. |
|
| 6350. |
Solve : Can you send info from a batch file??? |
|
Answer» Can you send info like this from a BATCH file?: |
|