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.
| 3151. |
Solve : Rename files with % sign? |
|
Answer» I have a DIRECTORY with filenames that have a % (percent sign) in the name. I need to rename all files with "%" sign to an "_" underscore. Any ideas how I can create a loop to do this in DOS batch [not VB]? I thought percent signs are illegal in Windows filenames, just how did these files get on your system? The files are coming from some vendor, its the way they always create all the files on their sftp SERVER. Whatever happened with the simple naming standards. Thanks for the code.... |
|
| 3152. |
Solve : help neaded to process files? |
|
Answer» Hi all, i am looking for some HELP please |
|
| 3153. |
Solve : nbtstat bat file? |
|
Answer» I am trying to make a batch file were I can input an IP ADDRESS and it run "nbtstat -a (ip)" and it has been a while SENSE I last wrote a batch file, were is a GOOD place to start?C:\>type ipstat.bat |
|
| 3154. |
Solve : Starting a new window with the specified commands.? |
|
Answer» Quote from: BatchFileCommand on April 05, 2009, 03:19:58 PM Thank you Dias, couldn't you have just posted that in the BEGGINING. I didn't think of it until today, ALSO you have been very rude, so I decided to punish you. 18:03 = 6:03this is funny little util, pop up little window showing time-watch. only few lines. nice.. and then again i am going to preach about code readability Code: [Select]@echo off>clock.bat >>clock.bat echo @echo off >>clock.bat echo mode con: cols=16 lines=2 >>clock.bat echo :loop >>clock.bat echo echo %%time%% >>clock.bat echo if not exist signal.txt goto loop >>clock.bat echo exit if exist signal.txt del signal.txt start "" "cmd.exe" /c clock.bat set /p string="Press ENTER to stop clock " echo %string%>signal.txt Code: [Select]@echo off ( echo @echo off echo mode con: cols=16 lines=2 echo :loop echo echo %%time%% echo if not exist signal.txt goto loop echo exit )>clock.bat & REM parantesis is not supported, escape with caret if exist signal.txt del signal.txt start/b "" "cmd.exe" /c clock.bat set /p string="Press Enter to stop clock " echo %string%>signal.txt |
|
| 3155. |
Solve : setting a delim as ONLY a space? |
|
Answer» I can't figure out the delimeter to set it as only a space without the tab. |
|
| 3156. |
Solve : End process and delete file every 5 seconds? |
|
Answer» hey guys, having an issue with a virus that keeps REAPPEARING after i delete it, i am trying to temporaily fix this problem until a security update is released.. Usage: sleep time-to-sleep-in-seconds or using ping, replace 2 with the number of timeout you want Quote ping localhost -n 2 -w 1000 >nil as for proccess kill, taskkill or tskill: Code: [Select]TSKILL processid | processname [/SERVER:servername] [/ID:sessionid | /A] [/V] processid Process ID for the process to be terminated. processname Process name to be terminated. /SERVER:servername Server containing processID (default is current). /ID or /A must be specified when using processname and /SERVER /ID:sessionid End process running under the specified session. /A End process running under ALL sessions. /V Display information about ACTIONS being performed.yea i know, but its an exchange problem thats spamming our servers, like i said this is just temporary. ive found that i can use ping to set time but it looks very messy, any other way?sleep doesnt work, in XP anyway@echo off :loop tskill PROCESS (without .exe) del File.ext ping localhost -n 5 -w 1000>nul goto loop But PLEASE go to the computer viruses section to REMOVE your problem, not just hide a symptom. Quote from: Khasiar on OCTOBER 27, 2009, 04:44:31 PM sleep doesnt work, in XP anyway I use XP Pro and sleep works very well. @echo off Code: [Select]set /a c=0 :here echo Sleep 3 seconds and repeat echo when count is 10 quit echo count = %c% C:\batextra\sleep.exe 3 set /a c+=1 if %c% EQU 10 exit /b goto here OutPut: C:\batextra> reploop.bat Sleep 3 seconds and repeat when count is 10 quit count = 0 Sleep 3 seconds and repeat when count is 10 quit count = 1 Sleep 3 seconds and repeat when count is 10 quit count = 2 Sleep 3 seconds and repeat when count is 10 quit count = 3 Sleep 3 seconds and repeat when count is 10 quit count = 4 Sleep 3 seconds and repeat when count is 10 quit count = 5 Sleep 3 seconds and repeat when count is 10 quit count = 6 Sleep 3 seconds and repeat when count is 10 quit count = 7 Sleep 3 seconds and repeat when count is 10 quit count = 8 Sleep 3 seconds and repeat when count is 10 quit count = 9 C:\batextra> |
|
| 3157. |
Solve : spelling? |
|
Answer» wonder if he means by name meanings... wonder if he means by name meanings... Well you still couldn't do that with batch. UNLESS you had some 3p program...even then it would be strange.No this is possible, if you LIKE doing alot of tedious IF..THEN statements, he could go onto some name meaning site and search up a name one by one and add that to the code....but still to TRIVIAL and tedious to attempt.Quote from: Helpmeh on April 05, 2009, 12:47:48 PM You can't change the ENGLISH letters in a name and get Japanese... oh, I know it is just a game however, I don't want to continue with that batch. Our alphabet is more beautiful Thank you and excuse me please |
|
| 3158. |
Solve : Backgrounds? |
|
Answer» HI everybody! Any way to set a background to my batch file, or can I insert in image in? color /? image? impossibleWhy do people think Command Prompt can do all these magical THINGS?Quote from: feras on April 05, 2009, 04:47:39 AM Hi everybody! MS-DOS and CMD are purely text based. You can CHANGE the text/background colour, but that's it.mm THANK you Quote Why do people think Command Prompt can do all these magical things? Because they don't KNOW that is not true |
|
| 3159. |
Solve : How to cycle through numbers..?? |
|
Answer» If %money% isn't assigned, then wouldn't set %money%=whatever bring an error because there was no variable name?I thought that in NT, the RECEIVING end of an anonymous pipe is launched in a separate child process, so any environment changes will not survive, so, BC_Programmer, how did you get the pipe method to work? If %money% isn't assigned, then wouldn't set %money%=whatever bring an error because there was no variable name? YES, I AGREE just the variable and not the contents of variable. I got no error messages, just the wrong answer. I did not use local variables, so the value was many times from the previous run. Finally I set the variable to zero at the beginning of the run and there after only zero appeared. No value was ever assigned to the variable with the pipe. Strange: it looks like it should work. The pipe in CMD, the COMMAND interpreter, does not work like UNIX and C. Quote from: DarrenReeder on October 27, 2009, 08:47:14 AM DOS is suupose to be the easier stuffno, its not. there are programming limitations in DOS (cmd.exe) that makes it clumsy(if not impossible) to do certain things. eg floating point maths, arrays, ability for error control, date manipulation etc. If you want to learn programming, start with a real programming languageQuote from: Salmon Trout on October 27, 2009, 04:41:02 PM I thought that in NT, the receiving end of an anonymous pipe is launched in a separate child process, so any environment changes will not survive, so, BC_Programmer, how did you get the pipe method to work? Hmm, Not sure. Not sure how I had it working either, maybe it just appeared to work; I was messing about with the commandline seeing how I could force the contents of the file to be the stdin of set /p and I figured I do it with more, may as well give piping a shot. No idea how it worked, must have been a fluke and I had set a variable to the same value I was expecting (). I believe it's true though, that as far as the | is involved each program is given a inherited environment. (it was my understanding that they could inherit a handle to the same environment, and thus change the values within it... but I suppose cmd doesn't do that. redirection works, and it's shorter, too. What I did probably stems from when I used "ANSWER.com" to perform input queries in Pure DOS; since it was a program using the pipe to force input wasn't really that esoteric. (And of course the fact that the environment block was relatively UNCHANGED for the execution of any number of programs was a big plus). |
|
| 3160. |
Solve : Help me with this Batch File Code?? |
|
Answer» mkdir c:\archive |
|
| 3161. |
Solve : Batch create crazy diretories from list.? |
|
Answer» It's a common thing on here... the classic error of the child/newbie/ignoramus: "This thing that looks complicated to me will look complicated to everybody."Quote hiding it inside maze of folder is just too easy to break. Your response to my request was very nice until I saw this. Now this takes all the fun out of it. So does that mean that now it is just a exercise in how to pull a prank on somebody? Create a maze of folders and move all of goat pictures to a folder in the bottom of the maze? Too easy to find. --sigh-- Still, is t really this easy? Is this batch? Looks like APL. I know all computers LANGUAGES, except APL. And this sure looks like APL to me! Code: [Select]for /f "tokens=*" %a in ('dir/b/s/a-d') do @if %~za neq 0 echo %aHow does it work? what are the funny symbols for?I'm not very keen with the new Batch extensions introduced with the later NT command processors, but I'll see if I can break that down: for /f "tokens=*" %a in ('dir/b/s/a-d') performs the specified directory command, which returns a listing of all files in all folders within the current directory- note the /a-d part, which says not to include files with the directory attribute (no folders). then, for each file found, it will execute: Code: [Select]@if %~za neq 0 echo %a I actually haven't a clue how it works, but the given comment "how to break garble" as well as the comparision tells us that it is comparing something to zero, only echoing it if it is not zero. I might hazard a guess and say it's checking the filesize, which would mean that create files with anything more then a single byte of random characters all over the place, perhaps with filenames, and sizes the same as the "proper" files- maybe hundreds of them, all over the place, and only the person who created it knows the "real" file. Of course the idea is to waste their searchers time opening files that crash their image editor It would confuse your basic user, but at the same time a "basic user" isn't looking for goat pictures, and just wants to know where the HECK he SAVED february's tax reports. OBVIOUSLY they would probably be puzzled why there are 500 "BESSIE.JPG" files, but probably would ignore them. If somebody was "REALLY" looking for the files, they could simply search for them, and at the very worst open them until one succeeds, or EVEN better, look at the file times and open the earliest one.Quote from: BC_Programmer then, for each file found, it will execute: for each filename found (%a in dir /b /a-d) in this and (/s) all subdirectories, if that file's size (%~za) is not zero (neq 0), echo the filename. I'm trying to figure out how reno thinks that will break "garble"... garble, after all, would consume space... Now- what if one was to literally store the "secret" files in the alternate data stream of the folders themselves?Quote from: BC_Programmer on April 07, 2009, 12:24:31 AM I'm trying to figure out how reno thinks that will break "garble"... garble, after all, would consume space... Or steganographically squirrel them away in goat images? Or did I mean goat them away in squirrel images? (Did you read about that racoon guy in Russia?) yes yes- steganographically hide them in images that are then saved to alternate data streams! ha ha ha, it's perfect! even if they are found, all they can see is the pornographic images they were hidden in! |
|
| 3162. |
Solve : Printing MS-DOS to a USB printer? |
|
Answer» My mother has an OLD dos application and she wants to use it on her new NOTEBOOK with Windows XP SP3. DOS program works but it prints nothing on the USB printer now. |
|
| 3163. |
Solve : Make Directory using "variable"? |
|
Answer» Hi all |
|
| 3164. |
Solve : MS-DOS batch file? |
|
Answer» Hi I have attached my EXCEL file Where? In any case, batch is probably not the best way to do this. Do you mean real MS-DOS or Windows command? Quote from: gimini75 on April 06, 2009, 10:19:21 AM Hi This is beyond the capabilities of Batch...Visual Basic Quote from: macdad- on April 06, 2009, 11:17:58 AM This is beyond the capabilities of Batch...Visual Basic Not in MS-DOS, unless you mean VB 1.0 for DOS. More likely have to be QBasic. Depending upon if he means CMD or Dos itself.Quote from: macdad- on April 06, 2009, 11:31:22 AM Depending upon if he means CMD or Dos itself. The title says "MS-DOS batch file" and the post refers to the serial port, which says "MS-DOS" to me. True...But still Batch is way out of this capability, QBasic would be the alternative.java sorry just being randomQuote from: squall_01 on April 06, 2009, 12:03:26 PM java sorry just being random java for MS-DOS? http://ledos.sourceforge.net/ In place of it like I said its randomQuote from: squall_01 on April 06, 2009, 12:37:19 PM In place of it like I said its random And how eactly does it help the OP to post your random thoughts? Quote from: macdad- on April 06, 2009, 11:17:58 AM This is beyond the capabilities of Batch...Visual Basic I am humoring him that is all.Back in the dark ages I used some form of Microsoft BASIC to read and write from serial ports. Almost any version of MS Basic will read and write the COM ports. But has he tested it user a TERMINAL? Send out the codes manual, or cut and past? There is all that baud rate, ODD or even or no parity, start and stop bits stuff to know about and set up.Quote from: Dias de verano on April 06, 2009, 11:11:24 AM Where? In any case, batch is probably not the best way to do this. Do you mean real MS-DOS or Windows command? |
|
| 3165. |
Solve : How can I get my DOS Computer to Boot Up?? |
|
Answer» I have a DOS based computer that when it starts to BOOT up COMES up with a message asking for the BOOT diskette in Drive A: I don't have this disk. I think the computer forgot how to LOOK at the hard drive to boot up. Is there a work around to FIX this?I suspect you cmos battery is dead |
|
| 3166. |
Solve : Using Evaluate in batch script.? |
|
Answer» XP Home. |
|
| 3167. |
Solve : Parsing string from file twice? |
|
Answer» Quote from: Helpmeh on October 23, 2009, 03:01:45 PM I fiind it funny that the op has started to learn for loops before he or she has really learned the set command. A lot of people don't so much "learn" to write code, it's more a case of copying and pasting.Very true, but some people learn that way. I first learned how to use for loops by studying Jacob's code in his AoA Local BETA. If only I still have that .ZIP archive. I was one of those weirdo's who learned by reading the documentation... the MS-DOS 6 help, to be precise.Quote from: BC_Programmer on October 24, 2009, 07:44:16 PM I was one of those weirdo's who learned by reading the documentation... the MS-DOS 6 help, to be precise.I am one of those wierdos who are too young and weren't even BORN when MS-DOS was around. How much of that documentation would apply to the command processor in windows xp? and, Is it in digital format? and if the answer to the second question is yes, May I have a copy?ntcmds.chm is a lot better then the help reference included with MS-DOS. Quote from: BC_Programmer on October 24, 2009, 08:03:25 PM ntcmds.chm is a lot better then the help reference included with MS-DOS. %Windir%\Help\ntcmds.chm on XP but unfortunately, on many computers such as those made by Compaq/HP, they make it impossible to run ntcmds.chm separately from the help and support center, so you can't use the CHM search facility easily. I think running hh ntcmds.chm might do it though AS for Vista, not included, so get it from an XP system or install disk or from e.g. Windows Server 2003 Adminpak from Microsoft. Quote from: Helpmeh on October 24, 2009, 01:51:02 PM Very true, but some people learn that way. I first learned how to use for loops by studying Jacob's code in his AoA Local BETA. If only I still have that .zip archive. a LOT of people do the copy-and-paste part without doing the learning part though. Often they then say they have "written" a program, but are apparently quite oblivious of the most obvious errors and faults in the code thus produced. Errors that they would not have perpetrated had they actually thought about what the code does. Salmon Trout Thank you for your post. You are quite correct that %% vs. % is a little (lot?) foreign to me. I have been trying to find a good DOS book but they seem to be quite hard to get compared to 10 years ago. I will look at your code and give it a burl. PS: It is amazing how many posts can appear in these threads when you turn your back for a moment.Quote from: Helpmeh on October 24, 2009, 07:54:42 PM I am one of those wierdos who are too young and weren't even born when MS-DOS was around.Sigh. I had a birthday on the weekend and I am too close to 50 to want to think about it. I had a FIDDLE with DOS 1.22 when it first came out and continued until 5.0. After that I switched to C, Pascal for a few years. I had a 10 year break but now I am back programming. I have written some C code but to complere the task I was given DOS will help. DOS is easier for file moving, deleting etc: rather than C. Quote from: Helpmeh on October 24, 2009, 07:54:42 PM How much of that documentation would apply to the command processor in windows xp? and, Is it in digital format? and if the answer to the second question is yes, May I have a copy?A copy would be nice if possible.Quote from: Tigers! on October 26, 2009, 06:34:34 PM DOS is easier for file moving, deleting etc: rather than C.A copy would be nice if possible.if your task is just copying, moving deleting files, maybe. BUT if you want to go into serious programming, DOS is not the right tool. Computing has progressed SINCE your time. Nowadays, we don't just do moving, copying deleting of files.. there are a variety of tasks that people do such as grabbing stuffs from the internet and parsing HTML, XML, reading and parsing text inside PDFs, reading Word/Excel files and getting data, querying a database, telnetting, doing file transfers etc.... Quote from: Salmon Trout on October 23, 2009, 11:22:26 AM try this if you want to actually use named variablesST I modified the code to move my files and clean up and it worked a treat. Thank you for that. Further to your comments about learning more. Looking at your code I am puzzled by your use of %%a in two apparently different situations. Firstly you are using it (so it seems to me) to step through the tokens on the line and then you are using it as an actual variable with a known value. How does DOS keep track? You also assign the current value of %%a to the other variables %%b, %%c, %%d without explicitly assigning or setting them. Again how does DOS do that? Without a good reference book I find it hard to know abour comamnds like !!. I have not yet found a site that mentions seemingly obscure commands like that. Do you have a good, available book or site?!var! Is not a command. It is the same as %var% except WITHIN a for loop if delayedexpansion is enabled. I didn't learn any of my reasonable knowledge from a book. Trial, error and looking a others' codes. Quote from: Tigers! on October 27, 2009, 06:24:05 PM Looking at your code I am puzzled by your use of %%a in two apparently different situations. Firstly you are using it (so it seems to me) to step through the tokens on the line and then you are using it as an actual variable with a known value. How does DOS keep track? You need to read the FOR help. Open a command window and type FOR /? |
|
| 3168. |
Solve : handling spaces in dos? |
|
Answer» suppose there r three files in a DIRECTORY named "NEW folder" "new folder1" "new folder2" |
|
| 3169. |
Solve : FTP Stalls? |
|
Answer» Quote from: Spoiler on APRIL 03, 2009, 10:58:47 AM Ok I want to ASK another question. From what I see so far your real goal is to copy a file from another machine to your machine right? Are both of these machines in the same network? Is the other machine running a FTP server? Is the folder called "Home" part of the other machines FTP server? Sorry for the LATE reply. Both are on different networks and the other machine is an FTP server. YES the home folder does exist in the ftp server. As I mentioned this works in an XP machine. My PLAN is to run the BAT file as a scheduled task weekly. Quote from: gh0std0g74 on April 03, 2009, 07:00:56 PM make sure that D is your root FTP folder. another way is to NOT specify the drive It wasn't the root FTP folder. I changed it to the root and it hasn't made any difference. |
|
| 3170. |
Solve : silent bat file - Is it possible?? |
|
Answer» Is there a command that can be used to run a batch file completely silent?yes, there is a way to run batch file in complete silence, but i won't post the code since it can be USE for "evil" doing. yes, there is a way to run batch file in complete silence, but i won't post the code since it can be use for "evil" doing. Well...in JUST batch, that's like half-silent...but if you convert it to an .exe...No one wonders why he WOULD NEED to run a batch file silently? Quote from: Carbon Dudeoxide on April 06, 2009, 09:58:23 PM No one wonders why he would need to run a batch file silently? heh, I was just thinking the same thing. Also, "converting" a batch to EXE simply wraps the Batch file into the executable, which recreates the batch file and shellexecutes it. I NEVER heard of such a thing I heard of were you can turn the code its self off.Quote from: joedavis on April 07, 2009, 01:52:09 PM Why doesn't the output of the AT command come to the screen? it did: Quote from: joedavis on April 07, 2009, 01:52:09 PM Added a new job with job ID = 1 |
|
| 3171. |
Solve : Batch file to start a program on another computer? |
|
Answer» Hi guys. |
|
| 3172. |
Solve : Automated Disk Cleanup? |
|
Answer» Hello Everyone! |
|
| 3173. |
Solve : batch script Adding Ip adresses to hosts file? |
|
Answer» Quote from: plm on April 07, 2009, 04:11:07 AM Hi CDOsince you have spoken , here's a link for your reference.Quote from: gh0std0g74 on April 07, 2009, 06:13:29 AM come on, what are talking about? I am talking about network-administration software.I see this as an excuse to get post-count up. Carbon SAID that the code that we could have given could have been used for malicous purposes. It may not be the OP, but LIKE he said, this is a public forum. ANYONE could see/use it. OP, if you are a sys admin, then you should at least have enough knowledge of computers to make your own easy way to do what you first posted.@plm, reply #30 is what you need to get you started. check it out and see if it works for you. Or, if you have no restriction to download gawk for windows(see my sig) Code: [Select]C:\test>gawk "1" file1.txt file2.txt 10.20.30.40 50.60.70.80 1.2.3.4 5.6.7.8 |
|
| 3174. |
Solve : Edit Ini File? |
|
Answer» If possible to edit a .txt or ini file in ? read line and data and edit them ...... Quote from: Deadly D on October 28, 2009, 01:54:39 AM If possible to edit a .txt or ini file in ? read line and data and edit them ...... http://support.microsoft.com/kb/314081 If you are using XP Pro, you may edit the ini file. Hardly anyone edits the ini file. Only experienced Administrator should edit the ini file: The purpose of the BOOT.ini file in Windows XP View products that this article applies to. This article was previously published under Q314081 For a Microsoft Windows 2000 version of this article, see 99743 (http://support.microsoft.com/kb/99743/ ) . INTRODUCTIONThis article describes the purpose and contents of the Boot.ini file....This article describes the purpose and contents of the Boot.ini file. MORE INFORMATIONWindows (specifically Ntldr) uses the Boot.ini file to determine which operating...Windows (specifically Ntldr) uses the Boot.ini file to determine which operating system options to display when the Startup program is running. By default, Boot.ini is not flagged as a read-only system file and generally does not require any manual modification. If you must change the contents of this file, use the System tool in Control Panel: Click Start button, click Control Panel, and then double-click System. Click the Advanced tab, and then click Settings under Startup and Recovery. Typically, the Boot.ini file contains the following data: [boot loader] timeout=30 default=scsi(0)disk(0)rdisk(0)partition(1)\winnt [operating systems] scsi(0)disk(0)rdisk(0)partition(1)\winnt = "Windows NT" /NODEBUG C:\ = "Previous Operating System on C:\" The following list describes the meaning of the data in the Boot.ini file: The "timeout" variable specifies how long Windows waits before choosing the default operating system. The "default" variable specifies the default operating system. The term "scsi(0)" means that the primary controller (that is frequently the only controller) is responsible for the device. If there are two SCSI controllers, and the disk is associated with the second controller, the controller is named "scsi(1)". If the system uses IDE, enhanced IDE (EIDE), or Enhanced SMALL Device Interface (ESDI) drives, or if the system uses a SCSI adapter that does not have a built-in BIOS, replace "scsi" with "multi". The term "disk(0)" refers to the SCSI logical unit (LUN) to use. This may be a separate disk, but most SCSI setups have only one LUN for each SCSI ID. The term "rdisk(0)" refers to physical disk 1. The term "partition(1)" is the partition on the first drive in the computer. If there are two partitions, partition C is partition(1) and partition D is partition(2). A multi-boot parameter calls for checking the Winnt folder to start from a specified SCSI controller's disk and partition. "/NODEBUG" specifies that no debugging information is being monitored. Debugging information is useful only for developers. You can ADD the /SOS option to display driver names while the drivers are being loaded. By default, the OS Loader screen only shows progress dots. "Previous Operating System on C:\" implies that the "previous operating system" is MS-DOS, because "C:\" is an MS-DOS path. |
|
| 3175. |
Solve : How to read target of .lnk file with command line? |
|
Answer» strings.exe can be used to remove unwanted characters. Code: [Select]C:\Documents and Settings\Administrator\Desktop>strings myshortcut.lnk Strings v2.41 Copyright (C) 1999-2009 Mark Russinovich Sysinternals - www.sysinternals.com +00 #C:\ &:<s1 Program Files PROGRA~1 &:<s Novativa Streamster NOVATI~1 &:=s Streamster.exe STREAM~1.EXE C:\Program Files\Novativa Streamster\Streamster.exe O*{ O*{ OK So I've got: Code: [Select]@echo off REM example echo Set Shortcut=%1 echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs echo set vbscript=cscript //nologo DecodeShortCut.vbs For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T del DecodeShortCut.vbs Echo Shortcut %shortcut% Echo Target "%target%">>target.txt And the output: Code: [Select]C:\VB>ShortcutTarget.bat "C:/Documents and Settings/All Users/Desktop/Adobe Acro bat 6.0 Professional.lnk" Set Shortcut="C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof essional.lnk" set vbscript=cscript //nologo DecodeShortCut.vbs C:\VB\DecodeShortCut.vbs(2, 1) WshShell.CreateShortcut: The shortcut PATHNAME mu st end with .lnk or .url. Shortcut It seems like it would work if I could GET rid of the quotes around the path as it seems to want the last characters to be .lnk So can I substring "C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof essional.lnk" to read C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof essional.lnk in my batch file? I need the quotes in the dos box since the path contains spaces?Quote from: nubia on April 06, 2009, 06:51:14 AM OK So I've got: The line with REM example can be removed; it was just to show where an example was in the original batch. There should not be an echo at the start of the next line! It should just be set Shortcut=[something] Quote I need the quotes in the dos box since the path contains spaces? Yes, that is correct, and the solution is to PASS the shortcut name with quotes from the command line like this Code: [Select]ShortcutTarget.bat "C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Professional.lnk" But in the batch strip the quotes off using the tilde ("~") variable modifier: so use %~1 instead of %1 as you see below. @echo off Set Shortcut=%~1 echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs set vbscript=cscript //nologo DecodeShortCut.vbs For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T del DecodeShortCut.vbs Echo Shortcut %shortcut% Echo Target %target% I want to thank all of you who have helped me in this. Dias especially. You have not only solved the problem you have taught me a lot, for which I am grateful. This is a great site and I HOPE some day to be able to help others. But it seems that I am way BEHIND every one and would like to learn more about Dos programming and vb script too. I, from necessity, have jumped into the middle of this and think it would be a good idea to read a primer on the subjects. (Dos programming and vb script). My best to all! |
|
| 3176. |
Solve : change key/value pairs in xml file from dos batch? |
|
Answer» Hi All,
We used commandline argument but can easily change to prompt: C:\>type patte.bat Code: [Select]@echo off findstr /v "111" patte.txt > newpatte.txt findstr /v "</param>" newpatte.txt > 2newpatte.txt echo "<value>%1</value>" >> 2newpatte.txt echo "</param>" >> 2newpatte.txt OUTPUT: C:\> patte.bat 113 C:\>type 2newpatte.txt Here is my lines in xml file: "113" "" C:\> I leave it to Cpatte to remove " (quotes) and add a prompt for user. If Cpatte needs further help I will do the above. Good luck p.s. The Ghost will now tell US the Unix sed ( Stream Editor ) command can edit your file with one line of code. Sed is available for windows and will work inside a batch file.Quote from: cpatte on October 29, 2009, 07:39:37 AM
C:\> sed 's/111/113/' pattie.txt OUTPUT: 113 C:\>Quote from: cpatte on October 29, 2009, 07:39:37 AM
C:\>type patsed.bat Code: [Select]REM Use commandline argument: patsed.bat 113 @echo off sed 's/111/%1/' pattie.txt OUTPUT: C:\>patsed.bat 113 C:\>REM Use commandline argument: patsed.bat 113 113 C:\>here's a vbscript. Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "c:\test\file" strInput = "" strOutput = "c:\test\output.txt" Set objFile = objFS.OpenTextFile(strFile,1) Set objOutFile = objFS.CreateTextFile(strOutput,TRUE) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If InStr(strLine,"license_ports")> 0 Then WScript.Echo "Enter new value: " Do While Not WScript.StdIn.AtEndOfLine strInput = strInput & WScript.StdIn.Read(1) Loop f=1 End If If f=1 And InStr(strLine,"value") > 0 Then strLine = "<value>"&strInput&"</value>" f=0 End If objOutFile.WriteLine(strLine) Loop objFile.Close objOutFile.Close output Code: [Select]C:\test>more file <param name="license_ports"> <value>111</value> </param> <param name="other"> <value>1888</value> </param> C:\test>cscript /nologo test.vbs Enter new value: 876 C:\test>more output.txt <param name="license_ports"> <value>876</value> </param> <param name="other"> <value>1888</value> </param> Quote from: billrich on October 29, 2009, 12:46:28 PM your method will not work when there are mulitiple tags, unless OP's XML file is just those 3 lines. Same to your sed solution. Quote p.s. The Ghost will now tell us the Unix sed ( Stream Editor ) command can edit your file with one line of code. Sed is available for windows and will work inside a batch file.don't put words in my mouth. I would not even consider sed AT ALL. The ideal solution this is to use a proper XML parser. If not, use a language that can process multiline strings easily, have regex capabilities (although its not a must), and let me/others easily read and understand my code. |
|
| 3177. |
Solve : Batch file to move files and rename? |
|
Answer» Hey All, Code: [Select]@echo off copy /v "%%a" d:\tmp\!i!.mod That is a slick way to rename a file but does not weed out duplicate files. It simply gives a new name to the duplicate file. This is fine if only the file name is a duplicate. Also, the for statement does not find .mod files when the path has spaces. The following might work a little better? : ( I believe the "delims=" is necessary. ) C:\>type mod.bat Code: [Select]@echo off setlocal enabledelayedexpansion cd \ set /a j=0 dir /B /s *.mod > mod.txt for /f "delims=" %%a in (mod.txt) do ( set /a j+=1 copy "%%a" E:\tmp\!j!.mod ) C:\>Bill I GAVE your second snippet a try but just got a hung command prompt window. I have also been tinkering with this process is vb script. Anyone think a batch would be better than vbs or vice versa? Thanks, NathanQuote from: nslemmons on October 29, 2009, 05:27:12 PM Bill I gave your second snippet a try but just got a hung command prompt window. I have also been tinkering with this process is vb script. Greg Flowers in post #3 gave the best answer. I merely tried to improve his answer slightly. You will not get a better suggestion than what Greg provided. Good Luck p.s. I started the mod search from root because I don't know where your mod files are stored. You may remove cd \ and start the mod search whereever you please. The mod search from root will find the mod files whereever they are stored on any machine. ( Copy but don't delete any system mod files.) Quote from: nslemmons on October 29, 2009, 05:27:12 PM Bill I gave your code a try but just got a hung command prompt window. Thanks, There is no hang with my code. It worked perfectly. Here is the code and the Output: C:\>type mod.bat Code: [Select]@echo off setlocal enabledelayedexpansion cd \ set /a j=0 dir /B /s *.mod > mod.txt for /f "delims=" %%a in (mod.txt) do ( set /a j+=1 copy "%%a" E:\tmp\!j!.mod ) Output: C:\> mod.bat 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. C:\>e: E:\>cd tmp E:\tmp>dir Volume in drive E is My Book Volume Serial Number is 0850-D7C5 Directory of E:\tmp 10/28/2009 08:42 PM . 10/28/2009 08:42 PM .. 08/10/1998 05:05 AM 6,089 1.mod 08/10/1998 05:05 AM 35,749 10.mod 08/10/1998 05:05 AM 136,770 11.mod 04/14/2008 07:00 AM 2,080 12.mod 04/14/2008 07:00 AM 2,080 13.mod 08/10/1998 05:05 AM 692 2.mod 08/10/1998 05:05 AM 29,053 3.mod 08/10/1998 05:05 AM 105,878 4.mod 08/10/1998 05:05 AM 1,080 5.mod 08/10/1998 05:05 AM 35,749 6.mod 08/10/1998 05:05 AM 136,770 7.mod 08/10/1998 05:05 AM 6,089 8.mod 08/10/1998 05:05 AM 1,080 9.mod 13 File(s) 499,159 bytes 2 Dir(s) 139,471,556,608 bytes free E:\tmp> P.S. : Greg's copy and rename line is an absolute jewel: copy "%%a" E:\tmp\!j!.modQuote from: nslemmons on October 27, 2009, 06:06:02 PM Hey All, if you want to make sure there are no duplicates after you copy, you can give each file a unique random number, if allowed by your specs. Here's a vbscript you can use Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject") Randomize strFolder = "c:\test" strDestFolder = "c:\tmp\" Set objFolder = objFS.GetFolder(strFolder) Go (objFolder) Sub Go(objDIR) If objDIR <> "\System Volume Information" Then For Each eFolder in objDIR.SubFolders Go eFolder Next End If For Each strFile In objDIR.Files If objFS.GetExtensionName(strFile) = "mod" Then name =strFile.Name src = strFile.Path rand=Int(1000000 * Rnd ) strName = objFS.GetBaseName(name)&rand objFS.CopyFile src, strDestFolder&strName&".mod" End If Next End Sub save as test.vbs on command line Code: [Select]c:\test> cscript /nologo test.vbs Quote from: nslemmons on October 29, 2009, 05:27:12 PM
I gave the vbs code by Ghost in post #9 a run and got no output the first time. And got "permission denied" the second time. Please post the VBS output here when you run the vbs code by Ghost in post #9. Thanks Quote from: billrich Please post the VBS output here when you run the vbs code by Ghost in post #9. since you insists.. Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject") Randomize strFolder = "c:\test" strDestFolder = "c:\tmp\" Set objFolder = objFS.GetFolder(strFolder) Go (objFolder) Sub Go(objDIR) If objDIR <> "\System Volume Information" Then For Each eFolder in objDIR.SubFolders Go eFolder Next End If For Each strFile In objDIR.Files If objFS.GetExtensionName(strFile) = "mod" Then name =strFile.Name src = strFile.Path rand=Int(1000000 * Rnd ) strName = objFS.GetBaseName(name)&rand objFS.CopyFile src, strDestFolder&strName&".mod" End If Next End Sub save as test.vbs on command line Code: [Select]C:\test>more test.vbs Set objFS=CreateObject("Scripting.FileSystemObject") Randomize strFolder = "c:\test" strDestFolder = "c:\tmp\" Set objFolder = objFS.GetFolder(strFolder) Go (objFolder) Sub Go(objDIR) If objDIR <> "\System Volume Information" Then For Each eFolder in objDIR.SubFolders Go eFolder Next End If For Each strFile In objDIR.Files If objFS.GetExtensionName(strFile) = "mod" Then name =strFile.Name src = strFile.Path rand=Int(1000000 * Rnd ) strName = objFS.GetBaseName(name)&rand objFS.CopyFile src, strDestFolder&strName&".mod" End If Next End Sub C:\test>dir /B /S C:\test\.txt C:\test\file C:\test\output.txt C:\test\test C:\test\test.awk C:\test\test.bat C:\test\test.vbs C:\test\test1 C:\test\test\aslfaa.mod C:\test\test\sdlfjasf.mod C:\test\test\test.asfklhasl C:\test\test\test1 C:\test\test\test2.doc C:\test\test1\123.mod C:\test\test1\3231.mod C:\test>dir c:\tmp Volume in drive C has no label. Volume Serial Number is 08AC-4F03 Directory of c:\tmp 10/30/2009 11:20 AM <DIR> . 10/30/2009 11:20 AM <DIR> .. 0 File(s) 0 bytes 2 Dir(s) 4,733,227,008 bytes free C:\test>cscript /nologo test.vbs C:\test>dir /B /S c:\tmp c:\tmp\123176457.mod c:\tmp\323114370.mod c:\tmp\aslfaa254512.mod c:\tmp\sdlfjasf277152.mod it works for me. any discrepancies at your side is your own doing.Quote from: gh0std0g74 on October 29, 2009, 09:17:01 PM since you insist. . . |
|
| 3178. |
Solve : How to run stored procedure from dos command? |
|
Answer» Hi Hi no matter what database you are using, mysql, sql server , sybase etc, they COME with documentations. The first thing you should do is read them and see how to execute stored proc from the command line. Appriciate your promt reply. I could find sqlcmd utility and will explore more on this. Yes BASICALLY they are SQL statements i.e. *.sql file which i normally execute on batch of databases. Comming to more specific requirement: I have say couple of sql files (variable) which needs to be executed on batch of database (variable). For sql files (variable) - i will keep this files in one local folder. For database (variable) - i will keep the information about dbs and their server in one txt file. Now i want to create one batch file i.e *.bat which will execute 'sqlcmd' picking up *.sql files from folder and database information from the txt file. How can i achieve this Information on this will be much appriciated. |
|
| 3179. |
Solve : for somthing = %%a? |
|
Answer» Hi All, I have write batch to dir my folders in every DRIVE at pc. so far I write it in this way @echo cd\ c: pause dir c:\ @echo pause d:\ dir d:\ pause e:\ dir e:\ I would like to find out any other way to dir all drives without naming this drives. This might help you out. Code: [Select]@echo off for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"') do ( dir %%i: ) for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "dvd-rom"') do ( dir %%i: ) for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "removeable"') do ( dir %%i: ) For network drives use net use. You can use the same technique to filter the output. Good luck.I think you spelled removable wrong. That may be an issue if the op tries to dir a flashdrive. Au contraire. I can't make this stuff up but Microsoft can. Quote C:\Temp>echo list volume | diskpartQuote I think you spelled removable wrong Quote I can't make this stuff up but Microsoft can. This has been discussed in various places. The spelling seems to be a USA vs rest-of-the-world thing, rather like color/colour, center/centre, meter/metre etc; UK English dictionaries tend to give the spelling without a second 'e' but "removeable" is a fairly widespread variant spelling in the US. Merriam-Webster says: 3 : to be capable of being removed — re·mov·abil·i·ty \-ˌmü-və-ˈbi-lə-tē\ noun — re·mov·able also re·move·able \ri-ˈmü-və-bəl\ adjective — re·mov·able·ness \-ˈmü-və-bəl-nəs\ noun — re·mov·ably \-blē\ adverb — re·mov·er noun Quote The spelling seems to be a USA vs rest-of-the-world thing, rather like color/colour, center/centre, meter/metre etc Could be, but the MS Word 2002 (XP) spell checker shows the correct spelling as removable. All in all it makes no difference. When dealing with data, you've got to handle it as it is.Quote from: Sidewinder on October 21, 2009, 04:50:38 PM Au contraire. I can't make this stuff up but Microsoft can.Hmm...is that a MS world-wide thing? I haven't noticed that and my regional settings are set to canada (I think). Quote from: Sidewinder on October 21, 2009, 12:35:53 PM This might help you out. thank you for your help .. and I tried this but I get an error ? that :Application data "dir" is not recognized as an internal or external command, operable PROGRAM or batch command file. Not sure what :Application data indicates. The code was designed to run from the prompt in a cmd window. Need more details. A copy and paste of the error message and what went before it would be most helpful. Quote from: Sidewinder on October 26, 2009, 07:17:37 AM Not sure what :Application data indicates. The code was designed to run from the prompt in a cmd window. Need more details. A copy and paste of the error message and what went before it would be most helpful. here in below a copied of error massage Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\ammmmm>@echo off for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"') do ( %%i was unexpected at this time. "Application Data"dir %%i: '"Application Data"dir' is not recognized as an internal or external command, operable program or batch file. "Application Data") '"Application Data")' is not recognized as an internal or external command, operable program or batch file. for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "dvd-rom"') d o ( %%i was unexpected at this time. "Application Data"dir %%i: '"Application Data"dir' is not recognized as an internal or external command, operable program or batch file. "Application Data") '"Application Data")' is not recognized as an internal or external command, operable program or batch file. for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "removeable"' ) do ( %%i was unexpected at this time. "Application Data"dir %%i: '"Application Data"dir' is not recognized as an internal or external command, operable program or batch file. "Application Data") '"Application Data")' is not recognized as an internal or external command, operable program or batch file. thank youApplication data is a directory immediately below the username directory in documents and settings. I haven't a clue how that error message was generated. From what I can tell, you are typing this in at the command prompt, (I read you wanted a batch file) in which case you should only use single % signs and the do instruction with at least the open paren should be on the same line as the if, otherwise the interpreter has no clue that the line is incomplete and requires more. When typing at the command line: Code: [Select]d:\wfc\testlib>for /f "tokens=3" %i in ('echo list volume ^| diskpart ^| find /i "partition"') do ( More? NOTE: It appears the for intruction is two lines long, however the interpreter sees the line as one logical line that requires completion. I suggest you copy/paste the code I posted earlier into an editor, create a batch file, and then run run the batch file. |
|
| 3180. |
Solve : my favorites? |
|
Answer» Hi all, I have a list of web SITES and I am TRYING to write batch file to add all this sites in this list to my favorites or enable me to BROWSE all web sites in this list. I have no IDEA where should I start. any HELP? Hi all, any idea with that?see here for example |
|
| 3181. |
Solve : add current date/time to filename? |
|
Answer» Hi there. |
|
| 3182. |
Solve : Create zip/rar file? |
|
Answer» Hi! I allready have the answer: If you already have the answer, why did you ASK the QUESTION? @dias, please enjoy your life more. little things like this shouldn't upset you at all.OK, let's assume the OP didn't mean "I already know how to do this". You can use rar.exe which comes with WinRAR, or the command LINE program addon for Winzip. Which one were you thinking of? Quote from: gh0std0g74 on April 07, 2009, 09:06:42 AM @dias, please enjoy your life more. little things like this shouldn't upset you at all. Wth?Quote from: Carbon Dudeoxide on April 07, 2009, 09:12:04 AM Wth? Ghostdog acting like he had 250000 posts instead of 25. Quote from: Carbon Dudeoxide on April 07, 2009, 09:12:04 AM Wth?Quote from: Dias de verano OK, let's assume the OP didn't mean "I already know how to do this".get it?Quote from: Dias de verano on April 07, 2009, 09:13:59 AM Ghostdog acting like he had 250000 posts instead of 25.what has post count got to do with it?Quote from: gh0std0g74 on April 07, 2009, 09:22:43 AM what has post count got to do with it? Big post count=big man (me). Little post count=little boy (you). Quote from: Dias de verano on April 07, 2009, 09:26:38 AM Big post count=big man (me). Little post count=little boy (you).you should know who i am. I just changed "O" to 0. Post count doesn't matter. Quote from: gh0std0g74 on April 07, 2009, 09:29:38 AM you should know who i am. I just changed "O" to 0. Post count doesn't matter. I know who you are. Quote from: Dias de verano on April 07, 2009, 09:33:31 AM I know who you are.glad to hear that.You're the guy who turned the 'O' to '0'.He tried to make his girlfriend say OH! but what she actually said was zeroQuote from: Dias de verano on April 07, 2009, 08:57:05 AM If you already have the answer, why did you ask the question? Sorry about that.. Only after i post the problem i've MANAGE the answer. I keep this post to someone with this kind of question.. Anyway, this way i can zip a file...what about zip an entire folder? Anyone? |
|
| 3183. |
Solve : current folder name? |
|
Answer» i've got a problem again I am not sure why BillHat wrote what he did. TO: All Hat and No Cattle: In Texas we always show at least part of the Output. In Canada the OUTput is not required? MANY new users do not know how to test code. No need to test Code by the Ghost. The Ghost code never CHECKS out. Show and Tell is required when we are new users from Texas. Not everybody is as dumb as you think. I believe my code is SELF explanatory. Quote from: Salmon Trout on October 30, 2009, 12:10:35 PM Not everybody is as dumb as you think. I believe my code is self explanatory. There are many new users who read these boards and a little extra show and tell helps. Not knowing and stupid are not synonymous. "Everybody is ignorant. Only on different subjects." Will Rogers |
|
| 3184. |
Solve : Batch file help?? |
|
Answer» I ALREADY POSTED this in the programming section by mistake, sorry. While I do appreciate Sidwinder's help, it just didn't work. |
|
| 3185. |
Solve : Need help for insert? |
|
Answer» I want to insert text in front of every lines. Is there anyone know how to do easy batch file?@echo off>newfile.txt @echo off>newfile.txt thanks for your help. It's work but if I have so many files in the DIRECTORY then I want to insert text for every files. Is there any other varibles that I have to put in?use another loop to go through all your files.Quote from: akeker on April 08, 2009, 12:57:59 AM thanks for your help. It's work but if I have so many files in the directory then I want to insert text for every files. Is there any other varibles that I have to put in? Code: [Select]@echo off for %%$ in (*.txt) do ( echo Processing %%$ --^> new_%%$ 2>new_%%$ for /f "tokens=*" %%a in (%%$) do >>new_%%$ echo whatevertext%%a )Quote from: Reno on April 08, 2009, 01:10:47 AM Code: [Select]@echo off Thanks again. it's work very well indeed. I wish you have all you want. |
|
| 3186. |
Solve : FTP Filedownload? |
|
Answer» I am creating this BATCH file to download an file which is one day older to today's date and I am not able to execute the file because of some errors. can you please follow the below program and LET me know where I am going wrong. |
|
| 3187. |
Solve : Batch script to check if last modified date is earlier than current day? |
|
Answer» I need to create a batch file to check the last modified date of a directory and if it's older than the current date i need to execute foo.com. Can someone assist? Ya, I'm a Linux adminif you have been a linux admin AND if you can use *nix stuff on your WINDOWS environment, you can download GNU tools (SEE my SIG) and use them. After that i am sure you know how to use GNU find to search for files older than 30 days and delete them |
|
| 3188. |
Solve : Running multiple bat files at the same time, and then run a separate bat file.? |
|
Answer» Hi. |
|
| 3189. |
Solve : How do i check a file existency in a folder/directory? |
|
Answer» I WANT to CHECK the file existence in a file or FOLDER using DOSuse if EXIST. type if /? for more info.thanks got it. |
|
| 3190. |
Solve : existent directory? |
|
Answer» Dear |
|
| 3191. |
Solve : how to asign dir result to the variable? |
|
Answer» how could i ASIGN dir result to the variable how could i asign dir result to the variable i have a question for you. what do you want to do with those directory listing results? are you going to find files ? If say you have 10000 files under the directory, are you going to assign all these files a variable each ?? Quote from: animo on October 30, 2009, 03:15:11 AM how could i asign dir result to the variable We cannot assign all the filenames in a directory to one variable. Usually only one line from a file to each variable. Quote from: animo on October 30, 2009, 03:15:11 AM how could i asign dir result to the variable Where did Animo go? Ask a question and leave the room? A variable is a storage location in RAM ( Random Access Memory ). The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ). When you shut down the information disappears. A file is a memory location on the Hard Disk. The information remains after shut down. Why would anyone expect to store all the information from a file in a variable location? Your basic understanding of computers is not present. Quote Your basic understanding of computers is not present. And some people can't separate a quote from their own reply. Quote from: billrich on October 30, 2009, 04:21:45 PM separate your quotes from your replies. Its annoying. Quote The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ).this has nothing to do with the question. Besides, the above is statement is wrong. The amount of information we can store in a variable is as equivalent to how much memory the computer system has. If you read a text file line by line and store into different variables for each line, you ARE basically using memory for the whole file. Get your PERSPECTIVE right. Also, there are functions in programming languages that reads the whole file into one big variable for the purpose of convenience, but ultimately, storing to many variables or one variable are both the same, they are both still using up memory. Quote from: billrich Your basic understanding of computers is not present.the pot calling the kettle black.Quote from: gh0std0g74 on October 30, 2009, 06:39:13 PM Pot and Kettle. Animo(OP) wrote "set /a result=`dir /b /o:n"` Animo wrote: "How could I assign dir result to the variable The above does not work." Bill wrote: "We cannot assign all the filenames in a directory to one variable with the for loop in Batch." "Usually only one line from a file to each variable." Bill Wrote: The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ). Ghost wrote (Fed by BC) : "This has nothing to do with the question." Bill explains: Read what Animo (OP) wrote above: Animo was trying to assign all the files in a directory to one variable ( Result ). Ghost wrote "Besides, the above is statement is wrong. The amount of information we can store in a variable is equivalent to how much memory the computer system has. If you read a text file line by line and store into different variables for each line, you ARE basically using memory for the whole file. Also, there are functions in programming languages that reads the whole file into one big variable for the purpose of convenience, but ultimately, storing to many variables or one variable are both the same, they are both still using up memory." Bill wonders: "What does the above have to do with Batch?" No, Ghost you are wrong but you do not use Batch. The Batch for loop will allow only one line to be assigned to each variable. So, what The Ghost writes has nothing to do with Animo's (OP) question. GHOST, What is this about a Pot and Kettle? This has come up before. If you have a huge amount to information that you need to store, common practice is to put into some kind of database that can be stored as a file. For practical reasons the number of variables you can have is limited. If you use a FOR loop and the variables are part of the FOR structure, the limit is 26 variables. A vailable should not be over 128 characters., says one reference. Some versions of ODS put a limit to the amount of memory that will be assigned to variables. Yet if the OP wants to put the names of all the directories into some variables, he can do that. Maybe we don't know why, but it can be done. Anyway, being rude to anyone has little value here. Quote from: billrich on October 30, 2009, 08:17:50 PM Bill Wrote:i say again. The amount of information you can store in a variable is unlimited, its only limited by the amount of physical RAM you have on your system!!! Whether or not DOS batch only read one line each time from a file is not the problem. I don't do batch , BUT i certainly know how to PROGRAM. Code: [Select]@echo off setlocal enabledelayedexpansion set var= for /f "delims=" %%a in (file) do ( set line=%%a set var=!var! !line! ) echo The file contents are: %var% Since you are a so called batch guru, i assume you can see that %var% is one big variable, now containing all the lines of the file. Now, do you understand what this means??? Quote GHOST, What is this about a Pot and Kettle?now i have to give you english lessons? go figure out yourself.Quote from: gh0std0g74 on October 30, 2009, 08:56:50 PM Code: [Select]@echo off Who wrote the code? Salmon Trout? Excellent. Did you provide a copy to Animo, the original Poster? I never claimed to be a "Batch Guru." I had not used batch until I logged on here several months ago. I'm 72. I don't work. Where does Ghost work as a Programmer? Ghost, read post #8 by Geek above. Quote from: billrich on October 30, 2009, 09:20:18 PM Who wrote the code? Salmon Trout? Excellent. Did you provide a copy to Animo, the original Poster?anyone who knows how to write batch will know its a "standard way" to concatenate lines to one variable. Why should i provide a copy to OP? you are ridiculous. whether i want to provide solutions is my own business. Quote I never claimed to be a "Batch Guru." I had not used batch until I logged on here several months ago.that's why i have written "so called batch guru". which implicitly means i am saying you are not. Quote I'm 72. I don't work.that's why you have plenty of time trolling around. Quote Where does Ghost work as a Programmer?what gives you the idea that i am a programmer? Does it mean i need to be a programmer in ORDER to program? Quote from: animo on October 30, 2009, 03:15:11 AM how could i asign dir result to the variable C:\batextra>type vardir.bat Code: [Select]@echo off REM code by unknown setlocal enabledelayedexpansion dir /b /o:n > dirvar.txt set result= for /f "delims=" %%a in (dirvar.txt) do ( set line=%%a set result=!result! !line! ) echo. echo The directory contents assigned to result variable: %result% OUTPUT: C:\batextra>vardir.bat The directory contents assigned to result variable: .uvwrap_v301.swf .uvwrap_v3 02.swf .uvwrap_v303.swf .uvwrap_v304.swf .uvwrap_v305.swf 2009.January.blanks 20 09.January.dotfile 2line.bat 2pdfdos.bat A.bat anecho.bat ans.bat AUTOEXEC.BAT B .bat Batch1.bat batchname.bat batexe.bat batfile.bat bc.bat bcalc.bat beep.bat b est.bat bill0910.bat bill0911.bat bill72.bat bill72.txt Blues.wma brost.bat BSET Bver.bat caavsetupLog.txt caisslog.txt carbon.bat caret.bat caseyville.gif chan gename.bat chkqo.bat choice.bat christmas.txt clear.bat clock.bat CONFIG.SYS cop yfiles.bat copytxt.bat cosmic.bat count.txt countf.bat countword.bat dalete.bat data.csv data06.txt date.txt datefile.bat datename.bat daydir.bat db.txt del3sec .bat delnet.bat desk.bat dev.bat devstr.bat devtok.bat devtwo.bat devtxt.bat dev u.bat Dias.bat digit.bat dir dirtree.bat dirvar.txt disklog.txt Divide.bat Docum ents dostimer.bat drive.bat echprom.bat envvar.bat err.bat evaluate.bat evaluate .vbs expand.bat extractfolder.bat field1.bat fiels1.bat fifty.bat file.bat file. txt filelen.bat fileprop.bat filetovariable.bat finalstr.bat finalziplist.txt fi nddir.bat findstring.bat findxfiles.bat FlashSavingPluginSetup.exe fold.bat fold 1 fold2 fold3 fold4 fold5 folder1 folder2 folder3 folder4 folder5 for.txt found. bat FP.vbs g.bat game.bat gee.bat generatebat.bat ghost.bat gkata.bat go.bat goo glemath.bat gotoline.bat h3.bat hello.bat helpme.bat helppetty.bat hi.bat his.ba t hist hist.txt hmath.c homewk.txt homework3.bat hope.bat htmldrive.bat inc.bat indent Instruct_for.txt jak.bat kaus.bat kay.bat Keeptime.bat lewbat.bat line.ba t list_of_program_files.txt list2a.txt listone.txt log log.txt longshot.doc lw.b at mac.bat macdir.bat main.bat map.bat map2.bat mapodd.bat match.bat math.bat ma th2.bat menu.bat Menuhope.bat MenuHope.txt mon.bat mon.txt monnum.txt mpgname.ba t MSDIR.bat msin.bat mwc.bat mydate.bat namedate.bat New Stories (Highway Blues) .wma newbat.bat newname.bat nomodname.bat noperiod.txt notime.bat null old.bat o ldfiles.bat orastr.bat outmenu.txt parsedate.bat particular.bat pdfdos.bat perio d.bat period.txt PID_446170_AFIQ3Q4_RMOLA_MMY_160x600.sw f PID_446170_AFIQ3Q4_RMO LA_MMY_160x600_Parent.swf pipe.txt playsong.bat pp.bat preloader.swf preloader01 .swf preloader02.swf progressbar.bat prtbat.bat psexec.exe quote.bat renamejpg.b at renjpg.bat reno.bat replace.bat reploop.bat reveille.mp3 rmext.bat rmnum.bat rmnum2.bat runany.bat safexp.zip save screenclean.swf sendfile.bat session.txt s etvar.bat sfc SH_HISTO shakeit.gif show.bat show.txt shut.bat Sig.gif signal.txt signature signature.htm sigop.gif sleep.exe sortdir.bat sortdir.txt sound.swf s tartsig.bat str.bat str2.bat str3.txt strcat.bat striptime.bat strlen.bat succes s.bat sumnum.bat TAPS.mp3 task.txt taskkill.exe tasklist.exe Tata.jpg tehthe.bat temp.tmp temp1.txt tes3.bat tes4.bat test.bat test06.bat test07.bat test07.txt test10.bat test18.bat testextract.bat testfilnam.txt TestLog.csv testnum.bat tes tver19.bat testwhat.bat textsearch.bat timediff.bat timeinseconds.bat timest.bat tips.txt tooktime.bat try.bat try06252009.bat try07182009.bat try07302009.bat t wodate.bat uvwrap_v3.swf val.bat val20.bat valarie.bat vardir.bat vars.bat vartx t.bat vbprop.bat verp.bat volis.bat wait1.bat wait10.bat wait2.bat wait5.bat wai ttime.bat walkthetalk.swf wget.bat whatd.bat whatis.bat win.ini winder.bat windo wsupdateagent30-x86.exe wmp.bat writetofile.bat x.txt x3.bat xc.bat xcc.bat xfif ty.bat xinc.bat xlw.bat xmas.txt xplaysong.bat xsignature.htm xtry.bat xxsignatu re.htm xxtestfl.bat xxx.txt xxxmenu.bat xxxxx.bat xy.bat y y.htm yourfile.bat z. txt zeke.txt zip.bat zip2.bat ziplist.txt zzero.bat C:\batextra> |
|
| 3192. |
Solve : start two batch files at the same time? |
|
Answer» How can i write a batch file which start two batch files at the same time? Code: [Select]start abc.bat That doesn't work. It just opens the command PROMPT. If you want to open at the same time, try this. Code: [Select]start cmd /c abc.bat start cmd /c def.bat That will open them up in their own window, and your first script can continue running (3 windows open).Quote from: Helpmeh on April 06, 2009, 05:56:40 AM That doesn't work Yes it does. abc.bat Code: [Select]@echo off echo This is abc.bat echo hello world def.bat Code: [Select]@echo off echo This is def.bat echo goodbye world xyz.bat Code: [Select]@echo off Echo this is xyz.bat start abc.bat start def.bat Result... Wierd...that just opens 2 instances of the command prompt.Quote from: Helpmeh on April 07, 2009, 07:08:20 PM Wierd...that just opens 2 instances of the command prompt. Are abc.bat and def.bat in the same folder as def.bat? Do they contain any commands? I say, you've got Consolas as your Command Prompt Font too. It's a secret to everybody... Quote from: BC_Programmer on April 08, 2009, 12:35:27 AM I say, you've got Consolas as your Command Prompt Font too. I cannot stand the default font! The raster one I mean. I used Lucida Console for a long while, toyed with Courier New for a bit, but Consolas is my favourite. I don't like WHITE text on black background either. I use Lucida Sans Typewriter in my text editor (Ultraedit32). I switched to Consolas in VB6... courier new LOOKS like crap now! I just wish the IDE had more options for colours and such; or DIFFERENT settings, such as bold and italic for it's syntax colouring. Oh well. I had "Inconsolata" for a bit, but then I FOUND the free MS download of Consolas so I can use it on XP. before I decided on consolas I toyed around with "proggy fonts": http://www.proggyfonts.com/index.php?menu=download for me, they are simply too small. I'm not sure what the raster font really is, but if I had to guess I'd say it mapped to "system"... which I might add was the default, unchangable font in Visual Basic version 1 through 3. I guess MS realized with 4 that the font blew hard.Quote from: Dias de verano on April 08, 2009, 12:23:13 AM Are abc.bat and def.bat in the same folder as def.bat? Do they contain any commands?Yes and yes. |
|
| 3193. |
Solve : how do I disallow a null entry from a user?? |
|
Answer» Here is what I have : Does that work if a "return" or "enter" is pressed? It will ONLY work if Enter/Return is pressed. The set /p command requires either a string of characters terminated by Enter, or Enter alone. The "null string", represented by "", is another way of saying "Enter". THANK you -- appreciate the explanation!That worked! Thanks for your help. |
|
| 3194. |
Solve : How do I ask for input from user and output to a file?? |
|
Answer» I am looking to have a batch FILE run at logon which would ask a USER for his name and then OUTPUT it to a log file. I am unsure how to do so.Code: [Select]@echo off |
|
| 3195. |
Solve : Help with creating this Batch file? |
|
Answer» cd\ for deleting files older than blah date, that's one extremely slow batch script. So are you wanting to say the files will be too OLD by the time the batch gets to the end? LOL! . Which brings up an issue. Anytime you want to find something that is exactly N hours, days, months old, you will have a logical failure. From the time the program STARTS until it ends there may be a probability that some file will fall out of the time frame. This is an ERROR IN LOGIC.thanks for that joke, but no, its definitely not what i meant. |
|
| 3196. |
Solve : Creating a backup bat? |
|
Answer» Okay so we were doing dos for a while and there was issues with the machines that we were using so we have just stayed with linux for a while in my class. The thing is that I understand how to do it for the most part. I have xcopy S D /y /s /v But I also need it to be a desktop icon that will launch it when clicked, I am not at my machines so sadly not sure how much of this will work at all.Quote from: squall_01 on April 08, 2009, 12:12:04 PM I have xcopy S D /y /s /v But I also need it to be a desktop icon that will launch it when clicked, 1. Put the commands you want to run, into a .bat or a .cmd file. 2. Save it to the desktop. let me refrase that OH I suppose it is that easy. Okay so FORGET it then just wondered if I wasnt missing anything as well.Quote from: squall_01 on April 08, 2009, 12:22:15 PM let me refrase that oh I suppose it is that easy. Okay so forget it then just wondered if I wasnt missing anything as well. Yes it is that easy. If you do not want to put the actual batch on the desktop you can open Explorer, open the folder where the batch is located, right click the batch file icon and drag it out of Explorer ONTO the desktop, and when you let go the mouse button to drop it, you can choose "create shortcut here". You can rename the shortcut to anything you like and choose it a different icon if you want, but it will still point at the batch file, which (obviously) needs to remain in its location. Probably what he was GOING to have us do. One thing I made the batch and told it to run with out ECHO off the thing is that I told it to copy one file and it starting coping a whole lot then it just like goes away from the disk. |
|
| 3197. |
Solve : Editting a BAT?? |
| Answer» OKAY I done this batch files on a seperate machine and instead of going to them cause I would be going from ONE room to another, wondered what the code would be to change them I am USING 6.2 usally editted it in NOTEPAD but that isnt there.editah FORGOT that I did see that some were just never need it till know. | |
| 3198. |
Solve : Logging a folders content size?? |
|
Answer» I am looking for a way to log a folders content size such as C:\squid\var\cache for the Cache folder to log the size of the Cache storage. I was thinking I could use DIR and a switch to output the size, and Icant remember how I did it a long ways back. Would be nice to export the echo from the command for the folder size to a log file such as below, when executed from C:\squid\var\cache\
Executed from a folder, Dir shows the names of any subfolders, and the names, dates and sizes of any files present in the folder, and the total size in bytes of the files in the folder only. S:\Test\Batch>dir Volume in drive S is USBHD Volume Serial Number is 2C51-AA7F Directory of S:\Test\Batch 26/09/2009 20:46 <DIR> . 26/09/2009 20:46 <DIR> .. 28/10/2009 21:02 <DIR> After 07-09-09 07/09/2009 17:13 <DIR> Older 15/05/2009 06:52 <DIR> EditVS 15/05/2009 06:56 <DIR> sst26 27/05/2009 17:56 116 Finder.bat 26/09/2009 20:46 44 getp2.bat 18/09/2009 16:51 217 isfolder.vbs 15/09/2009 17:48 46 ddf.vbs 09/05/2009 07:56 78 rarhelp.bat 25/05/2009 18:58 37 dequote.vbs 23/06/2009 19:34 245 Edit3 7 File(s) 783 bytes <----------------------------------------- 6 Dir(s) 146,969,190,400 bytes free Are you saying you want to know the amount of data in each subfolder? Hello...Yes I want to know how much total combined within local folder Cache and subfolders. I added a screenshot to show the subdirectory structure. I was thinking that maybe a DIR would have to be run against each sub directory and the sum of the files within it passed to a variable for every sub-folder/directory then the variables all added up at the end to give the lump sum of all data contained within Cache as the physical size of that folder and its sub-folders. (( But there has to be an easier method I am thinking )) [Saving space, attachment deleted by admin]Are you able (permitted) to use the Sysinternals du utility? http://live.sysinternals.com/du.exe if so I will rough out a batch file see my sig (GNU tools). Download and use them. It includes du command, plus others such as find (that is way better than Windows own), stat, etc you can use to show you sizes of files and folders. Of course, only if you are allowed to.Hello Salmon...sure I am sys admin and can run that. So if you can show a way to use DU and do that, that would be awesome. just type du c:\ for example on the command prompt. if you want, use a for loop to grab results. simple as that.Quote from: gh0std0g74 on October 31, 2009, 02:14:39 AM just type du c:\ for example on the command prompt. if you want, use a for loop to grab results. simple as that. Yes indeedy. Play around to get the syntax clear. Du /? to see help, where the various switches available are explained. (I am using the Sysinternals du.exe) Code below shows: You can use the -q switch to prevent the Sysinternals copyright message (which, incidentally, if enabled echos to stderr not stdout) I use quotes around folder names as good practice in case of spaces Can pipe through Find "Size:" to get the line with file size Comma separated file(s) size in bytes is 2nd token in that line Remove commas from size to make suitable for set /a Code: [Select]set dirname=C:\squid\var\cache for /f "tokens=1-2" %%A in ('du -q "%dirname%" ^| find "Size:"') do set foldersize=%%B set foldersize=%foldersize:,=% i would recommend the GNU version since it has more capabilities and more or less works on a *nix with GNU as well.The Sysinternals version is simpler to manipulate (I have both) but as you say the GNU version is less limited (no commas in output. Another thing to consider might be DIRUSE from the NT Resource Kit http://support.microsoft.com/kb/927229 Code: [Select]D:\Audio-DL>diruse /s "Amaral Discografia" Size (b) Files Directory 23503006 1 AMARAL DISCOGRAFIA 45934192 13 AMARAL DISCOGRAFIA\Amaral 216104622 46 AMARAL DISCOGRAFIA\split-IOtest 73095739 13 AMARAL DISCOGRAFIA\Una Peque±a Parte del Mundo 358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA 358637559 73 TOTAL: AMARAL DISCOGRAFIA D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:" 358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA 358637559 73 TOTAL: AMARAL DISCOGRAFIA D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:" | find /V "SUB-TOTAL:" 358637559 73 TOTAL: AMARAL DISCOGRAFIA Code: [Select]D:\Audio-DL>du -v "Amaral Discografia" Du v1.31 - report directory disk usage Copyright (C) 2005-2006 Mark Russinovich Sysinternals - www.sysinternals.com 44,857 D:\Audio-DL\amaral discografia\Amaral 211,039 D:\Audio-DL\amaral discografia\split-IOtest 71,382 D:\Audio-DL\amaral discografia\Una Peque±a Parte del Mundo 350,231 D:\Audio-DL\amaral discografia Totals: Files: 73 Directories: 3 Size: 358,637,559 bytes Size on disk: 358,637,559 bytes Code: [Select]D:\Audio-DL>gnuDU -b -c "Amaral Discografia" 45934192 Amaral Discografia/Amaral 216104622 Amaral Discografia/split-IOtest 73095739 Amaral Discografia/Una Peque±a Parte del Mundo 358637559 Amaral Discografia 358637559 total D:\Audio-DL>gnuDU -b -c "Amaral Discografia" | find "total" 358637559 total Cool... Thanks for your help guys. Going to play with it and learn it.Quote from: Salmon Trout on October 31, 2009, 03:41:14 AM The Sysinternals version is simpler to manipulate (I have both) but as you say the GNU version is less limited. Another thing to consider might be DIRUSE from the NT Resource KitQuote from: Salmon Trout on October 30, 2009, 11:01:42 AM Executed from a folder, Dir shows the names of any subfolders, and the names, dates and sizes of any filespresent in the folder, and the total size in bytes of the files in the folderonly.I bolded the text that the op wants. It seems that even though salmon put it in red, no one noticed. that part only shows the size in the CURRENT directory. how about the rest of the directories? you have to individually go into each directory under s:\test\batch and get those sizes and add them up. Extra coding, extra brain cells killed. Quote from: gh0std0g74 on November 01, 2009, 05:13:10 PM that part only shows the size in the current directory. how about the rest of the directories? you have to individually go into each directory under s:\test\batch and get those sizes and add them up. Extra coding, extra brain cells killed. Yes, I wrote a huge batch that went one level deep doing just that before I remembered I had du and diruse. You can even use xcopy in list mode but that is probably just as tedious as using dir. |
|
| 3199. |
Solve : Find out how many times a Batch is used.? |
|
Answer» that works- I still like my alternate datastream IDEA, though. How about this: How about this: Why use FOR, when if does the trick. Simple: Code: [Select]if not exist times.txt echo 0 > times.txt set /p times=<times.txt set /a times+=1 echo %times% > times.txtQuote from: HELPMEH on April 07, 2009, 06:55:33 PM Why use FOR, when if does the trick. I suspect its 6 of one, but I didn't know you could do that with set /p. COOL tip. Thx \\uSlackrQuote from: uSlackr on April 07, 2009, 10:13:21 PM I suspect its 6 of one, but I didn't know you could do that with set /p. Cool tip. I think that set is the most usefull COMMAND (that I can use...) |
|
| 3200. |
Solve : USB token Security? |
|
Answer» hI ! to all i want to make USB token Security. Like that i insert my PENDRIVE it DETECT but all other pen drive can't detect in my PC. Because my friend load Trojan in my computer system via pendrive. it is possible ? Pls Help me... Here are some of the USB security TOKENS available....... Just have a LOOK at them http://www.eyenetwatch.com/USB_hard_drive/security_tokens.htm i don't want to purchase any thing.. i want make pen drive like this..... |
|