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.
| 4751. |
Solve : update command prompt? |
|
Answer» I want to know if you can update command PROMPT and if you can how to do so. update command prompt?Exactly what I was going to ask. How/why are you doing this? What could this possibly accomplish? What possible additions would you add to the command prompt? Can you accomplish this without modifying the prompt?Quote from: batchmaster60 on June 08, 2009, 04:16:11 PM I want to know if you can update command prompt and if you can how to do so.if what you mean is you want to see more features and CAPABILITIES of cmd.exe, then no, i suggest you use a good programming/scripting language. Otherwise, i don't really think M$ would update. Or else you can switch to powershell...considered and "update" to me... C:\>prompt /? Changes the cmd.exe command prompt. PROMPT [text] text Specifies a new command prompt. Prompt can be made up of normal characters and the following special codes: $A & (Ampersand) $B | (pipe) $C ( (Left parenthesis) $D Current date $E Escape code (ASCII code 27) $F ) (Right parenthesis) $G > (greater-than sign) $H Backspace (erases previous character) $L < (less-than sign) $N Current drive $P Current drive and path $Q = (equal sign) $S (space) $T Current time $V Windows XP version number $_ Carriage return and linefeed $$ $ (dollar sign) If Command Extensions are enabled the PROMPT command supports the following additional formatting characters: $+ zero or more plus sign (+) characters depending upon the depth of the PUSHD directory STACK, one character for each level pushed. $M Displays the remote name associated with the current drive letter or the empty string if current drive is not a network drive. C:\>prompt $$ $prompt $T$G 21:15:18.56>prompt $P$G C:\>thank you for all of your HELP |
|
| 4752. |
Solve : Hidden Directory? |
|
Answer» I'm trying to remove a folder, and whenever I try to from windows everything crashes. Its not a system folder so I'm guessing a virus is inside and is trying to protect itself, because of this I'm now trying to use the dos prompt to remove it. When I type "rd messenger" it tells me that the folder isn't empty so it can't, having looked inside and not seen anything I'm guessing that a hidden folder is the problem. Does anyone know how I can remove a hidden folder without knowing its name? I've tried "attrib -h -s /s" on the advice of a friend but it doesn't work for some reason...What is the full path to the folder, how did it get created, and what does it contain? I did try attrib -h -r -s /s *.* earlier, it didn't do anything though You did not include the *.* in your earlier post. Good point, I'll try that next time I have trouble. Thanks again for all the help There is most likely a virus in that folder. Quote from: qinghao on August 17, 2008, 03:48:34 PM There is most likely a virus in that folder.Or it doesn't exist........ |
|
| 4753. |
Solve : Cut a text file after N specific strings found? |
|
Answer» Hi, |
|
| 4754. |
Solve : search for files with special (names size and modified date)? |
|
Answer» wow ! at last i done it. i am now one step closer to the target @echo off in above script you can now put lots of files and program will check their size (i put 2 files) but now i need a pattern for compare and CHECKING files date with my values any help or idea? thanks use %%~tAsorry dear devcom i forgot to tell you i tried your codes yesterday but maybe it's me that has problem not codes !! i tried this for /f "tokens=*" %%A in ('dir /b /A-D *.exe') do ( echo %%A %%~zA %%~tA ) now i have this report in CMD window Quote java2.exe 275238 02/03/2008 11:50 AM now what? how should i put these codes inside program? i tried this (i removed file's size this time to find out what's the problem) Quote @echo off i added red line to see which line has picked by program and always red line is selected !! what's the correct pattern for putting file's date? i even tried all below codes Quote 02/03/2008 11:50 what's wrong?you need to add QOUTES on var and string you want to match becouse cmd thinks that 11:50 and AM are some commands so: Code: [Select]if "%var1%" NEQ "02/03/2008 11:50 AM" echo>error.txt that will work i prefer only date so: Code: [Select]for %%a in ("java2.exe") do set time1=%%~tA REM GET DATE ONLY for /f "tokens=1 delims= " %%a in ('echo %time1%') do set date1=%%a if "%date1%" NEQ "02/03/2008" echo>error.txtwrong !! hi dear devcom and THANK you very much for your cooperation well your last codes did not work i don't know why ! i used following codes Quote for %%a in ("java2.exe") do set time1=%%~tA but i think there is something wrong . it always creates error.txt why? i think NEQ means=not EQUAL . right? and equ= equal so why it always create error.txt ? my values are not wrong. i even changed "02/03/2008" to anything example "02/04/2006" and it still create error.txt so it will always searching for wrong values not correct values !! i replaced NEQ with equ and it did not worked. i mean this time did not create any txt so do you have any idea? by the way in CMD report i see 02/03/2008 but java2.exe properties shows 2008/03/02 which one is correct? |
|
| 4755. |
Solve : Batch Multiple files for process? |
|
Answer» Well i have a lot of video's on my pc and i made a simple .bat encoder for them. |
|
| 4756. |
Solve : suppress an error message..??? |
|
Answer» if there is no disk in dir a:\ and i do "start a:" in cmd-batch, is there anyway to suppress the "Windows - No Disk" Error message that pops up..??Code: [Select]if exist a:\ start a:didn't WORK... yes the message did not show with dir a: 2>nul Have you tried it? if a formatted floppy is in the drive then a: exists then dir a: will work the output goes to nul so you don't see it and the && test is passed and the type "C:\1.txt" will happen. (unless the floppy has the write protect switch in the protect position) if a: does not exist then dir a: will not work and the && test is failed and the type C:\1.txt will not happen Maybe you don't know what && means? And why don't you answer about why you are using TYPE instead of COPY? yes i tried it.. like i said though if there are no files or folders in A:\ Dir A: will fail i tried on my usb drive E: your code dir E:>nul 2>nul && TYPE "C:\1.TXT" > "E:\1.TXT" there were no files or folders on the drive so Dir E: failed and so did the rest of the code.. i use TYPE instead of COPY becuz i don't want to use any external copy.exe like i say earlier... is there anyway to use this >nul FEATURE in this code "If Exist A:\ TYPE "C:\1.TXT" > "A:\1.TXT"Quote from: gumbaz on October 13, 2008, 01:17:58 PM i use TYPE instead of COPY becuz i don't want to use any external copy.exe There is no copy.exe in Windows. Where did you get that idea? Copy is an internal command just as type is. Quote like i say earlier... Try this XCOPY A:\Is_Ready.Test > NUL IF NOT ERRORLEVEL 4 ECHO Drive is ready. |
|
| 4757. |
Solve : Permanently shutdown "wmiprvse.exe"? |
|
Answer» Hello again! |
|
| 4758. |
Solve : To encrypt or to make a exe type file of a batch file that no one may modify it? |
|
Answer» Sir, Set the batch file to have read-only and system attributes. The system attribute prevents them from removing the read only status as system or hidden stati must be removed first. not file attributes, security attributes. The file owner- them - can remove write access to the file to the "Everyone" group.Ohh. Right! I KNEW that lol! |
|
| 4759. |
Solve : restore partition? |
|
Answer» I don't know if this is the right forum to post this, but it seemed LIKE the best fit... YOU CAN USE norton ghost for this issue i think this will help u in ur problam I think he already KNOWS that Use partitioning software to shrink the 2ND partition, then create a new FAT32 partition in the space made available, then boot with a DOS floppy or pen drive and run Ghost to make an image of your system partition in that partition. In my opinion, you would be better off using an external hard drive to store the Ghost image, as if anything goes wrong with the disk, your recovery partition will be hosed too. I used to use the Ghost to backup patiton when it's in good conditions, and restore it when the system did not perform so well. I think the way of he use the image file and my way are almost the same |
|
| 4760. |
Solve : Batch file to read date & time of text file & compare with Current? |
|
Answer» Dear, Sorry but i am not much familiar with VB scripts.if you are asking for a batch solution here, it shows you are not familiar with batch either. what makes you hesitate to learn about vbscript then? you are also expected to put in your own effort in the first PLACE. |
|
| 4761. |
Solve : Batch File Missing Files with xcopy? |
|
Answer» Hello, |
|
| 4762. |
Solve : Auto defrag BAT file when fragmentation is above 5%? |
|
Answer» Is there a way to parse the -a switch response of DEFRAG to determine the level of fragmentation and if it is above a certain amount start DEFRAG c:.Yes. Parsing is easy Would you please, explain briefly the code for me? I will do so briefly, but really you need to to study the "tokens=" and "delims=" features in FOR /F. Type FOR /? at the prompt. Also search the web for guidance. Quote for /f "tokens=1-9 Why 1-9? Because by selecting spaces and percent signs as token delimiters the defragmentation percentage figure is the 9th token in the output line of defrag which contains the figures, (the line which contains the word Fragmented which is selected by Find.exe) A B C D E F G H I 1 2 3 4 5 6 7 8 9 25.49 GB Total, 10.25 GB (40%) Free, 6% Fragmented (13% file fragmentation) "Tokens=1-9" FOLLOWED by "%%A in" means "set up 1 explicit loop variable (%%A) and 8 implicit ones (%%B to %%I)" Quote delims=%% Why %%? Because to echo a single percent SIGN in a batch file you have to type %% Quote What is difference between using only "|" vs. "^|"? Just using | in that place would result in a message "| was not expected at this time." The pipe character | needs to be escaped with a caret. Quote Where does %%I come from? (can it be any other character or it has to be "I"? It has to be I. See my chart of tokens above. I chose %%A to be my first token, and I require to extract the 9th token, and I is the 9th LETTER of the Roman alphabet. Dias, Thank you for the explanation, it was very clear. I LEARNED a lot more from it than by just typing "For /?" which is a typical Microsoft help, it does gives you an ANSWER but by itself it is useless. Thanks! Geza |
|
| 4763. |
Solve : Route Add? |
|
Answer» I am trying to GET connected to a clients FTP site. |
|
| 4764. |
Solve : Backups batch file help.? |
|
Answer» I have a BATCH file that I used to zip Virtual machines up with (for backup). |
|
| 4765. |
Solve : How can you place a variable within a variable in batch file programming?? |
|
Answer» I have been trying to create a batch file which outputs text followed by a respective number value, to a text document. My problem is that in order to do so, I need to place the variable %value% (in example below) within another variable. Try not to use the TIME variable as it always changes. Please explain in the context of the posted script. ThanksTry not to use %time% (the time variable) very often, as it always changes depending on the SYSTEM time. Try this script and see what I mean. Time contains: hours (in 24hr format), minutes, seconds and milliseconds. @echo off echo %time% ping localhost -n 1 > nul echo %time% pause > nulSure the System environment variable is changing every millisecond but what about Time set in the Command shell or Local environments? A script running in either of those environments sets VARIABLES only for those environments not for the system so if Time is set in either environment the system environment variable remains unaffected and the variables set in Cmd and Local environments are fixed until changed within those environments or until the script finishes or until Endlocal is processed. Try this: Code: [Select]@echo off cls echo Echoing the time variable... echo System environment time=%time% echo. echo Setting Time in Cmd shell environment to abcdefg... set time=abcdefg echo Echoing the time variable... echo Cmd environment time=%time% echo. setlocal echo Setting time in Local environment to qwerty... set time=qwerty echo Echoing the time variable... echo Local environment time=%time% echo. echo Accessing System time from the Local environment... set time= echo Echoing the time variable... echo New System environment time accessed from the Local environment=%time% endlocal echo. echo Returning to Cmd time... echo Echoing the time variable... echo CMD environment time is still set to=%time% Echo. echo Returning to System time... set time= echo Echoing the time variable... echo System environment %time% Thanks guys - problem solved! Particularly to 'Prince_' and i also learnt something from 'Helpmeh' I wasn't looking for any WAY to set the actual computer time, just a way to use a variable with the name time in it (resolved by using 'tme' instead). It was just a matter of placing an extra grouping of '%'s around the variable ie not echo %tme%value%% but instead echo %%tme%value%%% Thanks to everyone that replied -Danielsrry. just found out it hadn't actually answered my problem but I found a great website that had already solved the problem: http://www.codeproject.com/KB/winsdk/Batch_File_Bubble_Sort.aspx Thanks for all ur help ! |
|
| 4766. |
Solve : Is GOTO illegal in a FOR LOOP - i.e. FOR %%X (*.*) DO ( loop code )? |
|
Answer» My TEST.CMD file shares a folder with ToBAK.CMD. - 12 - 1 - ToBAK.cmd - ToBAK.cmd - ToBAK By simply changing "SET MAX=2" to "SET MAX=1", the "GOTO L2" does not execute and I get the "correct" result :- Quote - 12 - 1 - ToBAK.cmd - ToBAK.cmd - ToBAK My Conclusions :- execution of "GOTO L2" results in a) Total loss of the value of %%Y the second time around; b) Subsequent failure of the FOR (*.*) loop to process the second file. Code: [Select]@ECHO OFF setlocal enabledelayedexpansion SET MAX=2 SET N=11 FOR %%Y in (*.*) DO ( SET Z=%%Y SET /A N+=1 set P=0 :L2 SET /A P+=1 ECHO - !N! - !P! - !Z! - %%Y - %%~nY IF !P! LSS !MAX! GOTO L2 ) pause N.B. The above code illustrates the peculiarity I am fighting. The real code I attempting has the same basic form with the exception that instead of a harmless "ECHO %%Y" etc. I am trying to do more DANGEROUS things involving the creation of new sub-folders and relocating precious archives into the new structure. I am now thinking I can replace the 4 LINES of ":L2 ... GOTO LOOP L2" code with a single line "CALL :LOOP2" and that can have the secondary iteration code. Any advice will be appreciated, but much as I want to finish my present project, I wish now to learn about this peculiarity, and anything I have done wrong, and how to avoid this sort of problem in future. Regards Alan You could try and do something like the following: Code: [Select]FOR /f "usebackq" %%Y in (*.*) do ( SET Z=%%A& SET /A N+=1& SET P=0 & CALL :L2 %%A ) :L2 Thanks I have made a start upon using CALL :LOOP2 whilst awaiting further feedback. I am hoping for an explanation of why GOTO trashes a FOR LOOP so I will know what to avoid in future. Incidentally, I recognised "usebackq" and ran "FOR /?" to find out more - I still have not got to grips with it. I did alter my code to FOR /f "usebackq" %%Y in (*.*) DO ( and all I got was Quote The system cannot find the file *.*. Regards Alan what information are you trying to set in the variable Z? Right now this will run against any files in the current directory for the batch file. if you are trying to pull data from a specific file you will need to replace (*.*) with the file location that has the information you are looking for. I never wanted Z in the first place. The only reason I used "SET Z=%%Y" was because I observed that %%Y became undefined when GOTO L2 was executed, therefore before it lost its value I used "SET Z=%%Y" to see if Z was more permanent. I found that where GOTO killed %%Y, it did no damage to !Z! I thought I had a perfect solution by using !Z! wherever I had used %%Y. BUT THEN I added a second file in the folder and found that GOTO L2 not only killed the value of %%Y, it also caused "FOR %%Y ..." to forget where it was, and the subsequent file(s) never got processed. The two lines of output were - 12 - 1 - ToBAK.cmd - ToBAK.cmd - ToBAK - 12 - 2 - ToBAK.cmd - %Y - %~nY The second line shows that !Z! is still defined as "ToBAK.cmd" but %%Y and %%~nY have become undefined and useless. The eventual purpose of my project is to take a folder with disc partition image files such as I:\Backups\2009_03_31_19_06_40_198D.TIB I:\Backups\2009_04_05_18_49_38_184D.TIB I:\Backups\2009_06_06_14_00_32_370D.TIB Then for each such file create a companion folder such as I:\Backups\2009_03_31_19_06_40_198D Each of these companion folders will hold sub-folders such as I:\Backups\2009_03_31_19_06_40_198D\2 I:\Backups\2009_03_31_19_06_40_198D\3 I:\Backups\2009_03_31_19_06_40_198D\4 Then "incremental" files such as I:\Backups\2009_03_31_19_06_40_198D2.TIB I:\Backups\2009_03_31_19_06_40_198D3.TIB I:\Backups\2009_03_31_19_06_40_198D4.TIB will be moved to I:\Backups\2009_03_31_19_06_40_198D\2\2009_03_31_19_06_40_198D2.TIB I:\Backups\2009_03_31_19_06_40_198D\3\2009_03_31_19_06_40_198D3.TIB I:\Backups\2009_03_31_19_06_40_198D\4\2009_03_31_19_06_40_198D4.TIB Regards Alan ok I think i understand what you are looking for let me see if I can get it working for you. Thanks, but I have the original code fixed as below. The final implementation is coming along NICELY, but I am taking it slow with lots of debug, because my post above has glossed over many intricacies. All I really need now is an explanation of what rule(s) I violated by using a GOTO within a FOR loop. I appreciate that GOTO is not a nice WAY to break out of a loop but I was staying inside the loop and cannot see why that gives disastrous results. Code: [Select]@ECHO OFF setlocal enabledelayedexpansion SET MAX=3 SET N=11 FOR %%Y in (T*.*) DO ( SET Z=%%Y SET /A N+=1 set P=0 CALL :L2 %%Y ) pause EXIT /B :L2 SET /A P+=1 ECHO - !N! - !P! - !Z! - %1 - %~n1 IF !P! LSS !MAX! GOTO L2 Regards Alan |
|
| 4767. |
Solve : Realms of *censored* version G? |
|
Answer» Updated Realms of *censored*, http://realmsofhell.tk/ you can move back to main menu now i added a BANK, i added a teleporter bank works for multiple people, the MAP function DOESNT work everywhere all three CONTINENTS are something like this % % % * * * *********** % - home * * * % % % * - path * * * * * * T ********** k - Kingdom * * * K -* T - Teleport room/ bank room * * * * * * * * * *well you made few mistakes: * we have thread for apps/games * you complied your game so someone may dont trust you and we cannot see code * there are several error durning using the game (this is my opinion) but ANYWAY i think its a good code/game |
|
| 4768. |
Solve : Need help with..? |
|
Answer» I have a batch file and it waits for the user to write what to do, |
|
| 4769. |
Solve : clear print queue on a remote server? |
|
Answer» Hi everyone, I hope someone can help me out. I've got an older server running Windows Server 2003, and not very well. The print queue gets clogged up on a daily basis from teachers printing the same document over and over instead of waiting for it to come out. I have a simple batch file set up to stop the print spooler, delete the offending FILES, and restart the spooler. However, I have to log into the server each time. I'd like to put a batch file on my desktop to remotely delete the files. Below is the script I am using, can anyone help with modifying it to be able to do what I want? |
|
| 4770. |
Solve : Combining DBF files? |
|
Answer» I have 1508 DBF files that need to be combined into ONE FILE. Each file contains different data but all have the same column names. Is it possible to combine them using a dos command? |
|
| 4771. |
Solve : Stack Overflow? |
|
Answer» Hello,Hope someone can help me,i just got a Old 486 Ibm thinkpad Labtop computer from a yeard sale the other DAY,it had windows 95 on it."i notaced it would sometimes stop with a stack overflow message when i would start the comeputer and boot windows 95". well anyway it was a trashy install so i just thought i would reinstall windows 95. so being it dont have any cdrom drive,no usb ports,i had too use floppy disk(s).Well anyway now i wiped the old windows 95 now i cant reinstall windows 95. I Keep getting a stack overflow message,telling me to increase stack settings in config.sys.Well it dont make any sense as there are not any dos apps booting up.autoexec.bat is blank! "The install files are already on the hard drive!so i need SOMONE to tell me what could be worng.it dosent matter if i boot up to a Fresh bootdisk,i always get a stack overflow message.Could somedody Please help? |
|
| 4772. |
Solve : Updating the file based on the location using a batch file? |
|
Answer» Hi, |
|
| 4773. |
Solve : Run an existing .bat & .vbs script from a .bat or .vbs? |
|
Answer» Hi |
|
| 4774. |
Solve : copy files to different direcotry when they match specific string.? |
|
Answer» I have a file that contains list of SEARCH strings (like ABCDE, XYZ etc..) separated by new line. I have a source folder where there are around 35000 files (.txt). We need the destination folder populated (copied ) with matching files... I have to do this in MS DOS. can anybody give me a batch file...or vbscript..... thanks, rav.Your question is a bit ambiguous. Do the files get copied to different destinations depending on which string they match? What if a file name matches none of the string arguments? How many string arguments are there? Might be easier to hardcode an array rather than load array from file. Your profile mentions your OS as Linux Variant. VBscripts run in Windows or the SHELL program. They do not run in MS-DOS. Code: [Select]Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("search.txt", ForReading) 'Load Array i - 0 Do Until f.AtEndOfStream = True ReDim Preserve arrSearch(i) arrSearch(i) = f.ReadLine i = i + 1 Loop f.Close 'End Load Array Set f = fso.GetFolder("c:\source") Set fc = f.Files For Each fs In fc For Each arg In arrSearch If INSTR(1, fs.Name, arg) > 0 Then fso.CopyFile fs.PATH, "c:\dest", True End If Next Next Save file with a vbs EXTENSION and run from the command prompt as cscript scriptname.vbs You will need to add path information to match your environment. Good luck. linux variant? BASH? you can use the question mark ? to fill in unkowns for example, instead of dir file393039*.txt , dir file???*.txt |
|
| 4775. |
Solve : Bat2Exe problems when using icons.? |
|
Answer» well im TALKING about when you call the batch file, it shows the line, but when you just run it, it doesn't. Another issue just came up that maybe someone here can answer. In the BAT file (before compiling) I have an "Echo Running %1", this works when the file is a BAT file called from another BAT file, but as soon as I 'exe' it, the echo statement disappears. Anyone have an idea for a work around here? There are other controls for redirection: http://www.zsh.org/mla/users/1997/msg00526.html Quote "Will interpret the `1>&2' as Your bat to exe converter might have command line options for redirection? or the following workaround might survive the conversion PROCESS: echo Running %1 1>output.txt type output.txt WOOOHOOO that worked. The 1>output.txt did it. I'M FREE...lol Thanks guys, just have the ICON to test next. V1.5 is definately better.I definitely agree too! I can add the "additional informations" area without ANY issues at all! |
|
| 4776. |
Solve : Disable UAC via batch?? |
|
Answer» Is there a way to disable UAC via a .bat?reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f |
|
| 4777. |
Solve : Complicated Batch? |
|
Answer» Steini |
|
| 4778. |
Solve : BAT Program Help? |
|
Answer» Hey, I NEED some help with a .bat program. |
|
| 4779. |
Solve : how to check perl available in batch file? |
|
Answer» I've always CONSIDERED it as something that INSTALLS itself to be SIMILIAR to the old PC-DOS REXX processor, QBASIC, and BASICA interpreters, in that you wouldn't need to say, C:\DOS\QBASIC /RUN runit.bas |
|
| 4780. |
Solve : Display filename and length in batch file? |
|
Answer» The script will dispaly the filename. I need to display the length as well eg. filename is abc.txt, the length is 6 a-hire.txtyou can use vbscript Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFolder = "c:\test" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files WScript.Echo strFile.Name,Len(strFile.Name) Next save the above as myscript.vbs and on command prompt Code: [Select]c:\test> CSCRIPT /nologo myscript.vbs output Code: [Select]C:\test>cscript /nologo test.vbs 11 MickeyMouse Road.doc 23 11 MickeyMouse Road.pdf 23 a-hire-1-0601-txt 17 a-hire-2-0601-txt 17 a1.csv 6 a2.csv 6 alternative solution, in Python (for Windows) Code: [Select]import os path=os.path.join("c:\\","test") os.chdir(path) for files in os.listdir("."): print files,len(files) save the code as myscript.py and on command prompt Code: [Select]c:\test> python myscript.py Ghost, Why does wc -c show 9 characters when there are only six? C:\>cat unix.txt 666666 C:\>cat unix.txt | wc -c 9 C:\>carriage RETURN and linefeed, and the EOF mark, probably.Quote from: billrich on June 11, 2009, 07:40:55 PM Ghost,there are some unknown characters i believe. please check your unix.txt again. Most probably there are \r\n or somethign . you can use od to check what's inside your file Code: [Select]c:\test> od -c file.txt here's mine Code: [Select]C:\test>more file.txt 666666 C:\test>cat file.txt | wc -c <-------------------- No need to use cat .. see wc example below 6 C:\test>wc -c < file.txt 6 there are no other characters after the last "6" C:\>cat ghost.bat Code: [Select]@echo off echo 11 MickeyMouse Road.doc | wc -c echo 11 MickeyMouse Road.pdf | Wc -c echo a-hire-1-0601-tx | wc -c echo a-hire-2-0601-txt | wc -c echo a1.csv | wc -c echo wcup a2.csv | wc -l Output: C:\>ghost.bat Quote 25C:\>i will show you an example Code: [Select]C:\test>echo 11 MickeyMouse Road.doc | wc -c 26 C:\test>echo 11 MickeyMouse Road.doc | od -c 0000000 1 1 M i c k e y M o u s e R 0000020 o a d . d o c \r \n 0000032 after ".doc" there is a space. is counted as 1. also , the echo command gives you \r\n at the back. that's why whenever you use echo like this Code: [Select]C:\test>echo test test <---- extra blank C:\test> if you add them up, its 26 characters. cmd.exe's echo just treat everything after as 1 character, including quotes like " Since you already have GNU tools, you can use printf instead of cmd.exe's echo.. Code: [Select]C:\test>printf "11 MickeyMouse Road.doc" | wc -c 23 this is CORRECT one.Ghost, Hey, you are good. Do you work for Microsoft or AT&T? I like these Unix solutions better than than the VBS solution. I hope the lady who started this thread is STILL reading. Thanks for the effort over and above . . . Quote Quote from: billrich on June 11, 2009, 09:12:34 PM Ghost,no. i am "self employed" and a hobbyist now. previous job as win/*nix administrator. Quote I like these Unix solutions better than than the VBS solution. I hope the lady who started this thread is still reading. Thanks for the effort over and above . . .no problem. Its good that most of these *nix tools are ported to windows to complement what batch lacks. |
|
| 4781. |
Solve : Batch to stop SQL2005 service MSSQL$CSS ( sqlservr.exe )? |
|
Answer» Looking for the INSTRUCTION for my batch file to easily stop and start the MSSQL$CSS SQL2005 server service. and then svchost will start it up again...Less arrogance in the future please. I'm trying to help.I wasn't being arrogant, I was merely stating a fact. Actually, if you keep taskkilling in a loop for a while, svchost will give up starting it. Unfortunately I believe it also disables the service, causing problems with SQL server. Also- what if SQL server is in the middle of a transaction when you taskkill it? databases could get CORRUPTED, file handles remain open, meaning starting it again later (assuming the fact that svchost hasn't already disabled the service because it kept "crashing"), would CAUSE SQL server to have problems gaining EXCLUSIVE access to it's own databases again. Killing processes is never a really clean solution, even if it would appear so- even when it works- terminating processes leaves a lot of cruft, from open file handles to open registry keys and even open devices (try killing a burning program when it's in the middle of a burn...)Quote from: BC_Programmer on October 29, 2008, 05:06:32 PM I wasn't being arrogant, I was merely stating a fact. I'd rather not, and I have 0 experience with MySQL, He asked how to end a process, I gave him an answer.he asked how to end a service. Although a service is a process, it's always best to get svchost to shut down the service cleanly. Your solution works fine- but it could have ramifications beyond the solution (I stress the could part since it's highly likely that SQL server is smart enough to notice that it's service is disabled and enable it again anyways).Quote from: BC_Programmer on October 29, 2008, 05:18:18 PM he asked how to end a service. Although a service is a process, it's always best to get svchost to shut down the service cleanly. Agreed, period.Thanks for info both of you! Dave |
|
| 4782. |
Solve : Doubt in cmd comands.? |
|
Answer» Hello every one "abc:::123:::xyz"thanks, it helps me if you have gawk for WINDOWS(see my sig ) Code: [Select]C:\TEST>set str=abc:::123:::xyz C:\test>echo %str%|gawk -F":::" "$1=$1" OFS="\n" abc 123 xyz redirect to new file as needed. |
|
| 4783. |
Solve : batch file - urgent? |
|
Answer» Hi, To show the Language bar (using Classic view in Control Panel): FBI have crated an application in vb .net and i want to make sure that all my users have their regional and lanugage settings set to english us (mm/dd/yyyy)- as we agreed with them. i know how to do it manually.......but i want to run this batch file when INSTALLING the application thanks i found this - it changes your SETTING to mm//dd/yyyy but not English canada to english us :: ShortDate_Save_Restore.bat :: Process Steps: :: 1 Save current shortDate format, :: 2 Set format to Standard M/d/yyyy :: 3 Execute passed parameters :: 4 Restore original shortDate format @SETLOCAL&@SETLOCAL ENABLEEXTENSIONS&@SETLOCAL ENABLEDELAYEDEXPANSION&@IF NOT DEFINED EchoState @SET EchoState=OFF @ECHO %EchoState% :: Display current format REG.EXE QUERY "HKCU\Control Panel\International" /V sShortDate | FINDSTR.EXE /I sShortDate DATE /T :: CAPTURE (and save) the current date format output from 'REG QUERY' FOR /F "TOKENS=1,2*" %%A in ('REG.EXE QUERY "HKCU\Control Panel\International" /v sShortDate ^| FINDSTR.EXE /I sShortDate') DO ( SET _KEY=%%A SET _TYPE=%%B SET _VALUE=%%C ) :: Reset the format to the system default value MM/dd/yyyy REG.EXE ADD "HKCU\Control Panel\International" /f /v sShortDate /t REG_SZ /d MM/dd/yyyy :: Verify that the value is set REG.EXE QUERY "HKCU\Control Panel\International" /v sShortDate | FINDSTR.EXE /I sShortDate DATE /T PAUSE :: Run process @ECHO.CALL %* CALL %* :: End process |
|
| 4784. |
Solve : Change content of variable.? |
|
Answer» Win XP (H) Cmd.exe Batch script. |
|
| 4785. |
Solve : "Eval" in MS-DOS batch file?? |
|
Answer» Sorry if this is a very basic question, but surprisingly, extensive googling on the topic has yielded nothing of value. |
|
| 4786. |
Solve : How to find usernames via the computer name from command prompt within a network? |
|
Answer» I don't think the title made sense! |
|
| 4787. |
Solve : BAT2EXE adding Quotes to SET statements?? |
|
Answer» GOOD morning EVERYONE, the newest VERSION of Bat_to_EXE_converter does somerthing new. I have a bat file that has the following: set MODULE=%3 set SERVERNAME=%4 If the file is in BAT format, the results are: set MODULE=SY set SERVERNAME=NULL Once I compile the BAT file into an EXE, the results are: set MODULE="SY" set SERVERNAME="NULL" This definately messes up my scripts if {%4}=={NULL} set SERVERNAME=%COMPUTERNAME% Any ideas on how to stop this? Ken i don't personally use BATtoEXE and i have heard problems associated with it. however, i do have experience in programming with other languages like Perl and Python and have used their converters (perl2exe for Perl and pyinstaller/py2exe for Python) to produce EXE files and have worked PRETTY well. If you are not RESTRICTED to batch, i recommend you pick up one of these languages and play with it. Where is the site that created the complier ( converter ) from bat to exe? Contact their Support Department? In the meantime try: REM on the command line for the bat file try "%3" and "%4" @echo off set MODULE=%3 set SERVERNAME=%4 REM on the command line for the bat file try "%3" and "%4" set MODULE=%3 set SERVERNAME=%4 echo Module = %MODULE% echo Servername = %SERVERNAME% REM Once I compile the BAT file into an EXE, the results are: set MODULE="SY" set SERVERNAME="NULL" REM This definitely messes up my scripts if {%4}=={"NULL"} set SERVERNAME=%COMPUTERNAME% echo servername %SERVERNAME% C:\> |
|
| 4788. |
Solve : Change screensaver registry remotely...? |
|
Answer» /cry ... I'll maybe work on a BAT file running the the startup folder. The students are locked down from this AREA and shouldn't be ABLE to make changes. Thank you so much for trying to get this to work for me. I really, really appreciate your time! |
|
| 4789. |
Solve : I need a way to check a txt file for 0 or above..? |
|
Answer» I have a stats file that generated on the hour and it includes the following in it. What I need to do is if the failed reaches above 0 then reset the service that is running this. I am not sure what the code is to check a certain line in the stat.txt file like row 10 can anyone help with this one? |
|
| 4790. |
Solve : replace substring when giving file name to print? |
|
Answer» Hello, i want to execute the following command If you want to do it at the prompt, why can't you just type this? Code: [Select]LPR -S 192.168.3.20 -P AUTO d:\test.txt Or if the command is in a batch file, why can't you load it in Notepad, change "sample" to "text" by use of the delete key and a bit of typing, and then save the batch file? I fully EXPECT your answer will be that it's not as simple as that, but since you have given no background information, I don't SEE what else can be suggested. |
|
| 4791. |
Solve : Regedit, to dos variable?? |
|
Answer» There's a specific variable i want to GET from the registery. ! REG.EXE VERSION 3.0By that set q=REG QUERY HKEY_CURRENT_USER\Software\Valve\Steam /v LastGameNameUsed Will not do it. I want it only to be ogelami And i want to be able to use it, like in an ECHO. echo helo %q% That prints "Hello ogelami!"Code: [Select] @echo off set regcommand=REG QUERY HKEY_CURRENT_USER\Software\Valve\Steam /v set keyname=LastGameNameUsed for /f "tokens=1,2,3 delims=<TAB>" %%A in ( ' %regcommand% %keyname% ^| find "%keyname%" ' ) do set LastName=%%C echo Hello %LastName% Important note: Do NOT merely copy and paste this. Replace in the 4th line with a TAB character, obtained by pressing the key of that NAME. Thank you times and times ! it worked fine! Another happy customer! Glad to hear it worked. Good luck, my friend! Thank you, there's anoter small thing i need help with. When i receive a directory variable, the slashes are just regular slashes, i want them to become backslashes =), any solution?Quote from: ogelami on October 12, 2008, 05:11:57 AM Thank you, there's anoter small thing i need help with. This is a path name got from the REGISTRY? You mean they are forward slashes? like this / ? And you want them to be back slashes like this \ ? Please explain. Quote from: Dias de verano on October 12, 2008, 05:16:10 AM Quote from: ogelami on October 12, 2008, 05:11:57 AMThank you, there's anoter small thing i need help with. yes, excatly if i get "SteamPath" instead "LastGameNameUsed" it will return in C:/Program/Steam what i want is it to be C:\Program\Steam to replace one character or string in a variable by another: To replace X with Y in %myname%: Code: [Select]set myname=%myname:X=Y% and to replace Z with nothing (remove all the Zs) in UncleName: Code: [Select]set UncleName=%UncleName:Z=% and to replace cat with dog in %animalname%: Code: [Select]set animalname=%animalname:cat=dog% Thus: Code: [Select]C:\>set myname=aXa C:\>echo %myname% aXa C:\>set myname=%myname:X=Y% C:\>echo %myname% aYa and Code: [Select]C:\>set pathname=c:/program/steam C:\>echo %pathname% c:/program/steam C:\>set pathname=%pathname:/=\% C:\>echo %pathname% c:\program\steam Works both at prompt and in a batch thank you! |
|
| 4792. |
Solve : batch puzzle: conditionally truncating filenames throughout subdirectories? |
|
Answer» Hi all! I came across this site searching for some pieces to help me solve a batch puzzle I'm up against. I am vaguely familiar with DOS and programming in general, but lack specific knowledge of dos commands; I don't want to inadvertently modify files that don't need it, and I don't know how to apply a command to all subdirectories. p.s. entering the following - for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') ren "%%i;%%j" "%%i" - in the command prompt returns "%%i unexpected at this time" and nothing happens. Modifying to %i returns "ren unexpected at this time" Fixed the ren command. See code below. Quote "The system cannot find the file specified." I should have mentioned this message was expected. Files not containing the semi-colon did not need to be renamed. By appending a semi-colon, the file would not be found, throwing an error. Sloppy perhaps, but effective. Code: [Select]@echo off for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') do ( ren "%%i;%%j" "%%~nxi" 2>nul ) I made to slight change to the ren command to send errors to the nul device. Sorta like throwing dirt under the rug. since OP needs to rename only the files that end in ;1, why not just do a dir *;1 ??Quote from: Sidewinder on October 27, 2008, 04:51:24 PM
Worked perfectly! It was great to have explorer open and watch everything SNAP back to normal. Thanks a ton. |
|
| 4793. |
Solve : Activate a program with correct code lines? |
|
Answer» OK this might be a long shot, but perhaps someone can guide me in the correct way. I admit I am not that great in programming but I do understand a little like renaming, xcopy delete etc . This ONE has put me in difficulties and it has no samples for me to try with. You can download this utility tool from here (no virus included, I PROMISE) and it is not an install version. |
|
| 4794. |
Solve : Pass direction character '>' to SCHTASKS /TR switch value? |
|
Answer» I have a batch file to create a scheduled task on multiple servers. I am trying to set the task RUN: option to call the command and direct output to a logfile. The issue is SCHTASKS interprets the '>' for its role instead of being a member of the string for the /TR switch. My desired result for the tasks RUN: is without brackets ["C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log] |
|
| 4795. |
Solve : boolean functions? |
|
Answer» Is there a way to use boolean functions in the IF statement? Things like logical and, or, xor. |
|
| 4796. |
Solve : Compare file date to current date? |
|
Answer» try to put Mon 10/27/2008 in quotes ("")Thank you. |
|
| 4797. |
Solve : Config.sys editing? |
|
Answer» Hi everyone, |
|
| 4798. |
Solve : dos for command? |
|
Answer» I have a file LOG file for which I need to read each line. If a line in the log file starts with the word 'Record' or 'ORA' I want to capture the complete line and write it to a new file. ...the above method calls findstr for each line iteration. If there are 10000 lines, then findstr will be called 10000 times, which is inefficient. better to use it the other way round , ie Code: [Select]for ..... ( findstr "ORA Record" mainlog.txt ) do blah blah if there are further processing on each line found, or simply pipe to newfile if what OP wants is only to find ORA records Code: [Select]findstr [blah options] "text_to_find" >>newfile ghost, You are right the for loop is not needed: Code: [Select]@echo off echo. > newnewfile.txt findstr "ORA Record" mainlog.txt >> newnewfile.txt type newnewfile.txt Output: C:\>type newnewfile.txt Record bbbbbbbbbbbbbbbbbb ORA xxxxxxxxxxxxxxxxxxxxxxxx C:\> p.s. Works just like the Unix grep command. Quote from: billrich on June 12, 2009, 07:42:31 AM p.s. Works just like the Unix grep command.and also awk/sed. these tools iterate files and find patterns so they are similar. however, awk goes a bit more in that it is a programming language by itself. therefore, one does not need to learn grep/sed and use only awk to do the job( of MANY , eg cut, wc). this will reduce your learning curve a lot. |
|
| 4799. |
Solve : Pull files from server? |
|
Answer» Hi |
|
| 4800. |
Solve : Remove Spaces from String? |
|
Answer» Ok I got it. |
|