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.
| 7651. |
Solve : Batch - Count processes? |
|
Answer» Can someone help me with counting the number of opened processes of hlds.exe H:\>find /? |
|
| 7652. |
Solve : Use control key in batch file? |
|
Answer» hi |
|
| 7653. |
Solve : file name never exists? |
|
Answer» Hi all, Perfect! Thankyou! I havent made a batch file in a while, i knew to use brackets on the IF statements i just assumed it would be the same for the IF EXIST You don't have to use brackets around the things being compared in IF statements. You can use most of the character set EXCEPT for the special characters such as <>& etc. Most people use double quotes like this IF "%variable%" == "" IF "%animal%" == "horse" etc Oh, i didnt know that. Thanks!In fact you don't have to use anything surrounding a variable if you are comparing one thing with another e.g. if %animal% == horse if %var1% == %var2% etc. If you use bare variables you will be all right until one of them happens to be blank in which case the script will fail, which is why many batch CODERS routinely surround them with quotes or other characters in IF tests. Just keep the other characters away from filenames. Of course you do need to surround the variable if you are comparing one thing with nothing (a blank) if "%animal%" == "" if .%animal%. == .. if [%animal%] == [] |
|
| 7654. |
Solve : Can I shut down my LapTop from DOS like the Win95/98 does it?? |
|
Answer» Hello! |
|
| 7655. |
Solve : Manipulate Output of Find /C command? |
|
Answer» I need to run a script that does the FOLLOWING: so you can see the single quotes than enclose the command That's: "so you can see the single quotes that enclose the command" Salmon Trout - Thank you! This works perfectly. I really appreciate the explanation of what the commands do as well. Even if I had tried using parenthesis I wouldn't have used the single quotes around wlbs query . . . Very helpful, thank you. MJ |
|
| 7656. |
Solve : [Batch] Hide program from taskbar ?? |
|
Answer» exact CODE please :X? exact code please :X? You sound like a clever GUY, I bet you can WORK it out. |
|
| 7657. |
Solve : Lock Your Pendrive/Thumbdrive with Batch Program? |
|
Answer» Hi to all, so long im not visit this forum. Instead of this you can use a single software to secure your pen drive usb even cdc and dvds... Any free alternative?after double click the bacth file its make me a virus in pendrive......what to do |
|
| 7658. |
Solve : DOS batch file - Display popup message with two choices? |
|
Answer» Using a DOS batch file I'd like to display a popup window in XP and Windows 7 where I display a message and give the user the choice to press one of two buttons - one would stop the DOS batch file, while the other button would allow it to CONTINUE. Any hint on what dos batch command/pgm I may use?Windows command language does not have popup windows with buttons but you can use a batch/Visual Basic Script hybrid to do this. |
|
| 7659. |
Solve : using batch/PSexec to run sequence of installs? |
|
Answer» Hello to all,
Any assistance would be greatly appreciated. THANKS! TimNot all versions of Windows have WMIC and the OSARCHITECTURE option is only available in Vista and above.Thanks for that. OK. How can i determine OSarchitecture on WINXP machines? What other apoproach could i use for this whole PROCESS?? Thanks, Tim Quote from: tstimple on May 07, 2012, 10:24:31 AM Thanks for that.Well let me ask you this. What are the odds of any of your computers running XP 64bit. I don't know to many companies that do run that. Heck we don't even run Windows 7 64bit where I work.Well here I have over 100 machines running 64bit. Most are windows 7 but even a few winXP-64 Does "systeminfo" command work on XP? Could i use that to determine bit structure? Tim In all 64 bit Windows if there is a folder CALLED "%systemdrive%\Program Files (x86)" then you have WOW64 and therefore a 64 bit operating system. The command that PSEXEC executes must be included in the line; if you JUMP out to a label you have quit. |
|
| 7660. |
Solve : Comparing two directories? |
|
Answer» I want to be able to compare two directories from a command line like if I wrote a batch file for copying a whole directory and then comparing them. I have found "comp" and "fc"but those only compare specific files and there are a TON of files in the directories I want to compare. Is there a command to be able to compare two directories and all their sub directories? Quote I understand that the "for statement" is for, for "given code" do "this." But could you explain "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b'), specifically tokens, delims and what the %%v is doing? tokens=* TELLS the interpreter there is a single variable (%%v) and all the data on each line from the dir command is to be stuffed into that variable delims=" overrides the DEFAULT delimiters which are space and tab If you run the dir command from the prompt, you'll see the output appears as: filename1.ext filename2.ext file name3.ext . . . By overriding the default delimiters and and declaring a single variable, each iteration of the for loop PUTS a filename into %%v (including filenames with embedded spaces) Quote If their are files in both we get the first message but if it does not we get the second message, will this work all the way through the directory tree? Nope; as written compares folderA to folderB, then FolderB to FolderA. Did you check out rSync? Might be a better solution with recursed directories. Good luck, rsync might work but sense this is a network server and not a personal computer for myself I would rather not install anything new. Plus this is not sync per say. I am copying the files from one location to another, confirming they are there, and then deleting the original directory. The copy is easy I just use xcopy xcopy C:\FolderA\*.* G:\ /E Which copies everything from the first directory to the second directory including all sub directories. Then after a little manipulation I will run your code to compare the two directories before the deletion. My next question is if I use how do I delete everything below a certain point in the directory? I have tried del but it wants a specific file and I have tried rmdir but it deletes that directory and I want to keep it just remove everything below it so in the end it is a empty directory. Could I do something like this? for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (del "c:\FolderA\%%v ) Thanks for your help! Quote My next question is if I use how do I delete everything below a certain point in the directory? Quote Could I do something like this? Del works only with files. RD works with FOLDERS. One way to approach this would be to get the collection of files in FolderA and delete them. Then go back and get the collection of folders in FolderA and remove the sub-folders and their files. Code: [Select]for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /a:-d /b') do ( del "c:\FolderA\%%v ) for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /a:d /b') do ( rd "c:\FolderA\%%v /s /q ) The snippet should leave you with an empty FolderA. I would encourage you to test this before committing to production. Good luck. There seems to be a massive fascination with batch files this week. Must be something in the water.Thanks! I did do a bit of testing with some random files and folders I created myself but here is the some what finished product. @echo off set /p inputdir=Which directory are you moving files from (Collateral, Design, or Production)? echo. ::If directory is not found it goes to the DirNotFound section if not exist "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%" goto :DirNotFound ::If the directory is found it will execute the xcopy command if exist "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%" xcopy "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\*.*" G:\ /E pause ::Comparing the two directories to make sure both match for the files that have moved for /f "tokens=* delims=" %%v in ('dir F:\macdata\MonthlyDisks\CurrentHOData\%inputdir% /b') do ( if exist G:\%%v echo File %%v in %inputdir%; File %%v in G: ::If they do not both match it will go to the exit section if not exist G:\%%v goto :exit ) pause ::Deleteing the old directory and files for /f "tokens=* delims=" %%v in ('dir F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\*.* /a:-d /b') do ( del "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\%%v" ) for /f "tokens=* delims=" %%v in ('dir F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\*.* /a:d /b') do ( rd "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\%%v" /s /q ) echo The orginal files have finshed being moved and deleted. pause EXIT :DirNotFound echo ***That directory does not exist*** @ping 127.0.0.1 -n 5 -w 1000 > nul pause :exit echo File %%v in %inputdir%; File %%v NOT in G: pause exit It's really basic right now and I am sure I will do further tweaking but it gets the job done and makes sure it's done easier and right.folders...files... Quote from: Sidewinder on July 17, 2008, 04:18:04 PM
i like this code, simple and do not have to install anything. but can this code compare everything in the parent folder that i specified ex. FolderA, has 4 folders, and those may have other folders in them and other files. this only compares the INITIAL structure in FolderA (in my case 8 folders, and nothing in those folders.) thank you, jat but take note that it only checks for file existence and not file contents or file modified. if the source is older than destination, the destination will be overwritten with an old file. Best to check for md5 hash and file modified date.Quote this only compares the initial structure in FolderA (in my case 8 folders, and nothing in those folders.)[ Yes, you're right. 1. That's all it was designed to do otherwise it wouldn't conform to the KISS method of coding. 2. Each situation is different, which is why we frown on hijacking threads. Not sure what you asking, but if you want to check sub folders, AND the sub folder structure of FolderA was identical to FolderB, you could do a search and replace of FolderA with FolderB in the path and check that way. Otherwise you'd have to gather a list of all the folders in FolderB (including the top level FolderB itself), and check whether each file from FolderA (including subfolders) exists in any of the FolderB structure. Duplicate file names in different FolderB folders could really foul up the validity of your results. Finally you'd have to flip all the logic so FolderB is the master and FolderA is the slave. Dusty brings up a good point. Files with identical names do not necessarily have identical content. You didn't mention your OS but there is a PowerToy called SyncToy that may help. You don't actually have to sync anything, it has preview function. XP, VISTA only. If the folders in question have a lot of files and/or copying permissions is also a must, you might want to consider robocopy (microsoft) instead of xcopy. It is a lot more powerful copy tool than xcopy, it is a 32 bit app while xcopy is a 16 bit dos app and it is also free. Depending what you want to do you can use command line switches like /mov, /mir, (/copy is the default one), etc. You can see what it can do and how to use it - here: http://www.ss64.com/nt/robocopy.html and you can download it from here: http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en Geza Quote from: Sidewinder on July 17, 2008, 04:18:04 PM It's déjà vu all over again. I posted this in another thread, but it may help you out too: This works great! Anybody have any idea what command I would use to list only files found in FolderA and FolderB for today's date only? Thanks.You are posting in a 4 year old thread. I suggest you start a new topic if you have a question. |
|
| 7661. |
Solve : read text in a file? |
|
Answer» How would you make a batch FILE to display the text in a file in the command prompt |
|
| 7662. |
Solve : how to temp assign usb drive letter to c:? |
|
Answer» I have a family history app i run on usb stick in xp. The app is not installed but copied install files from my "c" drive to it and it runs ok except some reports don't print out, because of reg entries. I want to pass this usb stick to family members to run on their pc without installing it. Can i use a bat file cmd to assign the usb drive = to "c", as in the old dos cmd "assign"? I thought that way i could load the data files in a folder on the "c"drive, thru the bat file, and all should work ok. Or is there a better way. Any help appreciated. C: is reserved for the boot drive only...I've always wanted to say this to you, but that is where you're wrong. It just so happens that on MOST computers, the C:\ drive is the boot drive.Thank you. Got to put a stop to these urban myths. I propose we go back to MAKING A: the boot drive, -just the way GARY wanted it. Quote Gary Arlen Kildall (May 19, 1942 – July 11, 1994) was an American computer scientist and microcomputer entrepreneur who created the CP/M operating system and founded Digital Research, Inc. (DRI). Kildall was one of the first people to see microprocessors as fully capable computers RATHER than equipment controllers and to organize a company around this concept.[1] He also co-hosted the PBS TV show The Computer Chronicles.- From Wikipedia.Quote from: HELPMEH on May 11, 2012, 08:00:12 PM It just so happens that on MOST computers, the C:\ drive is the boot drive. Yes, and that being so, a plan to assign the letter C to a removable drive holding a "portable" app is going to be misguided & doomed to fail in MOST cases, which is the very good (and on-topic) advice that Patio intended to convey. Back on topic. See my replay #1 above. |
|
| 7663. |
Solve : can cmd read 2 separate hard drives in computer? |
|
Answer» I have 2 separate HDD on my COMPUTER one is C: and the other D: but I can't seem to get into the D: drive with cmd, is it possible? Thanks.yes, CMD can access all drives. |
|
| 7664. |
Solve : 2 worded file name won't open? |
|
Answer» Hi everyone, as you'll probably tell by my question that I'm new to this and just getting my HEAD AROUND directories, I went down through the directory to my pictures and opened one called sunset.jpg, i then went to open ANOTHER called water lllies.jpg but it didn't open and the next command line said 'water' not being RECOGNIZED, something like that, i tried another COUPLE of each but the same happened, I tried renaming the pictures instead of water lillies, I made it waterlillies all one word, is this normal and would I have to rename all my files with 2 words or more in them, thanks in anticipation, silly question but doing my head in. Always wrap the term in double quotes and it will work with long filename elements. |
|
| 7665. |
Solve : Batch file changing - into û character? |
|
Answer» When running the below command for some reason a batch file created with NOTEPAD changes the - to be a û character. Anyone else seen anything like this? I have also tried notepad ++. |
|
| 7666. |
Solve : DOS Program/XP/Network Issue? |
|
Answer» At my workplace, we use a dos program called CPS Run-Time System. It currently runs on a desktop RUNNING Win98 setup as a server. All other computers on the network have it added as a network drive. To access the program, users execute a "c.bat" file with the following code: First of all, your batch program is doing more than it needs to. You could change the whole thing to No, it won't. It will not be in the same directory and it could matter. Quote The fact that it runs on XP (which should not have command.com) XP does have command.com for legacy applications. It is a stub, and mostly hands off the commands to cmd.exe though. @the OP: Try this modification of your code to diagnose the issue. When the dir command lists the files starting with c, ensure that the CPL program is there. Code: [Select]f: cd \cado dir c* /b /a-d /p pause CPL -C1 S pause exit Note that the first CD\ command in your batch file is misplaced and it would come after the F: drive change, but instead you can explicitly change the working directory with the 'cd \cado'. With it in the current position: if the working directory on the f: drive was changed then the 'cd cado' could fail and you would get the error you described, along with another error. If it still fails then do a screen copy and paste it into a reply.Quote from: foxidrive on September 11, 2012, 07:21:04 PM XP does have command.com for legacy applications. It is a stub, and mostly hands off the commands to cmd.exe though. I READ into this and I guess it does. I never realized command.com (in any form at all) was kept past the 9x branch, which ended with WinME. I always assumed that it had been dropped in windows NT when they introduced cmd.exe. My apologies Alright so I managed to fix the issue on the system I was working on. All I did was change the PATH in Environmental Variables from: %SystemRoot%;%SystemRoot%\system32;%SystemRoot%\system32\Wbem to C:\Windows\System32\;%SystemRoot%;%SystemRoot%\System32\Wbem That solution worked great. HOWEVER... I'm working on a second machine now and this fix isn't working. In fact, when I use the same fix as above (and even with the original PATH value in place, I still get the issue). Even when I type %systemroot%\system32 into a DOS prompt, it gives me the same error. So finally I added F:\cado;F:\CADO\CPS to the PATH as well. That finally gives me a new error, but one I've never seen (and keep in mind, no other computer on the network has needed this): error opening/accessing cps_data.exe So with this machine, I'm really lost. Basically, same problem, cannot duplicate fix. Any thoughts? EDIT: also, theres a legacy AUTOEXEC bat file that goes on every system we try to run this program from. although XP doesnt use AUTOEXEC bat files on start up anymore. ill show it just for completeness: REM [Cado Accounting App] PATH=%PATH%;F:\cado;F:\CADO\CPS SET CPSNODE=AB017 SET CPSSYS=F:\CADOI posted a reply and diagnostic steps. Here it is again. Copy and paste the screen output if it still fails. Code: [Select]f: cd \cado dir c* /b /a-d /p pause CPL -C1 S pause exit |
|
| 7667. |
Solve : MS DOS 7 download?? |
|
Answer» Quote from: Salmon Trout on April 13, 2012, 10:07:05 AM Offer's post proves nothing.Right. The document has references to Computer Software. It includes the idea of Computer Rental and copyright issues. It would make this thread more meaningful if specific issue were addressed. Specifically, can a person make a profit by offering downloads of software his does not own. Yes, people do it, but is it legal. Example: Quote How long does a copyright last?The above shows that presently the 7, 10 or 17 years rules are not the current law in the USA. (Others countries also) The question "Can I do something illegal if it does not directly involve money" is so juvenile that it is not worth considering. Now to the crux of the matter. "Can anybody offer re-copied of old software that was abandoned." Make a guess, but read this: Quote Abandonware are discontinued products for which no product support is available, or whose copyright ownership may be unclear for various reasons. Abandonware may be computer software or physical devices which are usually computerised in some fashion, such as personal computer games, productivity applications, utility software, or mobile phones. ...Of course, Wikipedia is not a legal authority. But does provide a framework and a list of references. Quote Even if the copyright is not defended, copying of such software is still unlawful in most jurisdictions when a copyright is still in effect. Abandonware changes hands on the assumption that the resources required to enforce copyrights outweigh benefits a copyright holder might realize from selling software licenses. Quote ReferencesIs that enough?Quote from: Geek-9pm on April 13, 2012, 11:27:37 AM The question "Can I do something illegal if it does not directly involve money" is so juvenile that it is not worth considering. Indeed. Indecent assault, genocide, and breaking the speed limit are all illegal in civilised countries, and don't directly involve money. 4 - 3 - 2 - 1....Patio, it doesn't look as though you closed this thread, so can I ask a really dumb question? Thank you, Isn't DOS included in every version of Windows? If you format a floppy disk, for instance and ask for it to be made bootable, have you not just taken some of DOS off of the PC? At least a small part of it is and will go wherever that disk goes. Just curious...... So I'm just wondering how much DOS a person really NEEDS that they couldn't get from their own PC. I wouldn't even think of asking someone else for DOS. I told you this was a Dumb question? Quote from: TheShadow on May 03, 2012, 03:27:38 PM Isn't DOS included in every version of Windows? Some (not all) versions of Windows have the capability of creating a bootable floppy disk that contains a (very) small subset of files from MS-DOS, the standalone single-user text based operating system whose last standalone version (6.22) was released in 1994. That small subset is just enough to boot the computer and if necessary access a CD-ROM drive. It is not the complete MS-DOS operating system, and I don't think the license for the Windows install that it came from allows the user to sell it or distribute it freely. Was selling or distributing a part of the OP's quest? For Shame, if it was, but I didn't read it that way. I have several PC's with Windows ME on them. A floppy disk formatted on ME is great for a DOS utilities disk. It's just full of all sorts of neat stuff. And more DOS files from within ME can be added to the disk for added functions. Oh well, those of us that know how, DO and those that don't, ASK. Eh? Y'all have a great day now, Y'hear? Quote from: TheShadow on May 03, 2012, 03:27:38 PM Isn't DOS included in every version of Windows?No. Non x86 versions of windows cannot seem to format a system disk from a floppy. (at least from the prompt, the /s switch for the format command now enables or disables short file name generation). I don't have a floppy disk to test, though. Actually looking back it seems like none of the NT lineage provides either a /S switch or a sys command for creating a system disk from the prompt. Quote If you format a floppy disk, for instance and ask for it to be made bootable, have you not just taken some of DOS off of the PC?Yes. But what is your point? The EULA for most software states you can install the program on a computer and has provisions for a portable, non-permanent installation of it. testing via a XP vm, format.com, at least since XP, does not support the /s switch, and there is no sys command to copy to said floppy either, making the floppy created from the SHFormatDrive() function nothing more than a portable boot disk. it cannot, however, be permanently installed to another machine using the facilities provided either by copying files from the original system or provided on the disk (which only has three files, iirc) The DOS Setup floppies, on the other hand, are designed specifically for installing it onto the hard drive of a machine. Quote So I'm just wondering how much DOS a person really needs that they couldn't get from their own PC.Well, since XP (probably any NT windows system) and later only allow you to create a bootable floppy which can not then be installed to another hard drive, if all a person wants to do is use internal commands on FAT disks, without installing from that floppy, than it's all there. Of course, the DOS package consists of more than msdos.sys, io.sys, and command.com, but also external utilities like find, more, sort, edit, qbasic, scandisk/chkdsk, format, sys, deltree, mscdex, diskcopy, comp, fc, diskcomp, etc. Of course for 9x it's a bit difference since you could create a working DOS environment on another machine by copying files from the C:\Windows\command folder and using sys on that other drive. But, just because a Operating System gives you the first step in such a process (creating a boot disk) doesn't mean that it is condoning the extension of that allowance to "permission" to supplant those files to a completely different system. Quote I wouldn't even think of asking someone else for DOS. I told you this was a Dumb question?With the exception that, unless you have rather old, 9x systems, that copy of DOS is going to stay on the floppy since it doesn't provide the capability to make other disks system disks via format /s or the sys command- the DOS version of the boot disk is Windows ME iirc but Windows no longer has a C:\Windows\Command directory from which you could copy files; If somebody has Win9x then it's possible to transplant the underlying DOS system from that system to another, but that applies to Windows itself, too, which could meticulously be copied and reconstructed on another system. However to my understanding there is no provision that being able to move software using a floppy disk made it public domain.Quote from: TheShadow on May 03, 2012, 03:56:37 PM Was selling or distributing a part of the OP's quest?The assumption is that they want to download MS-DOS 7 so that they can distribute it to one or more machines. And since we don't know the goal, the fact is that anybody would be able to view any information given on the forum, so even if they just wanted it for some slipshod museum, somebody else could easily stumble upon this thread and follow the helpful DIRECTIONS to get a free copy of DOS, which would be distribution. At that point the forum becomes an accessory to a crime. Now one can debate the morality of the law behind that crime and argue against it until one is blue in the face, but that isn't going to make that law go away. If somebody feels strongly about copyright law and feel it is mismanaged, they should lobby their own government, not members on a forum. Quote I have several PC's with Windows ME on them. A floppy disk formatted on ME is great for a DOS utilities disk. It's just full of all sorts of neat stuff. And more DOS files from within ME can be added to the disk for added functions.From C:\Windows\command of course, that basically constitutes a portable installation. You break the EULA if you then install that DOS (by copying format.com or sys and using format /s or sys) to another hard disk for the purpose of giving it a DOS installation. the FBI/CIA/whoever is not going to smash down your door, or anything like that, but it is against the license agreement, for which a breech of contract constitutes copyright infringement. Since that is illegal, it is thus outside the realm of advice that should be given or encouraged in the context of this forum. Oh the slippery slope! I just formatted a floppy disk under XP-Pro-SP3 and it came up as version "Windows Millennium 4.90.3000" Then I formatted another floppy under Windows 8/CP/64 and it still came up "Windows Millennium 4.90.3000" That was somewhat surprising. Eh? Where does DOS 7 come into play? I can't say that I've ever seen it. The last DOS that I actually 'Bought' was DOS 6.22 But that's now Ancient History. PS: I just checked my DOS Utilities disk that was formatted on my Windows ME PC, , , guess what,,,,,"Windows Millennium 4.90.3000"Quote Where does DOS 7 come into play?There are things you have not seen Google Boot to DOS 7 And see what they mean.Quote from: TheShadow on May 03, 2012, 04:40:41 PM I just formatted a floppy disk under XP-Pro-SP3 and it came up as version "Windows Millennium 4.90.3000"The version of the DOS subsystem used by Windows ME is DOS 8.0. Quote Then I formatted another floppy under Windows 8/CP/64 and it still came up "Windows Millennium 4.90.3000" Quote That was somewhat surprising. Eh?Not really, no. XP and later do not use DOS, but they include the basic components of the version supplied with windows ME, which itself uses the basic layout of the Windows 98 Emergency Boot Disk. The version numbers come from the version numbers given by that installation of DOS via the "get DOS Version" interrupt. Also, if you run MSD on a boot disk formatted in this manner, it will indicate version 7.0 for Windows 95, 7.1 for a 98 boot disk, and 8.0 for ME. the ver command is set to return the Windows version, not the MS-DOS version. I cannot check Windows 8 or any x64-version of windows to see if they allow it, but I have no reason to think otherwise now. Anyway, the boot disks are all the same, because they are merely image files that are found within DISKCOPY.DLL. Windows XP(and presumably later) takes the additional step of ADDING in empty autoexec.bat and config.sys files. The Image used is based on the Windows ME Emergency Boot disk. This can be confirmed because Undelete and Norton unerase can see and recover several files from the disk after you create a boot disk with XP and later. MSDOS.SYS on the disk contains ;W98EBD because the ME boot disk was in fact based on the Windows 98SE boot disk itself. Quote Where does DOS 7 come into play?The original post. The very thing being talked about is a distribution of MS-DOS where MS-DOS 7 was TEASED apart from it's PARENT Windows environment (in this case Windows 95OSRB), and distributed separately. Quote PS: I just checked my DOS Utilities disk that was formatted on my Windows ME PC, , , guess what,,,,,"Windows Millennium 4.90.3000"the Get DOS Version interrupt returns 8.0 for the Windows ME DOS subsystem. |
|
| 7668. |
Solve : [Batch] Ping Script?? |
|
Answer» It is possible to make something LIKE this ... not working ( Fine here... Code: [Select]C:\Batch\Test>aveping.bat Your connection to Yahoo.com is 188ms C:\Batch\Test> Windows 7 Professional Quote from: CaTaLinU on May 09, 2012, 10:11:55 AM not working (Don't know what to tell you. Works just fine for me. Code: [Select]C:\batch files>ping_avg.bat Your connection to Yahoo.com is 49ms( F**king windows ......... Someoen knows from what is this "error" For Salmon Trout worked this script but for me the console remain blank...Maybe he doesn't want to do batch arithmetic; perhaps he just wants to isolate the average part of the ping output summary line... C:\Batch\Test>ping www.yahoo.com Pinging eu-fp3.wa1.b.yahoo.com [87.248.122.122] with 32 bytes of data: Reply from 87.248.122.122: bytes=32 TIME=52ms TTL=52 Reply from 87.248.122.122: bytes=32 time=51ms TTL=52 Reply from 87.248.122.122: bytes=32 time=75ms TTL=52 Reply from 87.248.122.122: bytes=32 time=50ms TTL=52 Ping statistics for 87.248.122.122: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round TRIP times in milli-seconds: Minimum = 50ms, MAXIMUM = 75ms, Average = 57ms easy enough... for /f "tokens=1-9" %%A in ('ping www.yahoo.com ^| find "Average ="') do echo Average=%%I Quote from: CaTaLinU on May 09, 2012, 10:52:39 AM For Salmon Trout worked this script but for me the console remain blank... It worked for Squashman too. 1. Please don't use bad language, even censored. 2. How are you running this code? Bat File Name - ping.bat code given by Squashman is not changed, i run it how he give it to me the Double-Click on ping.bat if i wait more than 30 sec my pc it will work very slowly ..Quote from: Salmon Trout on May 09, 2012, 10:53:43 AM Maybe he doesn't want to do batch arithmetic; perhaps he just wants to isolate the average part of the ping output summary line...That makes the code a lot easier. Not sure why I didn't do that in the first place.Quote from: CaTaLinU on May 09, 2012, 11:01:27 AM Bat File Name - ping.bat Sounds about right, mine took nearly 23 seconds. Maybe you have a slow connection? C:\Batch\Test>( More? echo %time% More? aveping.bat More? echo %time% More? ) 18:18:24.61 Your connection to Yahoo.com is 158ms 18:18:47.23 Quote from: CaTaLinU on May 09, 2012, 11:01:27 AM Bat File Name - ping.batWell there is your mistake. You can't name your batch file the same as a command in your batch file!!!!!!!Quote from: Squashman on May 09, 2012, 11:21:17 AM Well there is your mistake. You can't name your batch file the same as a command in your batch file!!!!!!! I missed that... I just assumed nobody would ever call a batch script ping.bat... Quote from: Salmon Trout on May 09, 2012, 11:24:40 AM I missed that... I just assumed nobody would ever call a batch script ping.bat... Now works fine Thx a lot Quote from: CaTaLinU on May 09, 2012, 11:29:27 AM Now works fineWould probably run a tad faster if you used Salmon Trout's code. |
|
| 7669. |
Solve : Compare folder sizes between 2 externals and list only mismatched folder info? |
|
Answer» I am thinking this might be beyond batch. I realized this morning checking on my 2 external drives that chugged through the night since 6pm yesterday transferring data that I had made a mistake in how I should have gone about copying data from one to the other. I am a bit unclear on what it is you mean by a "difference". Do you mean that if G:\Root\Branch\Folder has 23 files and F:\Root\Branch\Folder has 0 files that is 23 "differences"? Or one? What are you looking for? Question #1 - Yes I am looking for a mismatch between the 2, so that if both = 23 files it would move on and not report back, but if one had say 22 and the other 23, that it would possibly write to a logfile this inequality between the 2 locations. *I would also like to add that I put further thought into this and thought that you could grab the structure of the 500GB drive from a DIR output and use that as a reference to test against the 1.5TB drive, so that its only looking for inequalities between both externals that are directly related to the folder structure of the original 500GB drive. All data added that came from the C: drive of the local machine that is blended in on the 1.5TB would be skipped over so that I wouldnt have those listed as inequalities between the 2 drives. Further information on that question you asked if I wanted to know about a single problem or 23 problems with the relation of 0 and 23 files. It doesnt have to specify 23 problems at a single location if that involves more work to achieve that. If I had a log output to say mismatch.log that displays just the folder path to an inequality that would be good enough for me to navigate and look to see where the problem is. I m guessing that it would be best for this to execute from C:\ to compare between G: and F: and write back to C:\ the mismatch.log information to avoid the mismatch.log from being added to itself if for example that is written to either external drive. Question # 2 - I realized what I had done ... I should have copied all data from the 500GB to the 1.5TB with the 1.5TB empty of data. So that could have just done a simple compare between them via properties and verify that it was an exact copy without data lost in the transfer. BUT the problem I created for myself was that prior to the xcopy g:\*.* f:\*.* /s/d/y to copy all data from one external to the other, I copied a large amount of data from the local machines C: drive to this external so it already had about 300GB of data onto it before copying over all data from G: to F:, so in the end I realized that I shouldnt have copied data to this 1.5TB in that order. I should have copied to a clean 1.5TB drive, done a comparison, then when satisfied that all was well then add data from the local machines C: to this 1.5TB. I could just dump all data from the 1.5TB and start over in the correct order to compare, but figured I'd post here to see if there was a way to check that the data from G: and F: match in relation to the data at G:, when F: will have extra files and folders that should be ignored in this comparison. There use to be a TREE command that I think would have worked out better for such a comparison in which you could TREE and write the output from TREE from G: to a file and then increment each path from that output to test against the destination of F:, but I think I saw a say to do this with DIR and a FOR loop a while back. And this is batching territory that is beyond what i can code up and I figured I'd check with you here to see if its something simple. Salmon - You have amazed me with the simplicity of batches in the past that perform powerful tasks, so I figured I would throw this out there in case this is something that can be done in which your expertise of batch programming shines over my lack of knowledge on the matter. THANKS for assisting with this Robocopy may be able to help you achieve your goal. For instance, to list the files in source_path which are not in target_path: Code: [Select]Robocopy source_path target_path /e /ndl /l This command will only list the missing files. If you want the missing files to be copied to the target_path, remove the /l from the command line. If you want the result written to a file, append /log:path_to_log_file to the command line. This should give you a list of the missing files. Hidden files will be also listed as missing. Code: [Select]@echo off dir g:\ /b /s /a-d>%temp%\list.list for /f "delims=" %%a in (%temp%\list.list) do ( if not exist "f:%%~pnxa" >>g:\MissingFiles.txt echo %%a )Thanks Everyone! I ran with what foxidrive posted and it worked perfect. Now to look thru the list and manually transfer what is missing. BTW I was looking it over and trying to figure out what Quote "f:%%~pnxa"does, the ~pnxa is something i have never seen before. I like to see why it does what it does than to simply just run with it to perform a task. Thanks for explaining You can run it again and make it copy the files - using xcopy it will recopy all the hidden/system files but it should be a full copy. Code: [Select]@echo off dir g:\ /b /s /a-d>%temp%\list.list for /f "delims=" %%a in (%temp%\list.list) do ( if not exist "f:%%~pnxa" xcopy /h/y "%%a" "f:%%~pa\" ) Or if you kept the file on g: then use this: Code: [Select]@echo off for /f "delims=" %%a in (g:\MissingFiles.txt) do ( xcopy /h/y "%%a" "f:%%~pa\" ) "%%~pnxa" is made up from parts of the %%a variable - p is the path, n is the name of the file, x is the .extension and a is the variable name. f: at the start adds the target drive letter. See the help for this, at the bottom. FOR /?Thanks for explaining that. Makes sense now. With the lengthy help instructions of FOR I never seen that one before till now. Also thank you for showing how to xcopy hidden files in reference to MissingFiles.txt from G: to F: Very Cool! Quote @echo offQuote from: DaveLembke on September 16, 2012, 06:19:47 PM Also thank you for showing how to xcopy hidden files in reference to MissingFiles.txt from G: to F: Very Cool! Your welcome. In case I wasn't clear, it will copy all the missing files - and recopy the hidden files if they exist. |
|
| 7670. |
Solve : Batch file to copy and rename? |
|
Answer» I have a directory containing folders: I need a batch which will move all tracks into the root directory (the one containing the folders 1,2,3) and rename them Track01.mp3 .... You WANT to move them all into the root folder and give them all the same name? Track01.mp3? That won't work, but I don't think that's what you MEANT. Does the ellipsis with an extra dot (those FOUR dots) imply some kind of sequence? Quote You want to move them all into the root folder and give them all the same name? Track01.mp3? That won't work, but I don't think that's what you meant. No, I want to rename them otherwise I'd have 12 Track01s and so on because that's how many folders I have. However, I want them named with the same convention (i.e. Track01, Track02, etc...) Quote Does the ellipsis with an extra dot (those four dots) imply some kind of sequence? Yeah, I just meant it would continue through all the tracks. Thanks SALMON. I know you're really good at complex batch files. Do you think you can help?The first question is... the final filename order, how is decided? Do you want "1\track01.mp3" to be "Final track 01.mp3" in the root folder and number sequentially, taking the folders in order starting at 1 and the files in each folder in order? What will the final filename be? The filename prefixed with the original folder name e.g. 1-Track01.mp3 etc? Do the subfolders start at 1 and go up without gaps to a final number? Quote The first question is... the final filename order, how is decided? Do you want "1\track01.mp3" to be "Final track 01.mp3" in the root folder and number sequentially, taking the folders in order starting at 1 and the files in each folder in order? Yes, they will be taken sequentially, but not renamed for just the first folder. For subsequent folders, they will need to be renamed because the track numbers will continue to increase. Quote The filename prefixed with the original folder name e.g. 1-Track01.mp3 etc? No prefix, that's what makes it hard. The numbers just keep increasing. Quote Do the subfolders start at 1 and go up without gaps to a final number? Yes. Here is a little more detail: Basically, for the first folder all files can just be moved to the root without renaming. Let's say the first folder contains Track01 - Track20. When it moves the files in the second folder it renames Track01 to Track21 and so on. Then the numbers just increase until it has gone through all the folders.Quote from: Linux711 on August 12, 2012, 01:06:47 PM Basically, for the first folder all files can just be moved to the root without renaming. Let's say the first folder contains Track01 - Track20. When it moves the files in the second folder it renames Track01 to Track21 and so on. Then the numbers just increase until it has gone through all the folders. This makes it easier. Watch this space. The subfolders run from 1 to what final number? What is the highest number NN in TrackNN.mp3 that each folder might have? Are all the mp3 files named TrackNN.mp3 where NN is a 2 digit number with a leading zero for 1 to 9? Are there going to be more than 99 files in the root folder? More than 999? (You see where I am going here... ?) Put this batch in the root folder. Assuming there are less than 100 final files. Change the number of digits in the NEW file number like this: set padnum=!padnum:~-2! Change the 2 to the number required Code: [Select]@echo off setlocal enabledelayedexpansion set fnum=1 set rootfolder=%~dp0 echo Root folder: %rootfolder% for /f "delims=" %%A in ('dir /b /ad /on') do ( echo Folder %%A for /f "delims=" %%B in ('dir /b /on "%%A\*.mp3"') do ( set padnum=00000000000!fnum! REM set number of digits here set padnum=!padnum:~-2! REM Delete echo from the start of the next line when you are happy echo Copy "%%A\%%~nxB" "%rootfolder%Track!padnum!.mp3" REM Copy rather than move because it is safer. When you have run it and you are happy delete or move the subfolders set /a fnum+=1 ) ) echo Done Pause Code: [Select]Root folder: C:\Batch\Test\After 04-07-2012\Sub-move-Rename\ Folder 1 Copy "1\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track01.mp3" Copy "1\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track02.mp3" Copy "1\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track03.mp3" Copy "1\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track04.mp3" Copy "1\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track05.mp3" Copy "1\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track06.mp3" Copy "1\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track07.mp3" Copy "1\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track08.mp3" Copy "1\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track09.mp3" Folder 2 Copy "2\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track10.mp3" Copy "2\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track11.mp3" Copy "2\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track12.mp3" Copy "2\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track13.mp3" Copy "2\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track14.mp3" Copy "2\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track15.mp3" Copy "2\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track16.mp3" Copy "2\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track17.mp3" Copy "2\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track18.mp3" Folder 3 Copy "3\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track19.mp3" Copy "3\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track20.mp3" Copy "3\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track21.mp3" Copy "3\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track22.mp3" Copy "3\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track23.mp3" Copy "3\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track24.mp3" Copy "3\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track25.mp3" Copy "3\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track26.mp3" Copy "3\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track27.mp3" Folder 4 Copy "4\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track28.mp3" Copy "4\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track29.mp3" Copy "4\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track30.mp3" Copy "4\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track31.mp3" Copy "4\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track32.mp3" Copy "4\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track33.mp3" Copy "4\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track34.mp3" Copy "4\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track35.mp3" Copy "4\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track36.mp3"It works perfectly. The only annoying thing is the folders have to be named 01,02,03 otherwise it doesn't go in the right order with numbers above 9. Is there some code I can add that checks if the length of the folder name is less than 2 and then adds the zero and renames the folder?Quote It works perfectly. The only annoying thing is the folders have to be named 01,02,03 otherwise it doesn't go in the right order with numbers above 9. Is there some code I can add that checks if the length of the folder name is less than 2 and then adds the zero and renames the folder? I got it: Code: [Select]for /f "delims=" %%A in ('dir /b /ad') do ( set foldername=%%A set foldername=0!foldername! set foldername=!foldername:~-2! echo rename %%A !foldername! ) The final: Code: [Select]@echo off setlocal enabledelayedexpansion set fnum=1 set rootfolder=%~dp0 for /f "delims=" %%A in ('dir /b /ad') do ( set foldername=%%A set foldername=0!foldername! set foldername=!foldername:~-2! rename %%A !foldername! ) for /f "delims=" %%A in ('dir /b /ad /on') do ( for /f "delims=" %%B in ('dir /b /on "%%A\*.mp3"') do ( set padnum=00000000000!fnum! REM set number of digits here set padnum=!padnum:~-3! REM Delete echo from the start of the next line when you are happy move "%%A\%%~nxB" "%rootfolder%Track!padnum!.mp3" REM Copy rather than move because it is safer. When you have run it and you are happy delete or move the subfolders set /a fnum+=1 ) rd %%A ) Thanks for the help, you're a genius.Yes, I was wondering about the sort order that Windows uses, where 10 is sorted before 2 etc. There is a registry setting, I believe, that can enforce either natural or numerical sort order in Explorer, but I am not sure whether it would apply to the command line DIR. I must say, this is the type of thread that I really like, where the other person takes the ball and runs with it. Very well done. Even PowerShell sorts the same way but the difference with PowerShell is you can pipe to the SORT command and use a regular expression to sort by so that it does sort numerically. |
|
| 7671. |
Solve : Counting a selected number of files with specific names in a folder? |
|
Answer» Hello |
|
| 7672. |
Solve : DIR? |
|
Answer» Hi All, |
|
| 7673. |
Solve : How to delete double quotes from a CSV file? |
|
Answer» How do I delete all of the double quotes (") from a CSV file? I am using Windows 7 64-bit.setlocal enabledelayedexpansion That looks like an SQL Prompt? Is that what it is? I wondered if it was a heavily nonstandard cmd.exe prompt, but your theory makes more sense. Quote from: Salmon Trout on July 12, 2012, 01:43:40 PM It's as "close" as you are going to get. Why you aren't creating after.csv in the same folder may be a question of write permissions, or perhaps it is there and you have missed it? I tried the script from a PREVIOUS topic that you also wrote and had no problem generating an output file. The output is going to the same folder as the input, which is on my HARD drive. I like the echo because it tells me that the desired string is being generated in memory, but the output file is not appearing. Unfortunately, it's been a decade or so since I used DOS regularly. I'm just trying to find a way to update my data that is faster/better than importing it to EXCEL, running a macro, then saving it back out, or writing a separate .NET app to parse the file, given the requirements I'm constrained to at the moment, a CUSTOM SQL query program at my workplace that can run DOS commands. I do appreciate your effort to help.On thing you could try is putting a drive/folder specification for the output, just to make sure it's going where you think/want it to go.Maybe you could do this (echo to console & redirect to an output file) SQLP>RemoveQuotes.bat > after.csv @echo off setlocal enabledelayedexpansion for /f "delims=" %%A in (before.csv) do ( set csvline=%%A echo !csvline:"=! ) That worked. Thanks! |
|
| 7674. |
Solve : Is there a way to copy or move files containing a certain word between folders?? |
|
Answer» I would be grateful for any help or suggestions you might give. I would be grateful for any help or suggestions you might give.So what you really want is a script that will parse multiple directories all at once and not just your folder called OLD.assuming you have all your files just in "old" and want them all moved to just "new" this should work. You will have to fill in the pathway yourself though. Code: [Select]@echo off setlocal EnableDelayedExpantion dir | find /v "<DIR>" >>mylist.txt for /f %%G in (mylist.txt) do ( title %%G if exist str.txt del /f str.txt echo %%G >>str.txt findstr /I "match" str.txt >nul if %errorlevel% EQU 0 COPY FILLINPATHWAYHERE\old\%%G FILLINPATHWAYHERE\new\%%G /Y >nul ) If in fact you do have multiple folders in "old" then you would have to use something else.Do you want to just do one folder at a time? This should recurse from the current folder and below, and copy all files with match somewhere in the filename to the target folder (make sure the target folder exists). Code: [Select]@echo off for /f "delims=" %%a in ('dir /b /s /a-d ^|find /i "match"') copy "%%a" "c:\new folder\here" I edited this to add the find command - because the DIR command will match using both long and short filenames so it can have a false positive when it matches on a short filename. The find command should restrict the search to long filenames only. If you have hundreds of thousands of files in the tree then let us know as this will slow down dramatically with so many files.Quote from: Lemonilla on July 11, 2012, 10:03:55 AM assuming you have all your files just in "old" and want them all moved to just "new" this should work. You will have to fill in the pathway yourself though.Do you realize that the DIR command has a switch to exclude Directories? alot of your code is redundant and could be shortened as you can see from Foxidrive's post.Quote from: foxidrive on July 11, 2012, 10:04:24 AM Do you want to just do one folder at a time?Hi Foxidrive. I see you found a new place to hang out. I think this might work as well. Code: [Select]xcopy *match* c:\temp /SYes Squashman, I noted you blokes talking about it. The more batch files the merrier! Note that I edited my post above - and it will work with the move command too.Quote from: foxidrive on July 11, 2012, 10:04:24 AM Do you want to just do one folder at a time? As a test I made the directory c:\new folder\here. At the command prompt in DOS I then changed directory to the directory I wanted (containing my test file with the word match in it). I then pasted in the code you supplied and hit enter. I got the message '%%a was unexpected at this time'. Any ideas what I did wrong ?My mistake - it was missing the do keyword. Make sure you create a batch file - call it matchA.bat for example. Code: [Select]@echo off for /f "delims=" %%a in ('dir /b /s /a-d ^|find /i "match"') do copy "%%a" "c:\new folder\here"Quote from: No_hope_without_snacks on July 12, 2012, 03:00:25 AM You cannot copy and paste the code directly into the command prompt for it to work. As Foxidrive has already said, you need to create a batch file and execute the batch file. Quote H:\>for /? If you are going to start getting into batch files to automate processes you better start reading the help files for the CODE you are executing so that you understand the code. This falls under the Teach A Person to Fish instead of giving them the fish. |
|
| 7675. |
Solve : batch file for renaming existing folder? |
|
Answer» My requirement is : If folder is already exist then do not replace it and create new folder with siffix. Thanks, it is working. how to write else part, i triedCode: [SELECT]IF EXIST "C:\users\Squash\My Folder" ( md "C:\users\Squash\My Folder_XXXXX" ) else ( md "C:\users\Squash\My Folder" )not working. for if section it says -- the syntax of command is incorrect and for else section it says -- 'else' is not recognised as an external and internal command please advise.You need the trailing \ to reliably test for folders, but the syntax looks fine and works fine here in Windows 7. What OS are you using? IF EXIST "C:\users\Squash\My Folder\" ( md "C:\users\Squash\My Folder_XXXXX" ) else ( md "C:\users\Squash\My Folder" ) Forgive my INTRUSION, but wouldn't it save space to write: Code: [Select]IF EXIST "C:\users\Squash\My Folder\" md "C:\users\Squash\My Folder_XXXXX" IF NOT EXIST "C:\users\Squash\My Folder\ md "C:\users\Squash\My Folder" That way you use 2 lines instead of 5. That is, unless there is a flaw in this method that I didn't see. Unless you plan on ADDING and rd to the if exist statement, which would require and else.I beat you with one line. Code: [Select]IF EXIST "C:\users\Squash\My Folder\" (md "C:\users\Squash\My Folder_XXXXX") else (md "C:\users\Squash\My Folder")Quote from: foxidrive on August 14, 2012, 01:26:18 AM I beat you with one line. You also won in the character count event. However, the double-liner was easier to read. By the time I got to the end of the one-liner, I was gasping for air and forgotten how I got got there. Quote from: Sidewinder on August 14, 2012, 05:57:45 AM You also won in the character count event. However, the double-liner was easier to read. By the time I got to the end of the one-liner, I was gasping for air and forgotten how I got got there.Which is why I break it up. Easier to read.This is shorter, and a single line, even with a couple of whitespace characters. Code: [Select]MD "C:\users\Squash\My Folder\" 2>nul || md "C:\users\Squash\My Folder_XXXXX"Quote from: foxidrive on August 14, 2012, 06:42:03 PM This is shorter, and a single line, even with a couple of whitespace characters.Me likey! Conditional Operators are one of my favorite things about batch |
|
| 7676. |
Solve : How to delete the first three lines of a text file? |
|
Answer» Hi All Assume the last letter is a , which i want to remove Where is it? It is not shown. Hi Please take a fresh look I am looking for help on how to remove the first 3 lines from a text file and save it my file looks like this. Changed database context to 'xyz'. ------------------------------------------------------------------------------------------------------- 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn', what i want is 1. Remove the first three lines --> now i have the solution 2. Replace the last charecter in the file "," with ")". --> i want a solution for this Finally it should look like 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn') thx OK Understood Please await suggestion @echo off setlocal enabledelayedexpansion set lines=0 if exist "output.txt" del "output.txt" for /f "skip=3 delims=" %%A in ( ' type "input.txt" ' ) do set /a lines+=1 set LastLine=%lines% set LineNumber=0 for /f "skip=3 delims=" %%A in ( ' type "input.txt" ' ) do ( set /a LineNumber+=1 set InputLine=%%A if !LineNumber! lss %LastLine% ( echo !InputLine! >> "output.txt" ) else ( echo !InputLine:,=!^) >> "output.txt" ) ) Wow Salmon!!. thanks very much. it worked like a charm warm regards Helen Quote from: Helen09122010 on July 07, 2012, 01:37:36 AM the last letter is a , which i want to remove This confused me - I read it as "the last letter is a, which I want to remove." You meant the "The last character is a comma which I want to remove". Commas are not letters, they are punctuation marks. Letters are a-z and A-Z. However letters, numbers, punctuation marks and symbols are all TYPES of character. |
|
| 7677. |
Solve : Dos Copy Command? |
|
Answer» I had a large home server with three drives full of data set up in a Raid configuration that spread out the data over three disks such that 1/3 of the data was RECOVERABLE from each disk. I have all three disks and have saved most of the data from the crashed disk. I need to copy all of this data onto my new server. The data is distributed among various folders and subfolders - several thousand in fact and about 2000000 files. I want to transfer this data to the new server from the old drives without deleting or overwriting existing data that may have been duplicated between drives. |
|
| 7678. |
Solve : Need to create bat file to append a text at the end of each sql script? |
|
Answer» NEED to CREATE a BAT file to ADD text at the end of each sql script For example Alter fields1,field 2. I need to add "text addition" at the end of field 2 |
|
| 7679. |
Solve : Migrate 500GB external HD data to 1.5TB and on error, log, and continue? |
|
Answer» Bought an external 1.5TB drive to migrate my data off of an older 500GB external. Ran the instruction of xcopy *.* F:\*.* /s/d/y from G: since G: is the 500GB connected via USB. Checked on it a couple times last night and saw files and folder trees scrolling as data was being copied to the larger drive. Left it running thru the night and checked on it this morning and come to find out it stopped copying when it got to a user profile that I had backed up from ages ago with Access Denied ending the transfer process. |
|
| 7680. |
Solve : Finding double back slashes? |
|
Answer» How do I retrieve all lines in every file in every SUBDIRECTORY that contains the double backslash \\ ?Do you want the contents of those files to be appended into a separate file? |
|
| 7681. |
Solve : %0,%1,%2,%3,%4,%5,%6,%7,%8,%9? |
|
Answer» So forgive my ignorance, but I can't seem to find out what these actually do. Google ignores the percent sign (%), and I'm not sure what they're called. Would someone mind explaining them? |
|
| 7682. |
Solve : Removing File Extension from a Filename ...? |
|
Answer» I am currently using batch commands for many functions where normal windows actions are more time consuming. i.e. Copying an entire directory (15,000+ files) to a different drive, etc. I am even using them to back up specific files instead of going through the windows explorer method. set noext=%file:~0,-4% Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore. Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done. Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files? here is other script with drag and drop feature: Code: [Select]@echo off SETLOCAL ENABLEDELAYEDEXPANSION set fName=%1 if '%1' equ '' set /p fName=Enter file name: for /f "tokens=* delims= " %%F in ('echo %fName%') do ( echo REN %%~nxF %%~nF ) pause if its working just change echo REN to RENThank You for your added input. Is there a way to drag & drop multiple files for the task to be performed at one time? or ... for the batch command to automatically seek out ALL .tif file extensions, then rename them for me. you just drag your file over the script.bat file and it renames it automatically Quote Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?and by the isolate files you can use Code: [Select]DIR /b C:\path\to\files\*.tifQuote from: Dias de verano on March 14, 2009, 12:56:25 PM Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore. thats true..but he's using it on a 3 char extension, and: Quote from: eagle on March 14, 2009, 01:44:05 PM Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done. If he needed it to do more than just dot + 3 char extensions, i would of re-wrote the code.Much appreciation goes out to those helping with this. Well, I got the first recommendation to WORK. Unfortunately, having to enter the entire file name is not really time effective. The 2nd recommendation did not work with dragging the file and dropping onto the ".bat" file I did get the 2nd recommendation to work ONLY if I run the batch file, then I am able to drag & drop the file to be changed. Click on the cmd.exe window; Then Hit enter. I removed the pause, and inserted a call command to loop it. After I hit enter to remove the .tif, it loops back for the next file to be dragged & dropped. Here is what I have at this point ... Code: [Select]@echo off SETLOCAL ENABLEDELAYEDEXPANSION set fName=%1 if '%1' equ '' set /p fName=Enter file name: for /f "tokens=* delims= " %%F in ('echo %fName%') do ( REN %%~nxF %%~nF ) call RemoveFileExtension.bat Is there a way to automate things more? ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done. OR ... Do I have to KEEP feeding the files one at a time? I must apologize for my lack of understanding here ... it has been more than 20+ years since I did this stuff, or even other forms of programming. Before finding this website, I have been at my wits end ... LOL Quote from: eagle on March 14, 2009, 04:52:53 PM ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done. Code: [Select]for /f "delims==" %%F in ('dir /b *.tif') do ren "%%~nxF" "%%~nF" TY TY TY TY ... There's Mundane work, then there is working smart ... Kudos to ALL to have contributed and most importantly were quite patient with me. Anytime Fileviewpro is simplest way to CONVERT or view all types file without any problem so don't wasting your time, i think it will be great move to use this. The Topic is over 3 years old... SPAM link removed. |
|
| 7683. |
Solve : Find files with specific parameter? |
|
Answer» Hi, it gives me an error of: %%g was unexpected at this timeBecause you are trying to run the code from the command line. That would be the only way you would get that error. Code: [Select]C:\batch files>FOR /F "Tokens=4*" %%G IN ('dir /a-d ^| find "%date:~4,10%"') DO COPY "%%H" "C:\Some Directory" %%G was unexpected at this time. You need to put the code I gave to you and save it to a text file with a .BAT extension. |
|
| 7684. |
Solve : File transfer the files one by one? |
|
Answer» HI All, I have a requirement in which i have MULTIPLE source files in source folders in sFTP server. I need to CHECK if file exists in the source folders one by one and transfer from sFTP server to remote target server. Please suggest me any batch script which i can use for this requirement. Regards RajeshYou have to capture a listing of the files on the FTP server, then ITERATE through the listing to see if the files exist (where?) and then copy the ones that don't exist someplace. Do you have a command line sFTP program? |
|
| 7685. |
Solve : System admin via cmd? |
|
Answer» I bought a used computer |
|
| 7686. |
Solve : MS-DOS Disks to CD-ROM transfer? |
|
Answer» Hi, Create a bootable cdrom image of MSDOS V 6.22 with sys.comHe already did. Setup disk one has sys.com. Quote SYS a: c:This would give a too many parameters error. sys only accepts a target drive. Quote then just copy the MSDOS files into C:\DOSOr they could find them on their setup disks. Quote Either way, it's not a batch file issue.Nobody said anything about batch files. Anyway, the main issue here is that the DOS setup (iirc) goes by volume label. Best approximation would as you considered, actually use a complete disc for each floppy (with the appropriate label) in addition to the use of a CD-ROM driver on the first one to get access to the drive. (the second two would not need to be bootable, btw). If you have another machine with a working install of DOS, you can pretty much do as foxidrive suggested and transfer the boot files to the hard drive (so it starts up). HOWEVER one connotation of this is that you have to copy the CD-ROM driver file(s) over and get autoexec and .config.sys working with it, so that you can copy the rest of the DOS system. Copying from the floppies if I recall consists of using a "extract" program that decompresses the file. Example, find.exe is actually find.ex_ on one of the disks, and to get it on your hard drive would mean using extract. Of course there are "shady" ways to get the files, but that sort of defeats the intent with having the floppies to begin with.Quote from: BC_Programmer on August 18, 2012, 09:18:12 PM This would give a too many parameters error. sys only accepts a target drive. Au contraire. It accepts source and target. Quote from: BC_Programmer on August 18, 2012, 09:18:12 PM Or they could find them on their setup disks. True, if they can extract all the files. It'd be easier to find a repository of them.Quote from: BC_Programmer on August 18, 2012, 09:18:12 PM Nobody said anything about batch files. Yes, that was my mistake. I thought this subforum was related to batch files but I can see now that it's MSdos-anything.Hi, Thanks for suggestions. I do have access to the laptop CD-ROM - have also managed to create a CD with FDISK/FORMAT on which boots up. >actually use a complete disc for each floppy (with the appropriate label)< >use of a CD-ROM driver on the first one to get access to the drive. (the second two would not need to be bootable< I'll try the 3 separate CDs route first - I have already got the first one working and starts the install process. I do have another machine which is dual boot DOS/XP so will try the suggestion of using 3 CD separate CD initally. I do have a another machine which has dual boot DOS/XP so I could investigate that later - nor sure I understand the full implications of how to do that YET - a bit early in the morning at present. PeterQuote from: foxidrive on August 18, 2012, 11:44:35 PM Au contraire. It accepts source and target.So it does. Though arguably in this case specifying a source is probably redundant. Quote True, if they can extract all the files. It'd be easier to find a repository of them. Turns out the program is expand, not extract; (extract is the program for the same purpose provided with windows). With each disk, one could do this command with each floppy/disk contents, after setting up the basic DOS system on C: and copying EXPAND.EXE as well as getting a working setup for the CD-ROM drive with the driver and MSCDEX: Code: [Select]expand -r A:\*.??_ C:\DOS We want a basic DOS setup with CD-ROM support. you can get this with the first disk, which you have successfully used. You will also need a CD-ROM driver. My personal favourite is OAKCDROM.SYS. You will need to run the sys command on the hard disk, create a DOS folder, and copy over MSCDEX.EXE and the CD-ROM driver (which is not on the disk, this will need to be acquired separately). You will also want to copy EXPAND.EXE to the DOS HD directory. CONFIG.SYS and autoexec.bat should be created on the HD looking like this: CONFIG.SYS Code: [Select]DEVICE=C:\OAKCDROM.SYS /D:OAKCD PATH=C:\DOS autoexec.bat Code: [Select]MSCDEX /D:OAKCD With a basic setup this ought to boot fine. You should then be able to run EXPAND on the contents of each disk. This means you could easily just throw the contents of disk 2 and 3 onto the same image as a subdirectory (eg. DISK1 and DISK2) since the volume label is only needed by the setup program and this is essentially a manual install. Then you just expand the files in each directory in the CD-R: Code: [Select]EXPAND -r D:\*.??_ C:\DOS\ EXPAND -r D:\DISK1\*.??_ C:\DOS\ EXPAND -r D:\DISK2\*.??_ C:\DOS\ This will expand the compressed files, You might want to look through them for the uncompressed equivalents, (since a few files are not compressed) and copy those over manually. After which, you should have DOS installed. According to Microsoft: http://support.microsoft.com/kb/80751 Quote Although the MS-DOS asterisk (*) and QUESTION mark (?) wildcards are not supported by the EXPAND command You can't use wildcards.(run while in the source folder) Code: [Select]for %P in (*.??_) do expand -r %P C:\DOS Quote from: BC_Programmer on August 19, 2012, 05:31:19 AM (run while in the source folder) You will get a syntax error with that command as according to the MSdos V6.22 help there are no switches in expand syntax. Quote from: foxidrive on August 19, 2012, 05:54:25 AM You will get a syntax error with that command as according to the MSdos V6.22 help there are no switches in expand syntax.I was basing it on a direct expand /? from a DOS 6.22 system. However, I have windows 3.1 installed there as well, which puts the windows folder first in the path, so this expand.exe is in fact expand.exe from windows 3.1. Not that it's particularly difficult to workaround, though. Code: [Select]expand A:\*.ex_ C:\DOS ren C:\DOS\*.ex_ C:\DOS\*.exe of course this would have to be done with each file mapping (ex_ to exe, here, 38_ to 386, HL_ to HLP, OV_ to OVL, DL_ to DLL. It's a good thing some of us are looking for SOLUTIONS rather than problems.Quote from: BC_Programmer on August 19, 2012, 06:57:19 AM
So. Who's solution is far easier to use - yours, which still requires a lot more work to fully implement, or copying the files from a repository? Perfectly legal as you have the source disks. Maybe you should take your sig quote to heart...Quote from: foxidrive on August 19, 2012, 07:18:16 PM So. Who's solution is far easier to use - yours, which still requires a lot more work to fully implement, or copying the files from a repository? Neither. The only difference is where the unexpanded files are sourced. |
|
| 7687. |
Solve : Encrypt zip files within a batch file and then email? |
|
Answer» I just installed WINZIP 16.0 and the WZZIP DOS utility. I have dozens of FILES I need to ENCRYPT using predefined passwords. The format for the WZZIP file is: dir *.xls /b >mylist.txtYou could edit that file by hand and add the passwords. Doing part of the work by hand is quicker that taking three days to find a clever batch program to do the whole think in one whack.Don't know if batch is capable of e-mailing files, but you can use: Code: [Select]@echo off set /p path=Enter the Path to the Folder you Wish to Zip: cd %path% if exist password.txt set /p p=<password.txt if "%p%"=="" WZZIP zip.zip *.xls & exit WZZIP -s[%p%] zip.zip *.xls this should take the password from the first line in 'password.txt' that is located in the folder you wish to zip. If there is no password.txt it will not put a password in. Assuming that WZZIP can use wildcards. otherwise you will need to do something a little more elaberate, will post that later. Code: [Select]@echo off setlocal EnableDelayedExpantion dir *.xls /b >mylist.txt set /p p=<password.txt for /f %%G in (mylist.txt) do (WZZIP -s[%p%] zip.zip %%G) Is the OP still looking for a solution?I don't Know, hasn't posted. |
|
| 7688. |
Solve : Exiting dos command prompt from within a batch script? |
|
Answer» I have 3 batch scripts. The first executes the second as part of a loop. The second executes the third as part of a loop also. The point is to spawn 4 separate threads that each loop over a few process input files running some PROCESSES on each input file. |
|
| 7689. |
Solve : list dir into variable? |
|
Answer» I'm trying to set up an email alert (using blat) for a batch file and I've got most of it done. One thing remains.... I want to include the directory list in the body of the email, but am having trouble figuring out how to add the directory list into the variable that I'm using. I've found a few examples around the internet, but NONE of them seem to work. I'm trying to set up an email alert (using blat) for a batch file and I've got most of it done. One thing remains.... I want to include the directory list in the body of the email, but am having trouble figuring out how to add the directory list into the variable that I'm using. Another way is to simply create a file containing the DIR list and attach it to the email using BLAT or get BLAT to include it as the body of the email. dir /b >file.txtIt might be worth pointing out that the HTML line-break element is either or , and never . If the email is a plain text format and not HTML format (or the email software interprets it as plain text), you will not get the line breaks you want and should use the character code(s) for a line break instead.Quote from: TechnoGeek on September 11, 2012, 11:06:57 PM It might be worth pointing out that the HTML line-break element is either look at your response and you'll see why I put the \ in there. Blat has a handy little -html flag that formats the message at html.... I think we'll do fine with that. I tried using line break character codes, but none of them seemed to work for Outlook... Quote from: Lemonilla on September 11, 2012, 07:06:24 PM if you want the characters '<\br>' you should be able to change 'echo !a! \ %%G' to 'echo !a! ^<br\^> %%G' Thanks Lemonilla. the ^ fix worked. Now I'm getting some other errors when it gets to the part with the 3,1000 in it. Also, I can't get the ^ fix to work on other statements, such as: SET emailbody=%emailbody%^%timestamp% Quote from: foxidrive on September 11, 2012, 07:39:02 PM Another way is to simply create a file containing the DIR list and attach it to the email using BLAT or get BLAT to include it as the body of the email. I thought about that, but I could only make the list an attachment. I would rather have it as part of the message. But the way it's going, I might resort to that. Edit: I just ran a test with setting a variable with a ^ in it. Code: [Select]SET test=blahblah^<br^>morestuff ECHO %test% The System cannot find the file specified. Why would it return that when I run the ECHO statement? If I enter SET, and look through the list of USED variables, test has the correct string, but I just can't use it for anything..... What am I missing?Quote from: michaewlewis on September 12, 2012, 09:36:30 AM Why would it return that when I run the ECHO statement? If I enter SET, and look through the list of used variables, test has the correct string, but I just can't use it for anything..... The string %test% contains a < character and a > character. You had to escape them to get them in there, but when you echo %test% the shell expands the variable and finds them. To stop that happening use quotes Code: [Select][64] [64]C:\>SET test=blahblah^<br^>morestuff C:\>echo %test% The system cannot find the file specified. [64]C:\>echo "%test%" "blahblah<br>morestuff" Quote from: Salmon Trout on September 12, 2012, 12:04:38 PM The string %test% contains a < character and a > character. You had to escape them to get them in there, but when you echo %test% the shell expands the variable and finds them. To stop that happening use quotes Is there a way to remove the quotes from the output, while still ignoring the < and >?Quote from: Lemonilla on September 13, 2012, 01:42:06 PM Is there a way to remove the quotes from the output, while still ignoring the < and >? Get the string with quotes into a FOR variable and strip the quotes off with the ~ (tilde) modifier. Full details in the FOR help (FOR /?) Code: [Select]C:\>SET test=blahblah^<br^>morestuff C:\>echo %test% The system cannot find the file specified. C:\>echo "%test%" "blahblah<br>morestuff" C:\>for %A in ("%test%") do @echo %~A blahblah<br>morestuff Remember you use one percent sign for the FOR variable (e.g. %A) at the prompt, but TWO in a batch script (e.g. %%A). |
|
| 7690. |
Solve : rename files in a folder stucture? |
|
Answer» Hello, |
|
| 7691. |
Solve : Batch File to List File Names into 2 column TXT file? |
|
Answer» Hi, Code: [Select]@echo offI would rather not assume that the words document and client are hard coded into the file names. |
|
| 7692. |
Solve : Xcopy with dynamic file name as parameter? |
|
Answer» I need to copy a file from one DIRECTORY to ANOTHER directory using xcopy. The file that I need to copy is ALWAYS named differently based on the date it was created. |
|
| 7693. |
Solve : Converting a GNU Make to a Windows .bat (recursive sub-dirs feeding an app)? |
|
Answer» I am trying to recursively feed pandoc all of the HTML files in a directory and sub-directories and have it generate one Markdown file. Linux can read NTFS, but makes some errors in the index upon writes. So you would want to have a FAT32 partition to get around this.I've not run into that issue. Fairly sure they resolved it. I think that was a bug in some of the early writable NTFS FS implementations added to the Kernel.You are right. After kernel 2.6 there should be no problem. See the Linux item inn the Wikipedia link. OR http://en.wikipedia.org/wiki/NTFS#LinuxQuote from: Geek-9pm on June 29, 2012, 02:59:30 PM Welcome to CH I am just looking for the way to feed pandoc all files in the current, and all sub directories, that end in .html In short, I am trying to convert html to Markdown for some Javadoc I have that is spread across the current, and child directories. Thanks!I have no idea what pandoc is or what you use it for so maybe you can start by clarifying that. If you want a list of all HTML files in a directory and sub directories and be able to use them you can do this. Code: [Select]For /F "delims=" %%G in ('dir /b /a-d /s *.html') do echo %%GQuote from: Squashman on June 30, 2012, 11:47:42 AM I have no idea what pandoc is or what you use it for so maybe you can start by clarifying that. Pandoc is a conversion routine that can convert from HTML (and many others) into Markdown (and many others). It just needs to know where to grab the files from. For example this tells Pandoc the source is HTML format, the output is Markdown format, the output file is output and the input sopurce is all HTML files in the current directory: pandoc -f html -t markdown -s *.html -o output Can you break that down a little better for me. I am looking at the pandoc documentation and from your example I can't tell what the input file is and what each of those options are. You certainly explained it in your description but you didn't say option F does this and option S does this. Are you wanting to take all the HTML files and put them into one OUTPUT file or do you want each html file to have its own output file? If your ran my existing batch file you will see that the variable %%G is showing each HTML file is it finding. You should be able to use that variable with your pandoc execution. Just remove the echo %%G and put your pandoc command there using %%G for your input file name.-f is from, -t is to, (as in format types) -s is source, -o is destination (for file names)Quote from: BC_Programmer on June 30, 2012, 05:46:54 PM -f is from, -t is to, (as in format types) -s is source, -o is destination (for file names)I read this webpage but I could not find any documentation that said -s is for source. http://johnmacfarlane.net/pandoc/README.htmlnevermind. It's probably it's own switch (apparently, standalone). Most *nix style utilities will accept a "loose" file specification as their input.I see your question is already answered about what the switches stand for. What you are suggesting then is something like this: For /F "delims=" %%G in ('dir /b /a-d /s *.html') do pandoc -f html -t markdown -s %%G -o output That look about right? I'll give it shot. Thanks! Quote from: Squashman on June 30, 2012, 05:02:09 PM Can you break that down a little better for me.Quote from: BC_Programmer on June 30, 2012, 06:35:07 PM nevermind. It's probably it's own switch (apparently, standalone). Most *nix style utilities will accept a "loose" file specification as their input.The documentation just shows to put the input file as the last option in the command line with no switch so I am not sure where the OP is getting the documentation to use -s for the input file.Quote from: Squashman on July 01, 2012, 12:38:02 PM The documentation just shows to put the input file as the last option in the command line with no switch so I am not sure where the OP is getting the documentation to use -s for the input file. Yes, the -s shouldn't be there. Just leave it with the source file at the end. What I ended up wish looks like this: For /F "delims=" %%G in ('dir /b /a-d /s *.html') do pandoc -f html -t markdown -o %%G.md %%G That will take each HTML file in the entire structure and create a Markdown version of it. Thanks! One other question though. Is it possible to roll up all of the HTML files in a given sub directory into one output file instead of one file per input file? For example: subdir1 a.html b.html c.html Instead of having a, b, and c, just have one file containing all three and name it subdir1 with the md EXTENSION (since it is Markdown format it will append the .md automatically). Quote from: darrinps on July 02, 2012, 08:48:56 AM
This is untested: Code: [Select]@echo off for %%a in ("%cd%") do copy *.html "%%~nxa.md" |
|
| 7694. |
Solve : How to import data from .csv file into Access DB or SQL server DB using DOS.? |
|
Answer» Hi Team, |
|
| 7695. |
Solve : Quoted path with space in it still results in error? |
|
Answer» Hello All, I appreciate this. It doesn't quite work as I keep getting the error file not found. The section of the code that says *atched randomdates*.sps" is there to find files with these characters (along with any other characters) in their names. As such it isn't a part of the directory structure as such. It's part of the file system. I forgot to add /s after the /b That recurses through folders. |
|
| 7696. |
Solve : Determining the length of an environment variable? |
|
Answer» I am TRYING to determine the LENGTH of an environment variable. I tried this: |
|
| 7697. |
Solve : Compressing Multiple Files with 7zip via CMD? |
|
Answer» I am trying to COMPRESS over 100 files to 7z in 7zip. However, I have to select each files to compress them. |
|
| 7698. |
Solve : Big banks using DOS? |
|
Answer» Hi, What is PUSHD ? It's a command to change the current directory. Not really sure what it has to do with this, particularly because it's not on DOS systems (rather being a part of the NT command interpreter) Quote This system is to open new accounts (I would think an important part of their business). This is precisely why they are still using the DOS implementation. By updating the software and system, they have everything to lose, and nothing to gain; First, new systems are prone to problems both technologically (migrating old databases,adapting defunct database formats, conversions,ETC) as well as employee-wise, since they would need to retrain their staff to use the new system, and mistakes and problems that crop up as a result of that need to be DEALT with as well. This is no different for things like cash registers, which are equally important for the business of a retail store. Many of them use DOS-based software as well- because it works. usually the way it works in these places is they keep using the software until it no longer meets their needs; either they have new business requirements and cannot change the program because they don't have any of the original devs, don't actually own the software, or a myriad of other things. Once that happens, they then move forward. For example, grocery stores in my area predominantly used a DOS-based system, but I noticed that with the introduction of the Harmonized Sales Tax, many of them migrated to Windows-Based POS terminals, which leads me to believe the original software was not flexible enough for adding HST to sales, or something to that effect. |
|
| 7699. |
Solve : Does %1 have limitation on certain characters? |
|
Answer» That looks just LIKE what I was looking for. Also at the end the echo %url% requires to be echo !url! on my system. That is because you changed set "repl=^&" to set repl=&. Quotes and caret are both necessary if you want to use %url% at the end. Batch scripting has special characters and & in a string is notorious. (Did you not see the output listing I made?) Briefly, when the command interpreter encounters certain "special characters" it treats them as control characters unless you make special arrangements. Usually this means "escaping" them. The caret (^) is the escape used for most special characters but some are differently escaped. For example (you can try stuff like this out at the prompt) A single ampersand is the command separator so an unescaped one means "everything after me is a new command" e.g. cls & dir & echo hello world 1. Ampersand (&) unescaped, setting the variable fails Code: [Select]c:\>set string=cats & dogs 'dogs' is not recognized as an internal or external command, operable program or batch file. c:\> 2. Escaped in the SET statement, so that works... Code: [Select]c:\>set string=cats ^& dogs c:\> but LOOK what happens when we try to expand the variable Code: [Select]c:\>echo %string% cats 'dogs' is not recognized as an internal or external command, operable program or batch file. c:\> 3. We both escape the & with a caret and enclose the assignment portion of the SET statement with quotes The assignment works... Code: [Select]c:\>set "string=cats ^& dogs" c:\> So does the expansion... Code: [Select]c:\>echo %string% cats & dogs c:\> Excellent page at http://www.robvanderwoude.com/escapechars.php where I got this table: Escape Characters Character to be Escape Remark to be escaped sequence % %% May not always be required in doublequoted strings, just try ^ ^^ May not always be required in doublequoted strings, but it won't hurt & ^& < ^< > ^> | ^| ' ^' Required only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used ` ^` Required only in the FOR /F "subject" (i.e. between the parenthesis), if backq is used , ^, Required only in the FOR /F "subject" (i.e. between the parenthesis), even in doublequoted strings ; ^; = ^= ( ^( ) ^) ! ^^! Required only when delayed variable expansion is active \ \\ Required only in the regex pattern of FINDSTR [ \[ ] \] " \" Yes I noticed the '^' in your output listing. Not understanding the significance of the &, I thought it was a mistake. That's why I mentioned it. Your explanation and description clears it up. I bookmarked the link you supplied. Without experts such as yourself, there would be no point in posting in forums such this. I have learned a lot and have it all working now. Thank you very much.I am working on a method where you use a table of replace pairs e.g. [equals =] [and &] [comma ,] which would remove the IF tests from the loop and make modification easier. Quote from: Frank on July 08, 2012, 02:01:06 AM I thought it was a mistake. In general, I test scripts before posting them. That does not mean I don't make mistakes! Note: whichever scheme you use, you will find that if you use simple replacement tokens such as and for &, comma for , etc you may break urls because for example sand will become s& and commander will become either ,nder or comm&er (depending on the order you do the replacement) and so on. This may not matter but if it does I'd use tokens you will never find in the range of urls you expect to process e.g. $$$$$$$and$$$$$$$ or replaceAND or whatever. Code: [Select] @echo off setlocal enabledelayedexpansion set url=\"equalandcommaspacesemisemisemi\" set ReplaceList=equal and comma semi space set url=\"http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\" REM Alternative ways of building replace table string REM set ReplaceTable="equal:=" "and:^&" "comma:," "semi:;" "space: " set ReplaceTable= set ReplaceTable=%ReplaceTable% "equal:=" set ReplaceTable=%ReplaceTable% "and:^&" set ReplaceTable=%ReplaceTable% "comma:," set ReplaceTable=%ReplaceTable% "semi:;" set ReplaceTable=%ReplaceTable% "space: " echo Start echo url %url% echo. echo Remove first two characters set url=%url:~2% echo url %url% echo. echo Remove final two characters set url=%url:~0,-2% echo url %url% echo. echo In loop... for %%A in (%ReplaceTable%) do ( set "ReplacePair=%%~A" for /f "tokens=1,2 delims=:" %%B in ('echo !ReplacePair!') do ( set "search=%%B" set "repl=%%C" For %%D in ("!search!") do ( for %%E in ("!repl!") do ( SET "url=!url:%%~D=%%~E!" ) ) echo url !url! ) ) echo. echo Finished loop echo unquoted url !url! REM quotes will shield the & from the command interpreter echo quoted url "%url%" Code: [Select]Start url \"http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\" Remove first two characters url http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\" Remove final two characters url http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1 In loop... url http://www.tek-tips.com/threadminder.cfm?pid=287andpage=1 url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1 url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1 url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1 url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1 Finished loop unquoted url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1 quoted url "http://www.tek-tips.com/threadminder.cfm?pid=287&page=1" WOW, you've been busy. This is great. Just tried it. Thanks again.Tidied up and some (hopefully) clarifying comments... Code: [Select] @echo off REM you need this setlocal enabledelayedexpansion set url=\"http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\" REM Alternative ways of building replace table string REM (1) all in one line REM set ReplaceTable="equal:=" "and:^&" "comma:," "semi:;" "space: " REM (2) Start with blank string and append elements one by one (note SPACES) set ReplaceTable= set ReplaceTable=%ReplaceTable% "equal:=" set ReplaceTable=%ReplaceTable% "and:^&" set ReplaceTable=%ReplaceTable% "comma:," set ReplaceTable=%ReplaceTable% "semi:;" set ReplaceTable=%ReplaceTable% "space: " echo Start echo url %url% echo. echo Remove first two characters which are \" set url=%url:~2% echo url %url% echo. echo Remove final two characters which are \" set url=%url:~0,-2% echo url %url% echo. echo In loop... REM read each element of replace table; the spaces betwen the elements are the delimiters for %%A in (%ReplaceTable%) do ( REM remove quotes using ~ variable MODIFIER set "ReplacePair=%%~A" REM Split pair into 2 tokens at : character (arbitrarily chosen) for /f "tokens=1,2 delims=:" %%B in ('echo !ReplacePair!') do ( REM Prepare string substitution REM Search is first (explicit) loop variable %%B set "search=%%B" REM Replace is second (implicit) loop variable %%C set "repl=%%C" REM This is a trick to use variables in string substitution For %%D in ("!search!") do ( for %%E in ("!repl!") do ( REM Execute string substitution SET "url=!url:%%~D=%%~E!" ) ) echo url !url! ) ) echo. echo Finished loop REM Delayed expansion or quotes will shield the & from the command interpreter echo unquoted url !url! echo quoted url "%url%" This will make it a little easier to figure out how it works. Great |
|
| 7700. |
Solve : Send email after completion of batch file execution? |
|
Answer» is there any way to send an email after completion of the batch file execution?Try this: rkp, should you wish to enhance the capabilities of foxidrive's Thanks Ocalabob, and I confirm that there are other good solutions at Timo's link. |
|