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.
| 951. |
Solve : batch file data to email? |
|
Answer» I need a batch file which will search folders in this path try this untested code: Thanks, I already MAKE this, but I can't add in batch 100 lines for 100 folders for every user and adding a NEW one everytime I add user to backup. So batch need search folders and add result to one file which can be sended with bmailSo you want to check D:\users\*\users\documents then? If so look at the command for /r.still have no clue how to put that search into one txt fileThis untested: Just a comment here that some social lubrication is nice in a forum, so you could add a thank you to the people that have replied even if you only add "still have no clue how to put that search into one txt file". Code: [Select]echo off for /d %%a in ("d:\users\*") do ( if not exist "%%a\Users\Documents\*--datet.txt" >>"file.log" echo Missing: "%%a\Users\Documents\*--datet.txt" ) pause thank you for helping. After 3 hours of trying to make a batch I write that last post. I really appreciate all help from all of you. Your batch works perfect, like always. thank you again |
|
| 952. |
Solve : How to merge images using gdal-merge and cmd(.bat file)? |
|
Answer» I'm new to these batch thing and I badly need your help. There are 4 to 5 projected IMAGES in one DAY. Let's say I have all the projected images for 3 days. For day 1, the file name are: |
|
| 953. |
Solve : closing program with alt+f4? |
|
Answer» I have one updating software which updates 5 programs. I have one updating software which updates 5 programs. This can be done with a single command probably. Do you use a batch file to start this program? Show us the code here so we don't have to guess what is being done.no, it is a update.exe file when I run it, it opens a window and update programs one by another at the end when It finishes it shows up button CLOSE. I run it over task scheduler and problem is because if that program is opened I can not run it again to update until I press CLOSE button on it. Quote from: Blisk on October 29, 2014, 10:23:12 AM no, it is a update.exe file when I run it, it opens a window and update programs one by another at the end when It finishes it shows up button CLOSE. I run it over task scheduler and problem is because if that program is opened I can not run it again to update until I press CLOSE button on it. It looks like it isn't a command line program, but a GUI program. There isn't enough information about the task - I was assuming it was a command line program running from a batch file because you wanted to automate the closing of the window. It helps to provide relevant details about the task in the first post, so that your readers can understand what it is that you are doing and how it operates. Otherwise we have to use our crystal balls, and mine's at the mechanic for it's 6 month overhaul.yes, sorry I thought I explained good what program is. Yes it is gui and problem is updating again not working until first instance is closed. |
|
| 954. |
Solve : Rename first file with structure name.? |
|
Answer» Hi All, |
|
| 955. |
Solve : rename a directory whit the command move? |
|
Answer» hello all, i have a work to do in my class and one of the TASK is to rename the directory (fantasme) for (reve) but whit what i know in ms-dos 6.22 i can just change the name whit the COMMANDE move or xcopy. |
|
| 956. |
Solve : batch file sends mail after zipping? |
|
Answer» Hi i am totally new to the Batch file concept. |
|
| 957. |
Solve : Batch: convert text file to CSV? |
|
Answer» I have 11 plain text files which I want to open up in Excel. Each file has a different record type and different record length with the following attributes: fixed column lengthDo you mean fixed width? If that is true, parsing is not even needed. I am confused because your sample implicates fixed width FIELDS. Please clarify. Thanks.Geek, what is confusing you about a fixed length field vs a fixed width field? They are one in the same in my world of data processing.Well, whee records and fields are fixed size , parsing is just using what is in the filed, n o need to find the end. But CSV is often used to compress the size of files and to transport to other programs that do not have the field definitions. Just wanting to follow the logic. Pardon me. Here is one method using a batch script and helper batch file: This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat Place `repl.bat` in the same folder as the batch file or in a folder that is on the path. There are only three lines of code here: Code: [Select]echo off type "file.txt"|repl "^(.{2})(.{6})(.{6})(.{4})(.{2})(.{30})(.{5})(.{4})(.{10})" "\q$1\q,\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q," x |repl "^(.{96})(.{2})(.{2})(.{1})(.{8})(.{5})(.{4})(.{6})(.{5})" "$1\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q," x |repl "^(.{153})(.{10})(.{1})(.{15})(.*)" "$1\q$2\q,\q$3\q,\q$4\q,\q$5\q" x >file2.txt pause In the second and third invocations of repl in the same line, the first term in the search term - such as (.{96}) - is equal to the length of the modified output of the command before it, and then it continues with setting the field widths of the following terms. If you remove the code, in the middle line from the second | and onwards - and run it, then you will see what the first repl command does and which may make it a little clearer. It's a little clumsy in the construction with multiple calls of repl, but it is very robust and quick on large files, compared to plain batch code. Dave Benham has just written Jrepl.bat at dostips.com which should do it in a much more straight forward way if you ask him there, and show him this code and your question. Your input file Code: [Select]AB012345AC 201399Long name 55555198900006589673101N008500000008200979999999999900015294260999999999999999 AB012345ABC 201399Another long name 11111194500000012023203N000313200001840909999999999900000260524999999999999999 AB012345ABCD 201399three times 33333199600003609819104N004265000008000979999999999900005823119999999999999999 The output Code: [Select]"AB","012345","AC ","2013","99","Long name ","55555","1989","0000658967","31","01","N","00850000","00082","0097","999999","99999","0001529426","0","999999999999999"," " "AB","012345","ABC ","2013","99","Another long name ","11111","1945","0000001202","32","03","N","00031320","00018","4090","999999","99999","0000026052","4","999999999999999"," " "AB","012345","ABCD ","2013","99","three times ","33333","1996","0000360981","91","04","N","00426500","00080","0097","999999","99999","0000582311","9","999999999999999"," " If your lines do not contain any commas then this simplification can be used: Code: [Select]echo off type "file.txt"|repl "^(.{2})(.{6})(.{6})(.{4})(.{2})(.{30})(.{5})(.{4})(.{10})" "$1,$2,$3,$4,$5,$6,$7,$8,$9," |repl "^(.{77}).(.{2})(.{2})(.{1})(.{8})(.{5})(.{4})(.{6})(.{5})" "$1,$2,$3,$4,$5,$6,$7,$8,$9," |repl "^(.{118}).(.{10})(.{1})(.{15})(.*)" "\q$1,$2,$3,$4,$5\q" x |repl "," "\q,\q" x >file2.txt pause Where the terms (.{77}). and (.{118}). refer to the leading parts that were changed by the preceding repl commands, respectively.Hey foxidrive - new site for me I don't understand why you made your code so complicated. The following long one liner works for me (I used line continuation): Code: [Select]type myfile.txt|repl "^(..)(.{6})(.{6})(....)(..)(.{30})(.{5})(....)(.{10})(..)(..)(.)(.{8})(.{5})(....)(.{6})(.{5})(.{10})(.)(.{15})(.{10})" ^ "\q$1\q,\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q,\q$10\q,\q$11\q,\q$12\q,\q$13\q,\q$14\q,\q$15\q,\q$16\q,\q$17\q,\q$18\q,\q$19\q,\q$20\q,\q$21\q" x >test1.csv You can use up to 99 captured sub-matches. This problem only requires 21. Using the new JREPL.BAT is nearly identical. You can specify the input and output files as options: Code: [Select]call jrepl "^(..)(.{6})(.{6})(....)(..)(.{30})(.{5})(....)(.{10})(..)(..)(.)(.{8})(.{5})(....)(.{6})(.{5})(.{10})(.)(.{15})(.{10})" ^ "\q$1\q,\q$2\q,\q$3\q,\q$4\q,\q$5\q,\q$6\q,\q$7\q,\q$8\q,\q$9\q,\q$10\q,\q$11\q,\q$12\q,\q$13\q,\q$14\q,\q$15\q,\q$16\q,\q$17\q,\q$18\q,\q$19\q,\q$20\q,\q$21\q" /x /f "myfile.txt" /o "test1.csv" It is probably easier / more reliable to let code build the search and replace strings. Because this solution is passing the strings as variables, I am able to embed the quotes directly instead of using \q with the /X option. Code: [Select]echo off setlocal enableDelayedExpansion set "search=^" set "replace=" set /a n=0 for %%N in (2 6 6 4 2 30 5 4 10 2 2 1 8 5 4 6 5 10 1 15 10) do ( set /a n+=1 set "search=!search!(.{%%N})" set "replace=!replace!"$!n!"," ) set "replace=!replace:~0,-1!" call jrepl search replace /v /f test.txt /o test1.csv Dave Benham Quote from: dbenham on November 14, 2014, 09:48:50 PM Hey foxidrive - new site for me Nice to see you here Dave. Quote I don't understand why you made your code so complicated. D'oh! I thought it only worked up to 9 back-references, like GNUsed does! Mea Culpa! Thanks for the info. Quote It is probably easier / more reliable to let code build the search and replace strings. Because this solution is passing the strings as variables, I am able to embed the quotes directly instead of using \q with the /X option. And that's a clever way to clarify the field widths in the command. Welcome Aboard dbenham ! ! Quote from: patio on November 15, 2014, 07:26:58 AM Welcome Aboard dbenham ! !DittoSorry for the long delay in replying. I am doing this at work, and FRIDAY the forum server was down, Monday I was GIVEN a priority assignment for QA, and yesterday I was out of the office. Thanks for all of your input. I had seen previously references to repl.bat by dbenham, but I did not see how I could incorporate that logic into my situation. I will give this code a try. |
|
| 958. |
Solve : IE properties? |
|
Answer» I wrote a batch file to create INTERNET Explorer favourites and it successful. |
|
| 959. |
Solve : Project all the images/newest images that were added to the directory(.bat,cmd)? |
|
Answer» I was able to project all the level 2 hdf files and saved the projected files to the new(CREATED) directory using this script: |
|
| 960. |
Solve : Batch code that copies a specified folder outside another specified folder path? |
|
Answer» Hi , I need to search for a folder which has some XML files in it and move it to another location. Do you have to search for just one XML file to identify the folder? Quote If I give the destination location as d:/ABC/def I need that folder to be moved to d:/ABC . Why do you specify the destination location as d:\abc\def when you want to move the detected folder to d:\abc |
|
| 961. |
Solve : creating file from computer name? |
|
Answer» If someone can help me with this. OK I did itHow does this solve your problem? You said you needed to check if the computer name has HP in the name.This batch makes file with computername like mike10-HP.txt and second batch search for file with *-HP.txt if batch found that file than it makes backup, if not, than doesn't.This is another method which should work: Code: [Select]echo %computername%|findstr /e /i "-HP" >nul && (goto :backup) || (goto :FINISH) and this: Code: [Select]if /i "%computername:~-3%"=="-HP" (goto :backup) else (goto :finish)thank you, tihis one is better I will use it Quote from: Blisk on October 29, 2014, 08:42:15 AM This batch makes file with computername like mike10-HP.txtUgh! I guess you didn't bother to even research my ideas or even LOOK at all your old threads to accomplish this task. Quote from: Squashman on October 29, 2014, 01:51:33 PM Ugh! I guess you didn't bother to even research my ideas or even look at all your old threads to accomplish this task. No it is not that way, I have alot of work to do, so I don't have time now to sarch and learn how to do it so I found quickest way which worked. Quote from: Blisk on October 30, 2014, 01:34:26 AM No it is not that way, I have alot of work to do, so I don't have time now to sarch and learn how to do it so I found quickest way which worked.You are preaching to the choir, but that doesn't keep me from learning new scripting techniques every day. People will only want to give you the FISH so many times. Eventually you have to learn to FISH!unofrtunally everyone can't be fisherman, so thats why you have fish I have BREAD, you give me a fish I give you a bread! The basics I know but in reality what I do with fev lines or 2 batch files you can do with one line, because you have experiences. My work field is windows system and desktop, I use batch files just to make my job easier and I am not a programmer.I never saw you give him bread... Quote from: Blisk on October 30, 2014, 08:14:32 AM unofrtunally everyone can't be fisherman, so thats why you have fish I have bread, you give me a fish I give you a bread!Most Network System Administrators and Desktop Support people are not programmers but are at least required to know some kind of scripting language to automate tasks. I went to school 15 years ago and learning Batch on Windows and BASH on Unix was a requirement for my Network Administration degree. So it has nothing to do with being a programmer.yes you are right, what can I say. |
|
| 962. |
Solve : Batch Counter for Booting Up Windows? |
|
Answer» Hey all, Rettsu here. |
|
| 963. |
Solve : Batch asking question to add value to jar parameter? |
|
Answer» hello all Code: [Select]echo off Additionally, the path variable is a system variable and shouldn't be used as a general purpose variable name, and when you are adding a folder to the path then you can use something like this Code: [Select]set "path=%path%;c:\new\folder" Quote from: foxidrive on November 06, 2014, 04:15:06 AM Additionally, the path variable is a system variable and shouldn't be used as a general purpose variable name,Good catch. I was so focused on the code errors I must have glazed over that. Thanks ! now it looks like this : Code: [Select]echo off path=%path%;d:\AUXID\ set input= set /p input=input the CipherValue "C:\Program Files (x86)\Java\jre8\bin\java.exe" -jar d:\AUXID\SeedDecrypt.jar Ciphervalue %input% hex-key 1FF7738D8A8C5040DC68B9CB4E8DE2A2 >>d:\AUXID\SeedDecrypt.txt echo see file d:\AUXID\SeedDecrypt.txt for infos. echo. pause exit I still have the Java error, but I GUESS it's because I input random $hit. and still my txt file is at 0KB.Not sure why you are screwing around with path variable. It is not needed in your script at all. We would have no idea how to debug your Java program. But I am pretty sure you batch code is rock solid now.Thanks for the Help ! Took out the path variable like you said. Now I just have to figure out the java error. Thanks a lot ! |
|
| 964. |
Solve : Need to Write a batch File? |
|
Answer» Hello guys. I need help with writing a script file. I have over 500000 mp3 files im downloading from my google CLOUD account cause my HD crashed and DIED. All the files are being downloaded to the root of my N: drive. All the files are without folders and have metadata to show album name and artist name. within windows i have "album and artist" show under view attributes. I want to write a script that would create a folder based on the artist name, then move those files based on artist name into said folder e.g Coldplay -XY move to coldplay folder. please can anyone help me?Can't do it with BATCH natively. You will need a command line program that can read the ID3 tags. Once you have that someone can probably write you a script. But until they know what program that can do it, you are out of luck.This TOOL can help you I THINK: From the doc: Create Directories and organize mp3s from ID3 tag info |
|
| 965. |
Solve : i need help on this can someone fix the errors and email me !? |
|
Answer» echo off |
|
| 966. |
Solve : How to Invert Mouse? |
|
Answer» How to Invert Mouse and why.Regardless of the WHY, this does not seem possible with a simple registry hack. It either has to be built-in to the mouse DRIVER or you would need to use a 3rd party utility to make the change. At least that is what I can find from a simple Google search.I need for school project Please help me Is Very Necessary1. We don't do homework here. 2. This is not possible through conventional cmd commands without regedit. I would look into a fuller LANGUAGE like C or C++ if you want to write your own, though I'm sure there is 3rd party software that will do this for you. Your other option is to go into the control panel and look there. There might be SOMETHING of interest under the mouse options.Is this may be through the registry? Quote from: mss9668 on November 13, 2014, 09:29:23 AM I need for school project Has this link been shown here: http://superuser.com/questions/406502/how-can-i-reverse-mouse-movement-x-y-axis-system-wide-win-7-x64 |
|
| 967. |
Solve : Script or batch file to capture the program log? |
|
Answer» Dear All, I have 100 PC to do ping test. May I know how to write the script to capture the result if error or success This should work - with ONE PC address PER line in file.txt Code: [Select]echo off ( for /f "usebackq delims=" %%a in ("file.txt") do ( ping -n 1 %%a |find "TTL=" >nul if errorlevel 1 (echo %%a failed) else (echo %%a passed) ) )>output.log |
|
| 968. |
Solve : Batch file to add date to file name? |
|
Answer» Hello Folks, Was not the point of your question that you wanted one way to get the date in a consistent format so that you could use your SET commands to set the Month Abbreviation in upper case? Why are you still using the DATE command?Thank you foxidrive, your solution works perfect! Quote from: foxidrive on November 03, 2014, 07:29:28 AM Try this:Quote from: Squashman on November 03, 2014, 07:37:09 AM Was not the point of your question that you wanted one way to get the date in a consistent format so that you could use your SET commands to set the Month Abbreviation in upper case? Why are you still using the DATE command? Sorry, I guess I'm not understanding you clearly. Yes, I want to get a consistent date displayed as: DD MMM YYYY (with abbreviated month name in uppercase). However, when I displayed the date using the code you originally provided, the result was displayed as a numeric month. For example, taking your code as is and displaying the output: Code: [Select]ECHO off :: GET DATE and TIME for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YYYY=%dt:~0,4%" set "MM=%dt:~4,2%" set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" set "Min=%dt:~10,2%" set "Sec=%dt:~12,2%" echo %DD% %MM% %YYYY% Displayed results: 03 11 2014 That was why I went back and used a portion of the code I originally had. This enables me to obtain the non-numeric date. [ie: NOV, not 11]. Thank you for your help. You had the code to translate the numeric month to the abbreviated month. Did not THINK I had to add that to the code I gave you. Seemed fairly obvious to me.Not sure why you think it's necessary to belittle me here, but if that's what makes you happy so be it. YEAH, it was obvious to me as well. That's why I did indeed include the month code to translate the months. I was just curious why they had not all been uppercase. And you made a choice to get on my case about using DATE instead of SET. I used what worked properly for me in my particular case. Thanks to the great help of foxidrive, I now have what works awesome. I didn't get on your case about using the date command. I ASKED you a very black and white question. You obviously knew that the regional settings affected the output of the date command and I gave you a consistent date output that wasn't affected by the regional settings and could be used to translate into the month abbreviation using your existing set commands. You then asked again about using the date command again so I asked why you were still trying to use it. Quote from: KenK13 on November 03, 2014, 07:24:37 AM Code: [Select] The code you showed is both peculiar and broken. Your code essentially uses a numeric month to give you a three letter month, and with Squashman's code it works perfectly. The first line above sets the month variable to a THREE character string and then you proceed to compare it with a TWO character string - so it will do nothing and the original month variable will remain TOTALLY unchanged. That is why it failed. I should add that batch is peculiar too and if the string (of two numerals) happened to have a leading or trailing space then it could match in the compares. |
|
| 969. |
Solve : Remove what i think are invisible or printer character from txt file? |
|
Answer» I'm having a hard time capturing the data using a vb script b/c of these characters i noticed in notepad++. This is causing my data to not line up correctly and causing me to capture incorrect data for my sub strings. x86 disassembler Quote from: daillest319 on November 12, 2014, 08:37:05 AM I'm having a hard time capturing the data using a vb script b/c of these characters i noticed in notepad++. This is causing my data to not line up correctly and causing me to capture incorrect data for my sub strings.You can replace them with nothing, effectively removing them from the string Code: [Select]LineResult = Replace(LineResult,Chr(0),"") 'Null character LineResult = Replace(LineResult,Chr(240),"") 'greek character (Delta?) LineResult = Replace(LineResult,Chr(145),"") 'backtick thing LineResult = Replace(LineResult,Chr(15),"") 'Shift In Character I would first eliminate other sources of the characters such as how you are retrieving the data.Thank you all for your help. |
|
| 970. |
Solve : create a batch file with date as folder name? |
|
Answer» Hey, i have CREATED a batch file which copy the data of one folder into another. But after copying i want to give the particular date as a folder name. I am not able to. Please give your suggestions. |
|
| 971. |
Solve : Resume processing of files based on the date of the last processed files? |
|
Answer» The script indicated in here will merge files from the in_path and now will SUCCESSFULLY move the merged files only to ANOTHER directory which is the proc_path. The goal now is to merge the files based on the date of the last PROCESSED files and so on. So that whenever the system is down and you weren't able to process the files let's say for one week, it will just check for the last date where it stop and process it and then process the next date and so on. But how can I do that? Any idea? Not sure why you are posting this here when you already got the original code from DosTips.com. The helpers over there already know what the code does and can probably do a better job of helping you with any changes you need. But I still need help with this. The question above is the last thing that I still need in order to have it done. And I don't know how to do it. |
|
| 972. |
Solve : Seeking help to move files from specifically named directory up one level? |
|
Answer» I have a vast collection of fonts, sorted in different ways depending on where I downloaded them. Many of them are sorted into foundries or families, with a sublevel for designer. Thus: |
|
| 973. |
Solve : Bit version of Microsoft Office and Install Program? |
|
Answer» Here's my situation, trying to write a batch file that will show me the bit VERSION of Office installed, not the OS necessarily, and choose the bit version of Lync to install. Any Ideas? Thanks in advance.All 32bit programs installed on a 64 bit Windows OS will be in the Program Files(x86) folder. How's Zeus doin lately ? ? He has been involved in a controversy of a modern rather than ancient kind. He is depicted as a bull, the form he took when raping Europa, on the Greek 2-euro coin and on the United Kingdom identity card for visa holders. Mary Beard, Professor of Classics at Cambridge University, has criticised this for its apparent celebration of rape. Just don't worship Mary Beard...sounds LIKE every Liberal College Proff here in the states... I won't get started. Quote from: Salmon Trout on December 12, 2014, 10:51:58 AM Surely if you first check the bitness of the OS (if it's 32 bit you now know you have a 32 bit Office install) and if it's 64 bit then look in %ProgramFiles% (64 bit) or %ProgramFiles(x86)% (32 bit) for the Office folder (Office, Office10, Office11, Office12, Office14 or Office15) or else find the path of some common Office executable file such as Winword.exe or Excel.exe, you have your answer? Or am I missing something here? if this is some corporate thing, surely you know what your machines have installed anyhow? This will be a Lync rollout on about 300 machines. The majority, about 85%, are x64 OS's. But we don't know if the Office install is always x86 or x64. Also, Office does not always install in ProgramFiles or ProgramFilesx86. A lot of times it installs in the ProgramData folder, which does not determine if it's a x86 or x64. One more thing, I've had instances where a x86 Office installs in the ProgramFiles directory. Quote from: patio on December 12, 2014, 11:40:26 AM Just don't worship Mary Beard...sounds like every Liberal College Proff here in the states... Well, I am a liberal, and I am opposed to misogyny (like any sane person ought to be) but I don't really think Zeus needs to be dragged into the argument. Maybe in 50 years people will think differently.What version of Lync are you planning to use? The 64-bit Lync 2010 installation works with the 32-bit version of Microsoft Office. If you have a 64-bit machine with a 32-bit Office 2010, you can use the 64-bit Lync Installer. The 64-bit Lync client installation will install the 32-bit version of the Online Meeting Add-In for Lync 2010 for Outlook. The Lync client itself is actually only 32-bit – the 64-bit download is a 64-bit installer wrapping the 32-bit client. See here http://blog.insidelync.com/2012/02/top-10-faq-for-planning-a-lync-2010-client-deployment/ Quote from: col. sanders on December 12, 2014, 11:42:40 AM A lot of times it installs in the ProgramData folder That has got to be because the admin chose to install it there, right? Quote from: foxidrive on December 12, 2014, 12:40:48 PM That has got to be because the admin chose to install it there, right?Has to be. It does not default to that. |
|
| 974. |
Solve : Run 2 Commands, Keep Smallest File? |
|
Answer» Hi again everyone, The q and x files could be the same size. What should happen if that occurs? Well, the two different commands use two completely different compression algorithms. It is very unlikely that they would be exactly the same filesize. But, in that event, I would say it's BETTER to keep the .q file and delete the .x file. Thanks.Test this on some sample files. Code: [Select]echo off for /r DIR_1 %%a in (*) do ( dime -D CO=Q -L %%~dpa "%%a" "%%a.q" make -D CO=X -L %%~dpa "%%a" "%%a.x" for %%b in ("%%a.q") do for %%c in ("%%a.x") do if %%~zc LEQ %%~zb (del "%%a.x") else (del "%%a.q") ) pause Quote from: foxidrive on December 09, 2014, 03:59:57 AM Test this on some sample files. Thanks! Always appreciate the help. Quote from: foxidrive on December 09, 2014, 03:59:57 AM Test this on some sample files. Quick follow-up question: If I wanted to add a third command that would produce a ".z" file, how would I go about adding it in the comparison portion of the script? In other words, what would I need to add to compare 3 files and keep the smallest and delete the 2 larger files? The extra command would be identical to the other two except the file extension would be .z, like so: Code: [Select] make -D CO=X -L %%~dpa "%%a" "%%a.z" I'm hoping it's easy so I can, if need be, add more commands and not need to BOTHER you guys with this one again. Any help would be great.It's not totally straight forward to add one, two, or more commands, with tests. Batch files are frequently written for a SINGLE task and when the task changes, then the batch file can be very different. If you have a task to solve and want a script (rather than just a tip on how to use a technique) then always describe the full task - never ask for a simplified version and add things later. The reason is that the volunteers find little enjoyment in writing a script, and then having to change it because the task wasn't described accurately. http://stackoverflow.com/questions/27422598/this-batch-script-wont-work-why |
|
| 975. |
Solve : ping an address, log errors to text file with timestamp? |
|
Answer» Hi, I don't want him to bounce me into posting an untested and incompletely considered reply. Please bear with us a little longer! No worries and much appreciated.The script below addresses the simplest case I can think of, namely a host which exists and which either is or is not servicing ping requests. If the ping command is "successful" then it looks like this... Code: [Select]C:\>ping -n 1 192.168.56.129 Pinging 192.168.56.129 with 32 bytes of data: Reply from 192.168.56.129: bytes=32 time<1ms TTL=128 Ping statistics for 192.168.56.129: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip TIMES in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms If not, it looks like this Code: [Select]C:\>ping -n 1 192.168.56.129 Pinging 192.168.56.129 with 32 bytes of data: Request timed out. Ping statistics for 192.168.56.129: Packets: Sent = 1, Received = 0, Lost = 1 (100% loss), I only send 1 request for the sake of avoiding network congestion The IP I am using is a local XP machine whose firewall I turn on and off As you will see the meat is in the 2nd non-blank line, and we can examine this and decide whether to write it to a log file, preceded by the date and time. To make a delay I use the free sleep utility which is part of the Windows Server 2003 Resource Kit Tools which you can download here: http://www.microsoft.com/downloads/en/confirmation.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd There are plenty of others around but not all have the -m (milliseconds) feature. Code: [Select]echo off setlocal enabledelayedexpansion set hostIP=192.168.56.129 :loop set pingline=1 for /f "delims=" %%A in ('ping -n 1 -w 250 -l 255 %hostIP%') do ( if !pingline! equ 2 ( set logline=!date! !time! "%%A" echo !logline! | find "TTL=">nul || echo !logline! >> pinglog.txt ) set /a pingline+=1 ) sleep -m 5000 goto loop The IP you used as an example resolves to lr-rns.timik.uk.easynet.net on my machine; I wonder if you are wanting to log times and/or periods of bad Internet connection or whether it was just an example? Thank you so much. Works perfectly. I'll need to substitute my delay choice /N /T 1 /D Y >nul for your rather neater sleep utility as I don't have the option of installing anything. Are you doing a FIND on "TTL" because it is only a healthy reply that would ever have those characters in it? The IP I used in the example is just an ISP's nameserver that hasn't CHANGED in 15 years and for some reason I've always defaulted to it. I'll be using the script to troubleshoot an intermittent network dropout on some servers at work. I plan on pinging a known good IP (our main data centre router) from multiple servers. By correlating the logs I should be able to determine if the dropouts are due to OS, hypervisor, switch or data centre (at least that's my theory!). Thanks again. Love your nic by the way, started reading 'The Salmon of Doubt' by Douglas Adams just yesterday. Quote from: boff on June 11, 2011, 06:36:01 AM Are you doing a FIND on "TTL" because it is only a healthy reply that would ever have those characters in it? Yup. Note the || operator (execute 2nd command if 1st command returns nonzero errorlevel - the opposite of &&) Also note that the message "Request timed out" is quoted because I am echoing %%A, the 2nd nonblank line of the ping output, via a pipe to find, and a healthy response on my system SHOWS the response time field as "time<1mS" and the < symbol in an unquoted literal string or expanded variable breaks script processing because it has a special meaning (redirection). If you don't want the quotes to appear in the log see below Code: [Select]echo off setlocal enabledelayedexpansion set hostIP=192.168.56.129 :loop set pingline=1 for /f "delims=" %%A in ('ping -n 1 -w 250 -l 255 %hostIP%') do ( if !pingline! equ 2 ( set logline=!date! !time! "%%A" echo !logline! | find "TTL=">nul || ( set logline=!logline:"=! echo !logline! >> pinglog.txt ) ) set /a pingline+=1 ) sleep -m 5000 goto loop Before... Code: [Select]11/06/2011 14:44:42.28 "Request timed out." 11/06/2011 14:44:47.78 "Request timed out." 11/06/2011 14:44:53.28 "Request timed out." 11/06/2011 14:44:58.78 "Request timed out." 11/06/2011 14:45:04.28 "Request timed out." 11/06/2011 14:45:09.78 "Request timed out." 11/06/2011 14:45:15.28 "Request timed out." 11/06/2011 14:45:20.78 "Request timed out." After... Code: [Select]11/06/2011 14:47:11.28 Request timed out. 11/06/2011 14:47:16.78 Request timed out. 11/06/2011 14:47:22.28 Request timed out. 11/06/2011 14:47:27.78 Request timed out. 11/06/2011 14:47:33.28 Request timed out. 11/06/2011 14:47:38.78 Request timed out. 11/06/2011 14:47:44.28 Request timed out. 11/06/2011 14:47:49.78 Request timed out. 11/06/2011 14:47:55.28 Request timed out. 11/06/2011 14:48:00.78 Request timed out. 11/06/2011 14:48:06.28 Request timed out. Alternative method using VBScript - save with .vbs extension and call with cscript.exe supplying IP and log file name. In some ways more "elegant", maybe? e.g. cscript mypingscript.vbs 192.168.56.129 logfile.txt Code: [Select]hostIp = wscript.arguments(0) logfilename = wscript.arguments(1) Set fso = CreateObject("Scripting.FileSystemObject") Set Shell = CreateObject("Wscript.Shell") Set logfile = fso.OpenTextFile(logfilename, 8, True) shellstring = "%comspec% /c ping -t " & hostIP Set oExec = Shell.Exec(shellstring) wscript.echo "Ping Error log With Timestamp - Ctrl + C to halt" Do While oExec.StdOut.AtEndOfStream <> True pingline = Date & " " & Time & " " & oExec.StdOut.ReadLine If Not InStr(pingline, "TTL=") Then logfile.WriteLine(pingline) End If Loop Quote from: Salmon Trout on June 11, 2011, 03:08:10 PM Alternative method using VBScript The nice thing about that one is that when you exit the script the ping stats get written to the log file. Unfortunately for me every line is being written to the log file (the "TTL=" isn't working). The original dos script you wrote is perfect though. Thanks again. Quote from: boff on June 11, 2011, 04:10:35 PM Unfortunately for me every line is being written to the log file (the "TTL=" isn't working). Sorry about that... hostIp = wscript.arguments(0) logfilename = wscript.arguments(1) Set fso = CreateObject("Scripting.FileSystemObject") Set Shell = CreateObject("Wscript.Shell") ' OpenTextFile Method requires a Const value ' (Over)Write = 2 Append = 8 Set logfile = fso.OpenTextFile(logfilename, 8, True) shellstring = "%comspec% /c ping -t " & hostIP Set oExec = Shell.Exec(shellstring) wscript.echo "Ping Error log With Timestamp - Ctrl + C to halt" Do While oExec.StdOut.AtEndOfStream <> True pingline = Date & " " & Time & " " & oExec.StdOut.ReadLine If InStr(pingline, "TTL=") = 0 Then logfile.WriteLine(pingline) End If Loop Fantastic. Will implement tonight and let you know how it goes in a couple of days. The fact that with the vbscript you get the ping stats for the whole session written to the tail of the log file is very cool.Wanted to take the time to register on this forum and congratulate Salmon Trout for providing a 1st class solution. I have looked far and wide for something elegant, simple, robust that works and was only able to find it in Salmon's solution. I added TRACERT into the single logical operator line to get additional useful information for troubleshooting: echo !logline! | find "TTL=">nul || echo !logline! >> NetworkPingErrors.txt && echo Running TraceRT, please wait.... && tracert %hostIP% >> NetworkPingErrors.txt && echo ----------- >> NetworkPingErrors.txt Thank you very much sir! Hats off to you. Nice to see after nearly a year that SOMEBODY found it useful. mmedia man, you are using the double ampersand (&&) as a command separator, I hope you remember it is actually an AND operator - that is: command1 && command2 command2 is only executed if command1 returns a zero errorlevel The opposite is the double pipe OR operator. command1 || command2 command2 is only executed if command1 returns a non-zero errorlevel The ordinary command separator is a single ampersand command1 & command2 command2 is always executed example: Code: [Select]C:\>dir /b notexist.fil && echo command2 File Not Found C:\>dir /b notexist.fil & echo command2 File Not Found command2 In most cases it may not matter which one you use, but there may come a situation where a string of commands on one line will halt part way through if you use && when you don't actually intend to test the preceding errorlevel. Quote from: Salmon Trout on June 11, 2011, 06:03:28 PM Sorry about that... just registered this forum to thank you for such an excellent script. however, it still does not print "request timed out" in my case.. it simply writes "ping request could not find host www.google.com. Please check the name and try again." for my case i need to count how many RTO's occured to measure the bandwidth quality. so is there anyway to make it print the rto's as well? thanks |
|
| 976. |
Solve : Update CSV files? |
|
Answer» Hi, That is not a csv file format. The 'c' is 'csv' stands for 'comma'. Your column separator is a pipe character '|'. So please clarify. Thanks Salmon for reply. I agree its Pipe-Delimiter file exported from excel and SAVED as .csv 1. Approx. there are 20000 to 25000 rows and 200 columns. I don't mine if its more faster/flexible to achieve with VBScript, because i have atleast 30 files in which continuously new data is appended and once in month i will have to update/re-arrange it. 2. Yes we can create the temp files. c:\Temp. 3. No, total data is numeric not a single character. Col1=2 numeric, Col2=4 numeric, Col3=1 to 7 numericals and from Col4 fixed 6 numeric. Sample data: ST|BRIN|TP|KEY1|KEY2|KEY3|KEY4|KEY5|KEY6|KEY7|KEY8|KEY9|KEY10|KEY11|KEY12|KEY13|KEY14|KEY15|KEY16|KEY17|KEY18|KEY19|KEY20|KEY21|KEY22|KEY23|KEY24|KEY25|KEY26|KEY27|KEY28|KEY29|KEY30|KEY31|KEY32|KEY33|KEY34|KEY35|KEY36|KEY37|KEY38|KEY39|KEY40|KEY41|KEY42|KEY43|KEY44|KEY45|KEY46|KEY47|KEY48|KEY49|KEY50|KEY51|KEY52|KEY53|KEY54|KEY55|KEY56|KEY57|KEY58|KEY59|KEY60| 53|5305|1|722101|722102|722103|722104|722105|722106|722107|722108|722109|722110|722111|722112|722113|722114|722115|722116|722117|722118|722119|722120|722121|722122|722123|722124|722125|722126|722127|722128|722129|722130|722131|722132|722133|722134|722135|722136|722137|722138|722139|722140|722141|722142|722143|722144|722145|722146|722147|722148|722149|722150| 53|5305|1|745551|745552|745553|745554|745555|745556|745557|745558|745559|745560|745561|745562|745563|745564|745565|745566|745567|745568|745569|745570|745571|745572|745573|745574|745575|745576|745577|745578|745579|745580|745581|745582|745583|745584|745585|745586|745587|745588|745589|745590|745591|745592|745593|745594|745595|745596|745597|745598|745599|745600| 53|5305|1|823126|813002|813003|813004|813005|813006|813007|813008|813009|813010|813011|813012|813013|813014|813015|813016|813017|813018|813019|813020|813021|813022|813023|813024|813025|813026|813027|813028|813029|813030|813031|813032|813033|813034|813035|813036|813037|813038|813039|813040|813041|813042|813043|813044|813045|813046|813047|813048|813049|813050| 37|2037|22|575196|514202|514203|514204|514205|514206|514207|514208|514209|514210|514211|514212|514213|514214|514215|514216|514217|514218|514219|514220|514221|514222|514223|514224|514225|514226|514227|514228|514229|514230|514231|514232|514233|514234|514235|514236|514237|514238|514239|514240|514241|514242|514243|514244|514245|514246|514247|514248|514249|514250| 37|2037|22|713951|713952|713953|713954|713955|713956|713957|713958|713959|713960|713961|713962|713963|713964|713965|713966|713967|713968|713969|713970|713971|713972|713973|713974|713975|713976|713977|713978|713979|713980|713981|713982|713983|713984|713985|713986|713987|713988|713989|713990|713991|713992|713993|713994|713995|713996|713997|713998|713999|714000| The basic algorithm is fairly simple. 1) SORT the INPUT descending so header remains at top. 2) initialize PreviousKey to SOMETHING that will never match 3) for each line: (note, writes are without \n unless explicitly stated) - if 1st line than write line - else if key = previousKey write nonKey data - else write \n + entire line 4) terminate the last line with \n This can be done easily with VBScript or JScript or PowerShell. Or you could use batch coupled with JREPL.BAT Code: [Select]echo off sort /r %1 /o %1 call jrepl "^((?:.*?\|){3})(.*)" "output.Write($1==prev?$2:(prev?'\r\n':'')+$0);prev=$1;false;" /jmatch /jbeg "var prev" /f %1 /o - echo(>>%1 I suppose it could be done with pure batch, but I would worry about performance, as well as the potential for lines to exceed the max batch string length of ~8191 bytes. Thanks, dbenham! I was inclining towards VBScript, because of the Dictionary Object but you have ridden to the rescue! |
|
| 977. |
Solve : How to make exe files with batch files???? |
|
Answer» (If you never seen me, im a new user and i just registered.) If the OP is an expert in batch, it should not be hard to use a general purpose language. Currently he favorite is C++ for most people. One can make good EXE files with C++ that can make use of the Microsoft .NET library. C++ has a use but is only really worthwhile in much lower level programs, there are a lot of much more suitable languages for most tasks. It is certainly not the "favourite for most people". While I personally don't use Batch, for this use (a setup program), a shell scripting language is surely the most suitable since its main job is GOING to likely be moving files around on disk, Trying to use C++ for this would be a right pain, you would end up doing a lot more work for exactly the same output, not to mention all the other issues that crop up with C and C++. |
|
| 978. |
Solve : Sring handling problem? |
|
Answer» Hello, Beat me to it by a matter of seconds Gotta be quick over here Dave. Thanks for addition. I saw the space in the 2nd token but figured they could figure out how to strip it.Shouldn't that be second=%%C. Code: [Select]echo off for /f usebackq^ tokens^=1^*^ delims^=^" %%A in ("file.txt") do for /f "tokens=*" %%C in ("%%B") do ( set "first=%%A" set "second=%%C" ) echo %first% echo %second% pauseLemonilla, thank you for fixing my example. I would like to use a space for the delimiter. Unfortunately, this may be too difficult. Squashman, Thank you for offering another way. That is, going back one step and extracting the text form the file and splitting the text in one go. However, I notice that it only works if there is a space in the first path. There may be, in my case, where there is no space or more than one space in the first path and the script fails. As mentioned above, I might need to change my delimiter. I am not understanding you. It works with the example you provided. If it is not working then provide a non obfuscated example of your data that it is not working with.OK, yes it does work with the example I supplied. But, as I said if there are more or less spaces in the path it fails. I intended to enter more than one line in the file.txt file and process each line in turn. A couple of real examples: D:\MyProgs\DriveGleam\drivegleam.exe /startup "C:\Program Files (X86)\DropMyRights\DropMyRights.exe" "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe" Just to show a couple.Shouldn't have any problems with spaces as the code is using the double quote as the delimiter. But, you need to be consistent with your input. One example you just showed has no quotes.Thank you. I thought that script was using 2 spaces as the delimiter. Goes to show how well I understand batch scripting. I'll use double quotes. Quote from: Frank on December 17, 2014, 08:34:24 PM Thank you. I thought that script was using 2 spaces as the delimiter. Goes to show how well I understand batch scripting.I did specifically say in my first post I was using a double quote as the delimiter. Quote from: Frank on December 17, 2014, 08:34:24 PM Thank you. I thought that script was using 2 spaces as the delimiter. if you can control the delimiter and are using filename\paths then using a pipe character is a good choice as a delimiter. or a * or ? or < or > as none of them can be in a path\filename. Quotes are a poison character in batch scripts in many ways. Quote from: foxidrive on December 17, 2014, 11:26:04 PM if you can control the delimiter and are using filename\paths then using a pipe character is a good choice as a delimiter.I am in 100% agreement with you on that. It works flawlessly for us where I work. I do data automation for a living and we have all of our customers send in their data PIPE delimited. |
|
| 979. |
Solve : Shutdown the computer using an .exe file done in Code Blocks? |
|
Answer» Hello guys. |
|
| 980. |
Solve : Help needed for a batch file to extract data from text files? |
|
Answer» Hi, |
|
| 981. |
Solve : Handle ampersand "&" inputted by user in batch file.? |
|
Answer» I have a batch file that takes user input and places it in a variable. The problem is that sometimes the user may enter an "&" symbol which then causes the script to TRY to process the string after the & as a command. I need the script to take the ampersand and place it variable string and then convert it to url encoding. For example: I see you posted an almost similar question in the Computer Programming category. The code is basically the same as what Salmon Trout had posted for you for the spaces. Not sure why you didn't attempt to modify his code for the Ampersand replacement. I actually did, but with the code: Code: [Select]echo off & setlocal enabledelayedexpansion set /p "variable1=Enter Input:" set "variable2=!variable1:&=%%26!" set "variable3=!variable2: =%%20!" set "variable4=!variable3:,=%%2c!" echo %variable1% echo %variable2% echo %variable3% echo %variable4% pause I get the output: Code: [Select]Enter Input:you, me, & them you, me, 'them' is not recognized as an internal or external command, operable program or batch file. you, me, %26 them you,%20me,%20%26%20them you%2c%20me%2c%20%26%20them Press any key to continue . . . Because the input has an Ampersand you either need to enclose it in quotes or use Delayed EXPANSION to ECHO the contents. Code: [Select]echo off & setlocal enabledelayedexpansion set /p "variable1=Enter Input:" set "variable2=!variable1:&=%%26!" set "variable3=!variable2: =%%20!" set "variable4=!variable3:,=%%2c!" echo %variable1% echo "%variable1%" echo !variable1! echo %variable2% echo %variable3% echo %variable4% pauseoutput Code: [Select]Enter Input:you, me, & them you, me, 'them' is not recognized as an internal or external command, operable program or batch file. "you, me, & them" you, me, & them you, me, %26 them you,%20me,%20%26%20them you%2c%20me%2c%20%26%20them Press any key to continue . . .And there is also the SET /P trick, which doesn't require the use of Delayed Expansion. Code: [Select]echo off & setlocal enabledelayedexpansion set /p "variable1=Enter Input:" set "variable2=!variable1:&=%%26!" set "variable3=!variable2: =%%20!" set "variable4=!variable3:,=%%2c!" set /p ".=%variable1%"<nul echo/ echo %variable2% echo %variable3% echo %variable4% pauseoutput Code: [Select]Enter Input:you, me, & them you, me, & them you, me, %26 them you,%20me,%20%26%20them you%2c%20me%2c%20%26%20them Press any key to continue . . . |
|
| 982. |
Solve : May I advetise a free product?? |
|
Answer» Hi! Joseph Rose a.k.a. Harry Potter, here. I read PARTS of the agreement, and it said that I can't advertise. Is it okay to advertise and share freeware here? I have some....No. And thank your for asking.Oh. You might want to go to a website where it has a list of freeware and try there instead. Where else can I distribute and advertise DOS software?Not here... Utilities written by and for 30 year old software development software appeal to a very small fraction of people. Someone named Harry Potter has posted a few batch files on Usenet in alt.msdos.batch.nt in recent weeks and also asked where else to publish them. Was that you? Is that what you are creating - they were batch files. Quote from: foxidrive on January 01, 2015, 09:59:09 PM Someone named Harry Potter has posted a few batch files on Usenet in alt.msdos.batch.nt in recent weeks and also asked where else to publish them. Assuming the "Harry Potter" nick on sourceforge is the same individual, it SEEMS one is a VBDOS program designed to create file templates, which is apparently a feature in Win32 according to the readme. The other is a .DSK file with no documentation that I'm unable to open with Winimage.If any of it is open source you can post it on github etc. I posted a few projects there I wrote in C++ for the taking as open source as well as compiled form for download. Its nothing that you could ever make any money on, but might be useful to someone else as it was for myself. Just think of all the programs that people custom write for a specific purpose that many probably wont use so its not a money making program idea, but could be useful to others. As open source, people can download the source and alter it as they want or look at it and know its clean and compile their own copy of the program etc. No hidden Surprises vs a downloaded EXE or a MSI installer etc with unwanted problems bundled within.I thank all of you for your interest. I am the one who posted the batch file. Also, the .dsk files aren't WinImage disk images but Apple2 disk images. The BSW image is an empty data disk for Bank Street Writer, a simple Apple2 word processor for students. I also have two ProDOS images: one directly from the internet, and one that immediately loads into the menu. For the Win32 audience: don't worry. Template Creator for Windows is under production. BTW, I could use more templates. It was never designed to be a money-making scheme but to fulfill a need I had and thought it would HELP others. This leaves me with the same problem: where else can I advertise DOS software on-line? As a matter of face, Win32 software as well?Just create a website of the programs you make and Google will inevitably index your site. Someone is bound to search for something you may have created.I already have the files on sourceforge.net. As for my own web site, I started to, but it didn't get far. Do I have permission to share what the program is? |
|
| 983. |
Solve : Invalid Parameter? |
|
Answer» I have a function that doesn't work in context, but does as an independent program. One of the 3rd party external commands I am using (convert) is throwing a Invalid Parameter error. Any ideas why? CONVERT is an internal command to Windows. So you need to specify the full path to the convert program you are using. I will try that, but I don't think that's the issue as the program is executing. It just isn't recognizing one of the inputs that It would normally recognize. Quote from: Lemonilla on December 14, 2014, 05:06:00 PM I will try that, but I don't think that's the issue as the program is executing. It just isn't recognizing one of the inputs that It would normally recognize.Yes it is executing Windows Convert command. See my output. LOOKS just like your error. Code: [Select]C:\Users\Squashman>convert pg_1.jpg 1.pdf Invalid Parameter - 1.pdf Quote It just isn't recognizing one of the inputs that It would normally recognize. Do the files have to be within " " MAYBE? such as T:\mtg\packs\pack_1>..\..\convert.exe "pg_1.jpg pg_1.pdf" T:\mtg\packs\pack_1>..\..\convert.exe "pg_2.jpg pg_2.pdf"Oh, I didn't realize windows had a convert command. That fixed it, thanks! Quote from: Lemonilla on December 14, 2014, 06:08:40 PM Oh, I didn't realize windows had a convert command. That fixed it, thanks!Been there for almost 20 years. Basically since Windows NT came out. Quote from: Squashman on December 15, 2014, 06:22:02 AM Been there for almost 20 years. Basically since Windows NT came out.I got caught by this when I first started using Image Magick. In batch scripts you have to run the batch from the same folder as the IM convert.exe program, or provide the full path to it, or rename the IM program, e.g. to imconvert.exe, or you can rename the Windows c:\windows\System32\convert.exe to something else (it converts FAT volumes to NTFS and if you have bever heard of it, you probably don't need it, and if you subsequently do, you can rename it back). |
|
| 984. |
Solve : adding to a script to send an email if a folders date modified is > 1 day? |
|
Answer» HI guys, using the script below i am successfully able to find if a folders date modified time is less than 1 day ignore it and if not, do an else command to create a TEXT file in a location. what i need is to instead of create a text file, i need it to send an email to inform me it is greater than 1 day. this is the current script; dim filesys, filetxt, getname, path Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.GetFolder("c:\test").DateLastModified >= Date - 1 Then Wscript.quit Else if objFSO.GetFolder("c:\test").DateLastModified <= Date - 1 Then Set filesys = CreateObject("Scripting.FileSystemObject") Set filetxt = filesys.CreateTextFile("c:\test\not created.txt", True) path = filesys.GetAbsolutePathName("c:\test\not created.txt") getname = filesys.GetFileName(path) filetxt.WriteLine("file doesnt exist.") filetxt.Close End if end if im using outlook 2013 and windows 7. thanks!Is that code complete? You can use a batch file to send an email using VBS, and also use batch code to check if the folder date is not todays date - that's all your code seems to be doing (although the Date variable appears undefined). I'm not sure how you are launching this - more info is needed. Quote from: foxidrive on January 22, 2015, 11:18:13 AM the Date variable appears undefined Date is a built-in VBscript function which returns the current system date, formatted according to the system locale settings. On my system wscript.echo Date produces 22/01/2015, and adding or subtracting numbers e.g. Date-1, Date+30 produces a similarly formatted date string, representing the date that number of days in the past or future. Note to the OP: you mention files less than 1 day old, and files more than 1 day old. What do you want to do with files that are exactly ONE day old? This is how you could try to send an email using Outlook. I only have Outlook 2003 so I don't know if it would work with Outlook 2013. You would probably need to change Outlook security settings to allow unattended scripted sending of emails. Code: [Select]ToAddress = "[email PROTECTED]" MessageSubject = "Subject goes here" MessageBody = "Body message goes here." Set ol = WScript.CreateObject("Outlook.Application") Set ns = ol.getNamespace("MAPI") Set newMail = ol.CreateItem(olMailItem) newMail.Subject = MessageSubject newMail.Body = MessageBody & vbCrLf & MyTime newMail.RecipIents.Add(ToAddress) newMail.Send There are better ways of sending emails, like the CDO object. Quote from: Salmon Trout on January 22, 2015, 12:57:05 PM Date is a built-in VBscript function which returns the current system date, formatted according to the system locale settings. Thanks Mr Trout. You're very helpful to an old codger. I did search the WSH help for 'date' and clicked on the few that looked likely suspects, but gave up too soon it looks like. Foxidrive. Look at SS64 website. It has a list of all the VBscript commands just like it does for NT batch. Quote from: Squashman on January 22, 2015, 07:59:01 PM Foxidrive. Look at SS64 website. It has a list of all the VBscript commands just like it does for NT batch. Thanks Squashman. |
|
| 985. |
Solve : My Batch File will not Run Properly? |
|
Answer» I need help with the following batch program, it is supposed to check for the EXE WebFormApp.exe, if it is running then it should start Internet explorer. Otherwise it should start the WebFormApp.exe and then start Internet Explorer. the batch file below only works if the WebFormApp.exe is running. meaning it will open Internet Explorer. When the program is not running, it will run it and the cmd window will stay open. |
|
| 986. |
Solve : Checking Variables? |
|
Answer» It has been a long time since I have coded in Batch. There is a problem that I can't not figure out. I am making a Tic-Tac-Toe game, and when I have the player ENTER their choice via "set /p" and it goes through the process of setting the VARIABLE, which works fine. But what if they enter one that has already been selected. I do not know how to check the variable without having a bunch of if statements. I am very boredApparently you are too busy. In your other thread you talk about writing code together but you haven't bothered to share your final code. If you are going to ask for help in writing code then it is polite to share the entire code after you are finished.I don't have it. I gave it to my friend, and I didn't back it up sorry. And my multiplayer peice of code requires delayedExpansion and all it does is send it to a text file with the (echo whatever ) >> file.txt And there you have it...This rates right up there with JacobRocks not enough time excuse. Front runners for the Nebulous Request of the Month Award... |
|
| 987. |
Solve : Batch file to delete file? |
|
Answer» Hello, I tried your script in a temporal folder and it deleted all files including it self and leaving justIf the batch file deleted itself then you didn't FOLLOW my instructions!!!! Based on the information you gave me the script works as described. Until you can supply more information on what folder the files are in and what files are in the folder and what files need to remain and what files need to be deleted there is little anyone can do to help you. You need to think about what you are trying to do and be very specific with your instructions.Squashman, I suspect Akod doesn't have the knowledge to change this line: Code: [Select]pushd "c:\folder path" Akod - you must have failed to comprehend the instructions - why didn't you ask a question describing which part you didn't UNDERSTAND?Below is a description of the files in this location where the latest file is to be deleted: Control3.dmp > (Time of creation 11:26pm) Control2.dmp > (Time of creation 5:45pm) schedule2 > (folder) Schedule3 > (folder) schedule > (folder) The directory contains 2 files and 3 folders. The application we running automatically generates the two files at the time indicated above. Because of low disk ISSUE, anytime a file is created, the old one needs to be deleted. Please hope this explanation helps to get a solution. Thanks. You didn't answer all my questions but this again is the best I can do with the limited information. Code: [Select]echo off pushd "c:\folder path" FOR /F "skip=1 delims=" %%G in ('dir /a-d /b /o-d control*.dmp') do del "%%~G" popd |
|
| 988. |
Solve : check if Multiple Network Drives exist then Launch Application? |
|
Answer» I have 6 network drives that host applications, and are PUBLISHED in Terminal server. I currently use the batch FILE below to check for one network drive. I need help making this script check 6 network drives if they exist, if they do launch an APP. I tried various forms of if statements but wasn't successful. I am new to batch SCRIPTING, so your help is greatly appreciated. |
|
| 989. |
Solve : ntfs4dos? |
|
Answer» I use ntfs4dos.exe (only the executable) on a DOS 5.5 boot CD. When I type ntfs4dos.exe it mounts my ntfs partitions and a FAT32 partition. It would help to show the screen when the drives mount, for diagnostic purposes, plus the screen where you type in the commands. Seeing is 98% of figuring out the issue.I've redirected my stdout of "dir" dir > dir.txt But I could not access the file dir.txt in windows7: "no access" when I wanted to open it in notepad When I wanted to include stderr (because "file not found" is an stderr) dir 1>dir2.txt 1>&1 I get the dos answer: too much parameters I cannot redirect ntfs4dos.exe because it's an interactive command:there is an answer " yes" Quote from: louis14 on January 06, 2015, 09:47:42 AM When I wanted to include stderr (because "file not found" is an stderr)STDERR is not file stream 1. It is 2. Quote from: louis14 on January 06, 2015, 09:47:42 AM But I could not access the file dir.txt in windows7: "no access" when I wanted to open it in notepad Perhaps your account doesn't have read permission for that file. This error also happens when you try to write the file in a root directory or other location, when the account doesn't have permissions to write there - the file is not created. Quote I cannot redirect ntfs4dos.exe because it's an interactive command:there is an answer " yes" Use a phone and take images of the screen and upload them to a site - then include the links here.Here are my Phone images of my "dir" and my ntfs4dos" command. The share link is: http://www.filetolink.com/2855f94f6a Sorry but the link asks a facebook or google login I've tried to use the site senduit but there was a technical error Quote from: louis14 on January 09, 2015, 08:07:23 AM Here are my Phone images of my "dir" and my ntfs4dos" command. Thanks for creating the files - the site is asking a lot to get people to use credentials just to download a file. You can use a free dropbox account to share files without needing the downloader to log in. Not gonna create a FBook account just to see your pics....thats just me. Quote from: patio on January 09, 2015, 06:51:33 PM Not gonna create a FBook account just to see your pics....thats just me.+1oI've rehosted the files: Quote from: BC_Programmer on January 10, 2015, 12:52:50 AM I've rehosted the files: Thanks BC_Programmer. louis14, the screenshots aren't complete and things could have happened between screenshot 1 and 2 but assuming they follow each other with nothing in between - it looks like Drive D: was mounted and it is in fact empty. If I had access to the machine I would use these commands to determine if any other NTFS drive has files showing, and if the FAT32 drive does also. Code: [Select]dir f:\ dir e:\ dir d:\ dir c:\ Assuming the FAT drive shows files, and if all the NTFS drives show as empty, and still have files when examined under Windows, then the NTFS dos driver is failing. The reason could be either :
|
|
| 990. |
Solve : delete zero byte files? |
|
Answer» I need some help I have a process that creates a file and another that will start other jobs based on the file existing however I need to delete the file if there is no data in it. i.e. zero byte. |
|
| 991. |
Solve : Help Needed : String Split issue in for loop... while process folders? |
|
Answer» Hello Everybody, I am problem splinting the string in a loop. What are you trying to do to the listing? It can be more FUN to derive a solution than to READ long code which is broken. |
|
| 992. |
Solve : batch file as a setup file? |
|
Answer» Hello, |
|
| 993. |
Solve : Subtract images in batch process(leap year and regular year)? |
|
Answer» I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process.
LEAP YEARS: REGULAR YEARS: *2000, 2004, 2008, 2012, 2016, 2020...* *2001-2003, 2005-2007, 2009-2011, 2013-2015...* January - 1-31 January - 1-31 February - 32-60 February - 32-59 March - 61-91 March - 60-90 April - 92-121 April - 91-120 May - 122-152 May - 121-151 June - 153-182 June - 152-181 July - 183-213 July - 182-212 August - 214-244 August - 213-243 September - 245-274 September - 244-273 October - 275-305 October - 274-304 November - 306-335 November - 305-334 December - 336-366 December - 335-365 Here are the sample file name for the images(these will be the minuend): :there will only be 12 subtrahend(sample_file_jan.tif, sample_file_feb.tif, sample_file_march.tif . . .) C2000060.A1_ABC.ABCD.tif - sample_file_feb.tif ------------------> the file was subtracted to feb because 060 is a day included in February (leap year) C2002152.A1_ABC.ABCD.tif - sample_file_june.tif------------------> the file was subtracted to june because 152 is a day included in June (regular year) C2000032.A1_ABC.ABCD.tif - sample_file_feb.tif------------------> the file was subtracted to feb because 032 is a day included in February (leap year) C2001060.A1_ABC.ABCD.tif - sample_file_march.tif------------------> the file was subtracted to march because 060 is a day included in March (regular year) where: C = data name 2000 - year (leap year or regular year) 001 - julian date (leap year or regular year) A1_ABC.ABCD.tif - extension name If the year specified in the file name is 2000, 2004, 2008... then the date would be based on leap year. If the year specified in the file name is 2001-2003, 2005-2007, 2009-2011... then the date would be based on regular year. If the date from the file name is based on the date from the leap years, then subtract the image to its corresponding subtrahend/month to where it should be subtracted. Repeat this step if the date are from the regular years. Here is the script in subtracting images: gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1 +image2))" --image2=D:\path\to\subtrahend\sample_file_feb.tif image1=D:\path\to\minuend\C2001060.A1_ABC.ABCD.tif --extent=INTERSECT You are really referring to an Ordinal Date not a Julian Date. This will help you change your ordinal date to a Calendar date. Once you have the calendar date information you should then be able to figure out how to run your program. http://www.commandline.co.uk/cmdfuncs/dandt/#ordinaltodate Code: [Select]echo off&setlocal call :OrdinalToDate %1 %2 yy mm dd echo/%yy%-%mm%-%dd% goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :OrdinalToDate %year% %doy% yy mm dd :: :: By: Ritchie Lawrence, 2002-09-29. Version 1.0 :: :: Func: Returns a calendar date from an ISO 8601 Ordinal date. :: For NT4/2K/XP. :: :: Args: %1 year component to be converted, 4 digits (by val) :: %2 day of year component to be converted, 001 to 366 (by val) :: %3 var to receive year, 4 digits (by ref) :: %4 var to receive month, 2 digits, 01 to 31 (by ref) :: %5 var to receive day of month, 01 to 31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000 set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2 set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1 set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Going to assume you will want to convert the month number to the month name, so that you can use the month name with the GDAL_CALCULATE command. I have added that code. Code: [Select]echo off&setlocal enabledelayedexpansion call :OrdinalToDate %1 %2 yy mm dd echo/%yy%-%mm%-%dd% :: Now convert the month number to month name abbreviation set m=100 for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do ( set /A m+=1 set month[!m:~-2!]=%%m ) set MONTHNAME=!month[%mm%]! echo %monthName% goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :OrdinalToDate %year% %doy% yy mm dd :: :: By: Ritchie Lawrence, 2002-09-29. Version 1.0 :: :: Func: Returns a calendar date from an ISO 8601 Ordinal date. :: For NT4/2K/XP. :: :: Args: %1 year component to be converted, 4 digits (by val) :: %2 day of year component to be converted, 001 to 366 (by val) :: %3 var to receive year, 4 digits (by ref) :: %4 var to receive month, 2 digits, 01 to 31 (by ref) :: %5 var to receive day of month, 01 to 31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000 set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2 set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1 set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Quote from: Squashman on November 05, 2014, 09:21:49 AM Going to assume you will want to convert the month number to the month name, so that you can use the month name with the GDAL_CALCULATE command. How will I add the gdal_calculate command to the batch script you gave? Quote from: _unknown_ on November 06, 2014, 07:56:16 PM Well I assumed you wanted to use the Month Name Abbreviation as part of your sample_file_feb.tif file. So use the month abbreviation variable that I created for you.In which part of your script should I add the gdal_calculate command? Quote from: _unknown_ on November 09, 2014, 11:01:18 PM In which part of your script should I add the gdal_calculate command?Well you are not even to that point yet. You still need the code to extract the Ordinal Date from the file name. Look at the code that Aacini gave you on DosTips.com. That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command. Quote from: Squashman on November 10, 2014, 06:55:34 AM Well you are not even to that point yet. You still need the code to extract the Ordinal Date from the file name. Sorry for this. But is it like this? Code: [Select]echo off&setlocal EnableDelayedExpansion call :OrdinalToDate %1 %2 yy mm dd echo/%yy%-%mm%-%dd% :: Now convert the month number to month name abbreviation set m=100 for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do ( set /A m+=1 set month[!m:~-2!]=%%m ) set monthName=!month[%mm%]! echo %monthName% set "in_path=E:\Processed_Files\Merged\" set "out_path=E:\Diff" set "in_subtrahend=E:\sample_file_months\" set "yearDay=" set "fileList=" md %out_path% rem Process all *.tif files in input path cd "%in_path%" for %%a in (*.tif) do ( set "fileName=%%a" rem If the YearDay in this file is the same of previous one if "!fileName:~1,7!" equ "!yearDay!" ( rem Join this filename to previous list set "fileList=!fileList! !fileName!" ) else ( rem Subtract the files in the list if defined fileList gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2)/(image1+image2))" -- image2=%in_subtrahend% image1=%in_path% --extent=INTERSECT ) ) rem Subtract the files in the list gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2)/(image1+image2))" --image2= %in_subtrahend% image1=%in_path% --extent=INTERSECT goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :OrdinalToDate %year% %doy% yy mm dd :: :: By: Ritchie Lawrence, 2002-09-29. Version 1.0 :: :: Func: Returns a calendar date from an ISO 8601 Ordinal date. :: For NT4/2K/XP. :: :: Args: %1 year component to be converted, 4 digits (by val) :: %2 day of year component to be converted, 001 to 366 (by val) :: %3 var to receive year, 4 digits (by ref) :: %4 var to receive month, 2 digits, 01 to 31 (by ref) :: %5 var to receive day of month, 01 to 31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000 set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2 set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1 set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Quote from: Squashman on November 10, 2014, 06:55:34 AM That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command. Am I doing the right thing? Please help! I'm just beginning to learn batch files and I don't know how to do it. Quote from: Squashman on November 10, 2014, 06:55:34 AM Well you are not even to that point yet. You still need the code to extract the Ordinal Date from the file name. I have tried my very best with this. Please bear with me. Code: [Select]echo on setlocal EnableDelayedExpansion set "in_path=E:\Proc\Mer\" set "out_path=E:\Proc\Abcde" set "two_path=E:\Proc\Me\" set "proc_path=E:\Proc\Proc_Mer_Fi" ::Don't modify the following variables set "yearDay=" set "fileList=" md %out_path% md %proc_path% ::Process all *.tif files in input path cd /d "%in_path%" for %%a in (*.tif) do ( set "fileName=%%a" if %1 == 001-031 goto :condition1 ::reg/leap if %2 == 032-059 goto :condition2 ::reg if %3 == 032-060 goto :condition2 ::leap if %4 == 060-090 goto :condition3 ::reg if %5 == 061-091 goto :condition3 ::leap if %6 == 091-120 goto :condition4 ::reg if %7 == 092-121 goto :condition4 ::leap if %8 == 121-151 goto :condition5 ::reg if %9 == 122-152 goto :condition5 ::leap if %10 == 152-181 goto :condition6 ::reg if %11 == 153-182 goto :condition6 ::leap if %12 == 182-212 goto :condition7 ::reg if %13 == 183-213 goto :condition7 ::leap if %14 == 213-243 goto :condition8 ::reg if %15 == 214-244 goto :condition8 ::leap if %16 == 244-273 goto :condition9 ::reg if %17 == 245-274 goto :condition9 ::leap if %18 == 274-304 goto :condition10 ::reg if %19 == 275-305 goto :condition10 ::leap if %20 == 305-334 goto :condition11 ::reg if %21 == 306-335 goto :condition11 ::leap if %22 == 335-365 goto :condition12 ::reg if %23 == 336-366 goto :condition12 ::leap :condition1 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_jan.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition2 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_feb.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition3 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_mar.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition4 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_apr.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition5 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_may.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition6 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_june.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition7 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition8 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_aug.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition9 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_sep.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition10 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_oct.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition11 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_nov.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :condition12 gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_dec.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT goto end :: Move processed files to a different directory for %%a in (!fileList!) do move %%a "%proc_path%" >nul ) Quote from: _unknown_ on November 05, 2014, 02:34:30 AM I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process. Files have a MODIFIED date which can be used to see if they are new. Do your files get modified so that the most RECENT file was the last one that was created, or modified? Quote from: foxidrive on December 01, 2014, 02:39:47 AM Files have a modified date which can be used to see if they are new. Everyday there will be new files added to the input directory that's why I included that in my goals but now instead of that those processed files will just be moved to another directory. So that the input directory will not be confused of the newer files. I hope I'm explaining it well? Quote from: _unknown_ on December 01, 2014, 07:07:20 PM Everyday there will be new files added to the input directory that's why I included that in my goals but now instead of that those processed files will just be moved to another directory. So that the input directory will not be confused of the newer files. I hope I'm explaining it well? Well nothing you said replied to the question I posed. The task may be much simpler than the way your code looks to be - using the file dates rather than the numbers in the filename. I don't follow the task too well though, as subtracted and subtrahend are your TERMS for something but they make no sense in terms of describing what the task is. To me it would make more sense to say "processing" or "process the file with programB and copy it to folder c:\widget\" Quote from: foxidrive on December 01, 2014, 09:01:53 PM Well nothing you said replied to the question I posed. Well sorry for me. I'm really not good in explaining. So you mean, I should replace the subtract with process?or processing? I'm using subtract and subtrahend because I thought that was the right term and because the batch will literally subtract one image to another. |
|
| 994. |
Solve : Batch file is getting false positives? |
|
Answer» I'm fairly new to writing scripts and having trouble (yes, yet another newbie with a question.. ) But I have been working pretty hard on this and I'm not able to get this to work. Also, your use of ERRORLEVEL is odd. The OP is using the NT family alternative SYNTAX for errorlevel, which is an improvement on the old MS-DOS syntax Old MS_DOS syntax: If errorlevel N command (There are no == signs like in your example.) That means if the errorlevel is N or more, execute the command (often a GOTO a label) HOWEVER in NT family command language (I believe since Windows 2000 at least) you have an additional alternative syntax where errorlevel is treated like any percent-sign variable like this: You don't really need any quotes if %errorlevel%==N command if %errorlevel% equ N command (equivalent) Conveniently, you can use the standard IF comparison operators available in NT family command language: EQU - equal NEQ - not equal LSS - less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal I suggest to the OP: put some lines like this... echo errorlevel is %errorlevel% ...in your script to try to see what is happening. |
|
| 995. |
Solve : Echo command? |
|
Answer» HI, I have a question about Echo. I have read about what it is and what it is USED for ,but did not really help me to understand what the following line mean. Cananyona help please? echo .> D:\Projects\logs\WinScpFtp_log.txt What I cant find on the web is what these characters mean .> Does this mean that it puts in the file WinScpFtp_log.txt a dot? Thanks Yes but it also overwrites that file if it already exists. If you need to append to the log file then you would use two > You are physically echoing a period and redirecting the output to the log file.This: (with a space between echo and the dot!) echo . > path\filename echoes a dot and a newline (cr + lf) to the file, creating the file if it does not exist, overwriting the file completely if it already exists. Note however: This: (no space between the echo and the dot!) echo. > path\filename echoes a blank new line to the file. Redirection operators: > create new file if it does not exist, over-write file if it exists. >> create new file if it does not exist, append to file (add to end of file if it exists. Quote from: Suhi100 on February 11, 2015, 11:31:40 AM What I cant find on the web is what these characters mean .> Examples of many guides: (1) http://ss64.com/nt/syntax-redirection.html (2) http://ss64.com/nt/echo.html General help: http://ss64.com/nt/ http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true Or type cmd syntax into Google Also, because DOS batch was not intended as a learning language for those new to computer programming. If you look for information about computer languages, batch is seldom, if ever, LISTED as suitable for newcomers. Instead you might see: Quote Assembly (a relatively simple dialect)To be sure, there are excellent tutorials for batch. As was mentioned by Salmon Trout above. But you have to read them. Well said Salmon Trout. I visit SS64 and Rob Vanderwoude's site as well. http://www.robvanderwoude.com/redirection.php Quote from: Salmon Trout on February 11, 2015, 12:58:29 PM This: Just idly commenting here that your examples also add spaces. Quote from: foxidrive on February 12, 2015, 07:45:42 AM Just idly commenting here that your examples also add spaces. You know, I was on the bus coming back from work, and I thought "I put spaces before the redirections". Correction: This: (with a space between echo and the dot!) echo .> path\filename echoes a dot and a newline (cr + lf) to the file, creating the file if it does not exist, overwriting the file completely if it already exists. Note however: This: (no space between the echo and the dot!) echo.> path\filename echoes a blank new line to the file. Redirection operators: > create new file if it does not exist, over-write file if it exists. >> create new file if it does not exist, append to file (add to end of file if it exists. [/quote] |
|
| 996. |
Solve : Batch Project? |
|
Answer» I would like to start a project that involves the forum community. Before I do this I would like to know if people would like do it and prove that I am not a total idiot. Thanks for Your time anyway tho!Curious of what project ideas you have? Depends on what the project is. I for one don't have a lot I can contribute to a large scale project as it will most likely not be written in batch, and my grasp on python and java is not sufficient to contribute anything meaningful.Not sure why you or anyone else would think you are an idiot. If you want to start a batch program just post your ideas and some code and I am sure a lot of people will contribute their two cents if it peaks their interest.Why the Poll ? ? Why the Poll ? ? Quote from: Squashman on January 04, 2015, 04:17:38 PM If you want to start a batch program just post your ideas and some code and I am sure a lot of people will contribute their two cents if it peaks their interest. Me agree. I don't why the poll, just guessed it would help some how. Anyway I didn't come into this with any ideas. But now since you mentioned it I thought of a few like, advance Calculator, a city builder, a space adventure, a batch file manager. An since this is the first really new thing I tried on this forum. Maybe these projects could be written in multiple languages, via C++, python and java. Plus if multiple people help, some people might not need to speed massive amounts of time. The code of these projects could range from 20 to 1000. So that's all the questions I SAW, but the reason I didn't post some code, was I didn't have any. Other people can come up with more ideas then I can. And If anyone wanders why, I am very bored after school and practice, so i want to help people and program random things. Thanks for all the feedback anyway!, Shiverbob Quote from: shiverbob on January 06, 2015, 08:01:36 PM Maybe these projects could be written in multiple languages, via C++, python and java.Then post in the Computer Programming forum category. Quote from: shiverbob on January 06, 2015, 08:01:36 PM I am very bored after school and practiceThen help out on multiple forums. There are tons of them out there. I probably post on about 6 different forums. Quote from: shiverbob on January 06, 2015, 08:01:36 PM a space adventure Here's a start. I don't think I commented everything, but you should be able to figure it out. Every file other than launcher.bat should be in a folder named "bin". The files with names like this "filename." have no extension and shouldn't be saved with one. They are simply text files, but I was lazy and decided I didn't want to write .txt every time I used them. Post if I missed a file. Code: (launcher.bat) [Select]:: Launches the game. Displays the controls found :: in the controls file. echo off cd bin for /f "delims=" %%A in (controls) do set %%A echo. echo.controls echo. echo. %move_+_y_theta% = + y theta echo. %move_-_y_theta% = - y theta echo. %move_+_x_theta% = + x theta echo. %move_-_x_theta% = - x theta echo. %move_+_vel% = + vel echo. %move_-_vel% = - vel echo. %move_ping% = ping echo. %move_quit% = quit echo. pause call master.bat ====================BIN==================== Code: (cont.bat) [Select]:: Waits for user input and writes it to the cmd file. :: Closes upon finding the contr file, created by cmd.bat :: when the exit command is found. setlocal enableDelayedExpansion for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a" set "key=" for /L %%. in () do ( set "key=" for /f "delims=" %%A in ('xcopy /w %~f0 %~f0 2^>nul') do if not defined key set "key=%%A" set key=!key:~-1! echo !key!>cmd if exist contr exit ) Code: (com.bat) [Select]:: Checks file cmd generated by cont.bat for which command to execute :: and then executes that command. Uses values in controls file for :: key to commnand bindings. setlocal EnableDelayedExpansion set /p cmd=<cmd set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z set /p vel=<vel set /p theta_y=<theta_y set /p theta_x=<theta_x for /f "delims=" %%A in (controls) do set %%A if "%cmd%"=="." goto :end if /i "%cmd%"=="%move_+_y_theta%" ( set /a theta_y+=%delta_theta% echo !theta_y!>theta_y ) if /i "%cmd%"=="%move_-_y_theta%" ( set /a theta_y-=%delta_theta% echo !theta_y!>theta_y ) if /i "%cmd%"=="%move_+_x_theta%" ( set /a theta_x+=%delta_theta% echo !theta_x!>theta_x ) if /i "%cmd%"=="%move_-_x_theta%" ( set /a theta_x-=%delta_theta% echo !theta_x!>theta_x ) if /i "%cmd%"=="%move_+_vel%" ( set /a vel+=1 echo !vel!>vel ) if /i "%cmd%"=="%move_-_vel%" ( set /a vel-=1 echo !vel!>vel ) if /i "%cmd%"=="%move_ping%" call ping.bat if /i "%cmd%"=="%move_quit%" ( echo .>contr timout /t 1 /nobreak >nul exit ) echo .>cmd :end Code: (disp.bat) [Select] REM load data set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z set /p vel=<vel set /p theta_y=<theta_y set /p theta_x=<theta_x set /p turn=<turn for /f "delims=" %%A in (settings) do set %%A if not exist last goto :disp for /f "delims=" %%A in (last) do set l_%%A if "%pos_x: =%"=="%l_pos_x: =%" ( if "%pos_y: =%"=="%l_pos_y: =%" ( if "%pos_z: =%"=="%l_pos_z: =%" ( if "%vel: =%"=="%l_vel: =%" ( if "%theta_x: =%"=="%l_theta_x: =%" ( if "%theta_y: =%"=="%l_theta_y: =%" ( if not "%display%"=="1" goto :end )))))) :disp cls echo. echo. Possition: [%pos_x: =%],[%pos_y: =%],[%pos_z: =%] echo. Direction: y [%theta_y: =%], x [%theta_x: =%] echo. Velocity : [%vel: =%] echo. if "%display%"=="1" ( if exist v_grav type v_grav echo. ) :end Code: (grav.bat) [Select]:: apply gravity by calling grav.vbs set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z for /f "delims=" %%A in (settings) do set %%A cscript //nologo grav.vbs "%cd%\planets" %pos_x% %pos_y% %pos_z% "%cd%" "%wvec_lim%" 1>v_grav Code: (controls.) [Select]move_+_y_theta=w move_-_y_theta=s move_+_x_theta=d move_-_x_theta=a move_+_vel=o move_-_vel=l move_ping=p move_quit=t diplay_ex=g Code: (land.bat) [Select]:: Displays crash information and :: calls reset for a new game. set /p planet=<crashrep for /f "tokens=1-4 delims=," %%A in (planets) do ( if "%%D"=="%planet%" ( echo %%A >pos_x echo %%B >pos_y echo %%C >pos_z ) ) if /i "%planet%"=="earth" call win.bat call disp.bat echo You've landed on %planet% echo. echo Press G to explore. . . :l if exist cmd set /p cmd=<cmd if /i not "%cmd%"=="g" goto :l echo .>cmd call planet.bat Code: (master.bat) [Select]:: The master file that calls all other components. :: LOOPS forever, always reading the cmd file for :: commands to execute. echo off if exist last del last if exist contr del contr if exist turn set /p turn=<turn if "%~1"=="l" goto :l start /b cmd /c cont.bat 2>nul 1>&2 cmd /c ^""%~f0" l ^" rem ^<nul exit /b 0 :l REM setup Var set cmd=. if exist cmd ( set /p cmd=<cmd ) else ( echo . >cmd ) REM Start moving call mov.bat REM read commands call com.bat REM start view call disp.bat REM apply gravity call grav.bat REM check crash call chkcrsh.bat REM wait timeout /t 1 /nobreak >nul goto :l Code: (mov.bat) [Select]:: CHANGES ship position through the use of pt.vbs set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z set /p vel=<vel set /p theta_y=<theta_y set /p theta_x=<theta_x cscript //nologo pt.vbs "%vel%" "%theta_x%" "%theta_y%" "%cd%\Pos_x" "%cd%\Pos_y" "%cd%\Pos_z" "%pos_x%" "%pos_y%" "%pos_z%" Code: (planet.bat) [Select]:: Displays information on current planet you are on. :: Also allows for takeoff. set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z set /p vel=<vel set /p theta_y=<theta_y set /p theta_x=<theta_x set /p planet=<crashrep :: chart planet on map echo %planet% >chart call disp.bat type "..\desc\%planet%" echo. echo. echo Press G to leave planet. . . :l if exist cmd set /p cmd=<cmd if /i not "%cmd%"=="g" goto :l echo .>cmd set /a pos_x+=5 set /a pos_y+=5 set /a pos_z+=5 rem echo 1 >vel echo %pos_x% >pos_x echo %pos_y% >pos_y echo %pos_z% >pos_z del crashrep Code: (planets.) [Select]0,0,0,0,0,0,0,0, How to read: x,y,z,name,danger,grav,bound_sun_name 0,0,0,0,0,0,0,0, danger 0 = can't land, 1 = can safely land, 2 = crash 0,0,0,0,0,0,0,0, bound_sun_name=0 if self bound 0,0,0,0,0,0,0,0, smaller the grav the harder the pull 0,0,0,0,0,0,0,0, 1 pt ~ 100,000 miles 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, Sol System 0,0,0,0,0,0,0,0, 390000,470000,-38000,Sol,2,1,0 390000,470360,-37900,Mercury,1,50,Sol 390600,470070,-38100,Venus,1,30,Sol 390629,469700,-38070,Earth,1,10,Sol 388584,470000,-38030,Mars,1,10,Sol 394000,470836,-37970,Jupiter,0,5,Sol 381118,469990,-38000,Saturn,0,7,Sol 372136,469900,-37920,Uranus,0,20,Sol 390000,442012,-38000,Neptune,0,20,Sol 426662,470000,-40000,Pluto,1,100,Sol 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, Elbei/Ambon System 0,0,0,0,0,0,0,0, -950,-950,11,Elbei/Ambon,0,0,0 -1000,-1000,10,Elbei,2,2,Elbei/Ambon -900,-900,12,Ambon,2,2,Elbei/Ambon 10,10,100,Abron,1,10,Elbei/Ambon -150,-150,50,Upien,0,15,Elbei/Ambon Code: (grav.vbs) [Select]' grav "%cd%\planets" %pos_x% %pos_y% %pos_z% "%cd%" %wvec_lim% ' ' Applies gravity for each planet withing range. Uses wvec_lim variable ' from files settings to determine range. if dis/grav < wvrc_lim then ' gravity is applied. Value of grav is taken from file settings as well. dim x,y,z,working_x,working_y,working_z,dis,wvec,vec_x,vec_y,vec_z,x1,y1,z1,grav,wvec_lim,planets,name dim file,fso,listFile,line,arrline file=Wscript.Arguments(0) x=Wscript.Arguments(1) y=Wscript.Arguments(2) z=Wscript.Arguments(3) cd1=Wscript.Arguments(4) wvec_lim=CSng(Wscript.Arguments(5)) vec_x=0 vec_y=0 vec_z=0 ' Loop through planets list Set fso = CreateObject("Scripting.FileSystemObject") Set listFile = fso.OpenTextFile(file) do while not listFile.AtEndOfStream line = listFile.ReadLine() ' setup variables arrline=Split(line,",") working_x=arrline(0) working_y=arrline(1) working_z=arrline(2) name=arrline(3) grav=arrline(5) ' Ignore all planets with 0 gravity ' These are comments in the file If grav <> 0 Then 'find distance dis=Sqr((x-working_x)*(x-working_x)+(y-working_y)*(y-working_y)+(z-working_z)*(z-working_z)) wvec=dis/grav Wscript.echo name &" | "& round(wvec,2) 'determine adding If wvec < wvec_lim Then ' Find Vector length if dis=0 then dis=.0000001 x1=round(((working_x-x)/dis/grav),2) y1=round(((working_y-y)/dis/grav),2) z1=round(((working_z-z)/dis/grav),2) ' Display Data Wscript.echo " "&x1&" "&y1&" "&z1 ' Add vector length to sum vec_x=vec_x+x1 vec_y=vec_y+y1 vec_z=vec_z+z1 End If End If Loop ' Make corrections on possition x=x+vec_x y=y+vec_y z=z+vec_z ' Write to Files set objFSO=CreateObject("Scripting.FileSystemObject") outFile=cd & "pos_x" Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write x & vbCrLf objFile.Close outFile=cd & "pos_y" Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write y & vbCrLf objFile.Close outFile=cd & "pos_z" Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write z & vbCrLf objFile.Close Code: (pt.vbs) [Select]' cscript //nologo pt.vbs "%vel%" "%theta_x%" "%theta_y%" "%cd%\Pos_x" "%cd%\Pos_y" "%cd%\Pos_z" "%pos_x%" "%pos_y%" "%pos_z%" ' ' x = vel * cos(theta_x) * cos(theta_y) ' y = vel * cos(theta_x) * sin(theta_y) ' z = vel * sin(theta_x) ' ' Changes the position of the ship by using theta_x, theta_y, and vel to ' determine the end point of that movement. Is applied before gravity. dim x,y,z,vel,xTheta,yTheta,cd1,cd2,cd3,px,py,pz,log,pi vel = Wscript.Arguments(0) xTheta = Wscript.Arguments(1) yTheta = Wscript.Arguments(2) cd1 = Wscript.Arguments(3) cd2 = Wscript.Arguments(4) cd3 = Wscript.Arguments(5) px = Wscript.Arguments(6) py = Wscript.Arguments(7) pz = Wscript.Arguments(8) pi = 4 * ATN(1) ' convert degree's to radians xTheta = xTheta * pi / 180 yTheta = yTheta * pi / 180 x = round((vel*cos(yTheta)*cos(xTheta)),2)+px z = round((vel*cos(yTheta)*sin(xTheta)),2)+pz y = round((vel*sin(yTheta)),2)+py set objFSO=CreateObject("Scripting.FileSystemObject") outFile=cd1 Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write x & vbCrLf objFile.Close outFile=cd2 Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write y & vbCrLf objFile.Close outFile=cd3 Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write z & vbCrLf objFile.Close Code: (reset.bat) [Select]:: Resets the game. Does not call any other functions. if exist contr del contr if exist last del last if exist turn del turn if exist cmd del cmd if exist crashrep del crashrep echo 0 >pos_x echo 0 >pos_y echo 0 >pos_z echo 0 >vel echo 0 >theta_x echo 0 >theta_y echo 0 >turn :: echo delta_theta=10 >settings :: echo delay=50 >>settings :: echo grav=1 >>settings echo vel=0 >last echo .>cmd Code: (settings.) [Select]delta_theta=10 delay=50 display=1 wvec_lim=2 crash=1 Code: (chkcrsh.vbs) [Select]' chkcrsh.vbs "%cd%" %pos_x% %pos_y% %pos_z% "%cd%\planets" "%cd%\crashrep" ' ' Checks for possition conflict between ship and the planets found in the planets file. dim x,y,z,working_x,working_y,working_z,cd,errorlevel,file,arrline,cd1,lastX,lastY,lastZ,working_name,line,listFile errorlevel=0 cd=Wscript.Arguments(0) x=round(Wscript.Arguments(1),0) y=round(Wscript.Arguments(2),0) z=round(Wscript.Arguments(3),0) file=Wscript.Arguments(4) cd1=Wscript.Arguments(5) Set fso = CreateObject("Scripting.FileSystemObject") Set listFile = fso.OpenTextFile(file) do until listFile.AtEndOfStream line = listFile.ReadLine() 'setup variables arrline=Split(line,",") working_x=round(arrline(0),0) working_y=round(arrline(1),0) working_z=round(arrline(2),0) working_name=arrline(3) working_dang=arrline(4) if x=working_x then if y=working_y then if z=working_z then if working_dang <> 0 Then set objFSO=CreateObject("Scripting.FileSystemObject") outFile=cd1 Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write working_name & vbCrLf objFile.Close end if end if end if end if loop Code: (com.bat) [Select]:: Checks file cmd generated by cont.bat for which command to execute :: and then executes that command. Uses values in controls file for :: key to commnand bindings. setlocal EnableDelayedExpansion set /p cmd=<cmd set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z set /p vel=<vel set /p theta_y=<theta_y set /p theta_x=<theta_x for /f "delims=" %%A in (controls) do set %%A if "%cmd%"=="." goto :end if /i "%cmd%"=="%move_+_y_theta%" ( set /a theta_y+=%delta_theta% echo !theta_y!>theta_y ) if /i "%cmd%"=="%move_-_y_theta%" ( set /a theta_y-=%delta_theta% echo !theta_y!>theta_y ) if /i "%cmd%"=="%move_+_x_theta%" ( set /a theta_x+=%delta_theta% echo !theta_x!>theta_x ) if /i "%cmd%"=="%move_-_x_theta%" ( set /a theta_x-=%delta_theta% echo !theta_x!>theta_x ) if /i "%cmd%"=="%move_+_vel%" ( set /a vel+=1 echo !vel!>vel ) if /i "%cmd%"=="%move_-_vel%" ( set /a vel-=1 echo !vel!>vel ) if /i "%cmd%"=="%move_ping%" call ping.bat if /i "%cmd%"=="%move_quit%" ( echo .>contr timout /t 1 /nobreak >nul exit ) echo .>cmd :end Code: (chkcrsh.bat) [Select]:: Checks for a conflict in possition with ship and any planets :: calls upon chkcrsh.vbs for math and comparison. set crashrep= set /p pos_x=<pos_x set /p pos_y=<pos_y set /p pos_z=<pos_z set /p vel=<vel cscript //nologo chkcrsh.vbs "%cd%" %pos_x% %pos_y% %pos_z% "%cd%\planets" "%cd%\crashrep" REM for after planet based movement is possable if exist crashrep if %vel% GTR 0 call crash.bat if exist crashrep if %vel% EQU 0 call land.bat *I used dbenham's snake game to write cont.bat, he gets all credit for the controls input technique. Quote from: Lemonilla on January 07, 2015, 06:50:19 PM Here's a start. Post if I missed a file. Just a suggestion: It would aid people to get this, with no typos and saving errors, if you could attach a zip file with the entire shebang. Quote from: foxidrive on January 07, 2015, 09:23:27 PM Just a suggestion:>.< Now I feel stupid. Here's the file. [attachment deleted by admin to conserve space]If you want to properly collaborate on a project together, use a hosted version control system such as Github. It will make managing changes and who did what much easier than copying and pasting code in a forum post. Each person can then fork the repo, make the changes they want and then submit a pull request.Well, never (successfully) used github before, but here it is. I plan on continuing this alone anyway and should probably get into the habit of backing my stuff up more often.Looking good so far! Just remember, commit little, commit often. Github is also great since if you end up going for a job that will involve some SORT of programming, it can act as a CV of sorts. |
|
| 997. |
Solve : mode woes? |
|
Answer» Hello all. Unfortunately, neither of those options reports the current COM1 setting When you type MODE /? at the dos prompt, what do you see?My own memory is a bit rusty but to my recollection you cannot actually view the current settings, the "STATUS" shown for it will only include the RETRY=NONE for some stupid reason. Further googling as you've likely attempted as well doesn't reveal anything. I was able to see the current COM port settings by running MSD (Microsoft DIAGNOSTICS) However this is new in MS-DOS 6 so isn't in MS-DOS 5. I don't know of a in-box way of viewing the settings without a tool like MSD. (MSD also came with Windows 3.x as I recall, possibly other MS Software as well). Also, if you are printing, I would expect you are using redirection to redirect an LPT port to the serial port? If that is the case, than it is worth noting that if you change the settings on the serial port you need to re-issue the redirection command. (MODE LPT1=COM1), otherwise printing won't work. (I don't know if it resets the redirection itself or perhaps has it using the old values for the redirect). I unfortunately can't REMEMBER that far back to know what the OPTIONS were for the MODE command back then. That is why I have been trying to get him to tell us what it is because he has access to it.mode /? shows the command syntax and lists available options. I'm trying to talk to the com port directly, e.g. "dir > com1". When it works, it prints the directory OK. Quote from: student0101 on January 20, 2015, 12:19:28 PM mode /? shows the command syntax and lists available options.Yes, but I am LITERALLY asking to the the output of MODE /?. I don't have access to any version of DOS anymore so I need to see what the options are.This is what "mode /?" displays: Configures system devices. Printer port: MODE LPTn[:] [COLS=c] [LINES=l] [RETRY=r] Serial port: MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s] [RETRY=r] Device Status: MODE [device] [/STATUS] Redirect printing: MODE LPTn[:]=COMm[:] Prepare code page: MODE device CP PREPARE=((yyy[...]) [drive:][PATH]filename) Select code page: MODE device CP SELECT=yyy Refresh code page: MODE device CP REFRESH Code page status: MODE device CP [/STATUS] Display mode: MODE [display-adapter][,n] MODE CON[:] [COLS=c] [LINES=n] Typematic rate: MODE CON[:] [RATE=r DELAY=d] Quote from: Squashman on January 20, 2015, 09:42:32 AM Did you happen to try typing MODE /? at the DOS prompt and notice any options to display the STATUS of the com port.Quote from: student0101 on January 20, 2015, 12:34:14 PM Device Status: MODE [device] [/STATUS] Did you try that?Yes I did. It only says: Status for device COM1: ------------------------------------- Retry=NONE Quote from: student0101 on January 20, 2015, 12:47:16 PM Yes I did. It only says:Why did it take me 5 posts to get that information out of you? I feel like a Dentist today. Is there any way I could have worded my comments better?I don't know. I think I detailed my problem and how I tried to solve it sufficiently in my initial post. If the answer were in the DOS manual I wouldn't need to bother you. Quote from: BC_Programmer on January 20, 2015, 12:07:41 PM My own memory is a bit rusty but to my recollection you cannot actually view the current settings, the "STATUS" shown for it will only include the RETRY=NONE for some stupid reason. Further googling as you've likely attempted as well doesn't reveal anything. Thanks, BC_Programmer. I was able to download MSD.EXE and run it on MS-DOS 5.0. Under COM Ports it reports COM1 is correctly set for Port Address, Baud rate, Parity, Data Bits and Stop Bits. Carrier Detect=Yes, Ring Indicator=No, Data Set Ready=Yes, Clear to Send=Yes, UART chip Used=16550AF. Printer working OK at the moment. I'll see what it says next time the printer isn't printing. Quote from: student0101 on January 20, 2015, 01:03:56 PM If the answer were in the DOS manual I wouldn't need to bother you.You must not HANG out on a lot of Tech Help Forums. If I had a dime for every time someone didn't bother to check the help file or manual for a program, I could quit my day job and do this as my full-time job if they decided to pay me. Most of the time we act like Dentists trying to extract information from the person posting the question. We can't assume anything about the person posting the question. |
|
| 998. |
Solve : Industrial DOS Projection? |
|
Answer» hi There are miles of differences between Netware 3.x and Netware 6.x.A footnote: NetWare 3.12 Server Taken Down After 16 Years of Continuous Duty Quote The plug was pulled when noise from the server's hard drives become intolerable.do you have an idea for server instead netware with max performance !?Hard to give you any TYPE of server os recommendations when we have no idea what your requirements are and what you are planning to do with the server.Am i the only one who has absolutely no idea what the goal is here ? ?I agree. This thread has gone in 8 different directions already. |
|
| 999. |
Solve : Attrib to remove read-only from folder nested within everything else read-only? |
|
Answer» Trying to figure out a way in batch without going the easy route of windows interface to remove read-only attribute from "Screenshots" folder of this current WoW game CLIENT. C:\Documents and Settings\Dave\Desktop>attrib +r c:\Wow6\*.* /S /DUPDATE on this: Still unable to figure out how to attrib to have the screenshots folder the only folder with read/write privileges within WoW6 which everything else is read only, without cheating and just doing it through Windows GUI. I contacted Blizzard to see if they have been working on a fix for those who dislike the new Character Models. The good thing is that many people flooded them with demands to have a choice to have the original models back. I was pointed to a FEATURE that was slipped into their game client that allowed me to disable the new models and have the game run with the original character models, so the read-only attribute no longer has to be set for the game client and it can fully patch now. So other than curiosity on how to go about the read only attribute set on a folder, with all files within it read-only, except for 1 sub-folder within it and its contents not set to read-only, I guess the intent for the batch is no longer necessary, but finding out if there is still a way to do this in batch still has my interest if its not going to be a waste of anyones time to show how in case I need to do this with other games in the future to have certain folders and files read-only and others able to be overwritten. One THOUGHT I had as I was typing this now is, would I have to deconstruct the folders to say xcopy all but the screenshots folder to another location, set the attrib to read-only for all files and folders and then have to slip the screenshots folder back into it as the only means to do this since attrib doesnt have an exclude switch like xcopy has? Pic attached shows how to change the character model option from within the game client advanced system settings, in case anyone else out there plays wow and wants to know how to go back to the original look of the characters. This is my one female night elf resto druid that I dislike the new character model and prefer the original appearance. [attachment deleted by admin to conserve space]Set a folder or a file to read only doesn't keep you from deleting it or replacing it. You would need to set File Permissions for that. Quote from: DaveLembke on February 12, 2015, 12:09:02 PM Here is what I have that works in setting everything read-only, but the second instruction to remove the read-only attribute only does this for files within Screenshots and does not remove the read-only attribute from the Screenshots folder itself. I didn't follow your post too closely but to change the folder attribute, see if this helps. Code: [Select]attrib +r c:\Wow6\*.* /S /D attrib -r c:\Wow6\screenshots\*.* /S attrib -r c:\Wow6\screenshots /D pauseHello Foxidrive ... Thanks for helping with this... I will try this out when i get home from work later today. I believe I tried the /D alone as you have on the attrib -r c:\Wow6\screenshots /D and it complained that in order to use /D it had to be in conjunction to /S but not /D alone in which it required to be /S /D and not just /D, but you could use /S alone. The OS version is Windows XP Home SP3 btw in case there were any changes to attrib that I am not aware of between windows versions. Maybe I had a typo in the use of /D alone that caused that error message about /D having to be paired with /S. Code: [Select]attrib +r c:\Wow6\*.* /S /D attrib -r c:\Wow6\screenshots\*.* /S attrib -r c:\Wow6\screenshots /D pause Posted by: Squashman Quote Set a folder or a file to read only doesn't keep you from deleting it or replacing it. You would need to set File Permissions for that. hmmm.... so I would have to run as a user level account with the game client with restricted permissions then instead of admin while running the game, and your saying that read-only isnt enough to stop an update from changing the game client. I was thinking that with updates passing like file name data as updates to a game client that the read-only would stop alteration and removal unless the read-only attribute was removed which would then allow for the changes to take. So what i really need to be doing is setting up a user account with restricted permissions that do not allow modification of the game installation at c:\wow6 and all sub folders and files contained within. hmmm I didnt think I was going to restrict it this far and though a simple attribute change for all files and folders would have been good enough. But i see where you are coming from now.A read-only file can't be deleted or overwritten. Attempting to delete a read-only file causes an Access Denied error. Attempting to overwrite it will also cause an Access Denied Error. Windows Explorer however "helpfully" removes the attribute before performing the delete or copy operation and Read Only attributes do nothing in that instance. However, for WoW, it's going to encounter an exception/Error if it tries to overwrite or delete the files. It is possible that the game is designed in the same way as Windows Explorer, and, on encountering an issue overwriting/replacing a file, will remove attributes that are causing it and try again. ACL's are probably a better route to go. You should be able to right-click the folder and choose "Edit..." in the security tab, then you can "deny" the write permission for your account. This assumes- of course- that the game won't crash or show an error message and quit when it encounters an error trying to write those files. Strange. I just created a file. Set to read only and then right clicked it and it deleted just fine. and from the cmd line. Code: [Select]H:\attrib>attrib foo1.txt A R H:\attrib\foo1.txt H:\attrib>del /f foo1.txt H:\attrib>dir Volume in drive H is DATA Volume Serial Number is D2F3-49FA Directory of H:\attrib 02/13/2015 09:41 AM <DIR> . 02/13/2015 09:41 AM <DIR> .. 0 File(s) 0 bytes 2 Dir(s) 126,999,040,000 bytes free H:\attrib> Code: [Select]D:\>mkdir test D:\>cd test D:\test>copy con testfile.txt test file ^Z 1 file(s) copied. D:\test>attrib testfile.txt +r D:\test>del testfile.txt D:\test\testfile.txt Access is denied. D:\test>copy testfile.txt testfile2.txt 1 file(s) copied. D:\test>copy testfile2.txt testfile.txt Overwrite testfile.txt? (Yes/No/All): y Access is denied. 0 file(s) copied. The /f switch on del and erase forces deletion of readonly files by explicitly checking and removing the read only attribute before attempting to delete the file- at which point, the file being deleted is not read-only anymore. copy doesn't have a similar switch, but xcopy does. (/R). World of warcraft is not written in batch, of course. If it doesn't explicitly check for and remove the attribute, it will encounter an exception attempting to Delete it or open it to write new contents. Given that extra logic can remove the attribute fairly easily with something like SetFileAttributes(sFilename,GetFileAttributes(sFileName) & ~FILE_ATTRIBUTE_READONLY), some applications will just remove the flag. (Like Windows Explorer). ACLs are 'safer' (for Dave's purpose) because Applications are unlikely to go fiddling with those when they encounter Error 5. Quote from: DaveLembke on February 13, 2015, 07:31:21 AM I believe I tried the /D alone as you have on the attrib -r c:\Wow6\screenshots /D and it complained that in order to use /D it had to be in conjunction to /S You are correct - try this with the extra /S and it should work but this may just be academic. Code: [Select]attrib +r c:\Wow6\*.* /S /D attrib -r c:\Wow6\screenshots\*.* /S attrib -r c:\Wow6\screenshots /D /S pause |
|
| 1000. |
Solve : batch file to change ini? |
|
Answer» I have a program installed silently on few windows 7 clients. Ok, it's easy to find out the current users profile location.Now is in line 42 I am not soure about that line, because line may change if you change settings in software which use settings.ini I need to test some more for that. yes I intent to supply batch to user by system and run batch file by system on every user when he logs in tool for editing settings.ini, I use notepad.If each path is different 1 batch won't suit your needs... Quote from: Blisk on March 05, 2015, 12:07:38 PM Now is in line 42 If you want an exact solution: then providing a sample settings.ini file with a description of which line needs to change will let someone help you. Quote
Notepad can't be scripted in a batch script. We need to know what tools can be used to edit your file within a batch script. here is settings.ini http://zerobin.povej.net/?91ea09e70c9e153b#bSapGkskui9/Ms46E8+zAnoVZourlGlpRMURDoW0MhA= about tool don't know what you mean. Installed is windeows 7 system. If there is needed some extra tool just let me know and I will check if I can install that on clients. I found some batch which is something like I need if that helps? But I can not complete it for my task. maybe can help for making my batch? Code: [Select]echo off set "file=%userprofile%\AppData\Local\Lotus\Notes\Data\notes.ini" if exist "%file%" ( findstr /v /i "IM_DISABLE= IM_DISABLED=" "%file%" >"%file%.tmp" >>"%file%.tmp" echo/IM_DISABLE=1 >>"%file%.tmp" echo/IM_DISABLED=1 move /y "%file%.tmp" "%file%" >nul )Give this a shot: Code: [Select]echo off call jrepl "^OutputFilePath=.*" "OutputFilePath=%userprofile%\documents" /f settings.ini /o - This uses a helper batch file called `Jrepl.bat` (by dbenham) - DOWNLOAD from: https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat Place `Jrepl.bat` in the same folder as the batch file or in a folder that is on the path. Be aware that Modern Windows protects the user from unknown downloaded files so it may be blocked - if you are happy to try it and it is blocked then * Right click the bat file * select the properties * and click unblock. runas administrator doesn't make any problem so yes I can use that in folder with batch.>Thanks this WORKS great! I have just one problem, replacing settings ini must be when software is off. So first I need to do is taskkill and than run this batch to change settings.ini Is there a way to check first if that settings is already changed and if it is, than won't change it? Like if name Mike exist in settings.ini than must be changed if it deosn't exist than it is already changed. OK I manage that by myself. Thank you for helping now all works great! |
|