

InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your Microsoft knowledge and support exam preparation. Choose a topic below to get started.
251. |
Solve : close windows on error with batch file? |
Answer» <html><body><p>Hi<br/>I have written a batch file that downloads a file from a website and I have added a line that will write text to a log file if there is an error ie no network or website unavailable but the Internet Explorer windows remains open after the batch file ends<br/>Can someone tell me how I can have the Internet Exporer window to close if there is no network connection or the website is unavailabe.<br/><br/>Thanks<br/>GingerAre you going to let us see the batch file, or not?<br/> Quote from: Salmon Trout on September 04, 2010, 10:36:35 AM</p><blockquote>Are you going to let us see the batch file, or not?<br/><br/></blockquote> My cat is called Ginger.<br/>Corruption once again.<br/><br/>Anyway, Ginger, you could try something in the likes of <br/> <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a>: <a>[Select]</a>IF pingDoesntSucceed <br/>DO exit iexplorer<br/> (I don't know, I'm just giving some tips here).<br/> Quote from: Big on September 04, 2010, 08:47:23 PM<blockquote>Corruption once again.<br/><br/>Anyway, Ginger, you could try something in the likes of <br/> Code: <a>[Select]</a>IF pingDoesntSucceed <br/>DO exit iexplorer<br/> (I don't know, I'm just giving some tips here).<br/><br/></blockquote> <br/>That would be the general idea. (will probably use tskill/taskkill iexplore or something to that effect). Ping seems to give an errorlevel of 1 if the host is not found. (although for some reason it is able to resolve <a href="http://www.sdkjfksdhfkjshdjf.com">www.sdkjfksdhfkjshdjf.com</a>, and thinks it exists (?)) It would probably take additional checking with things like ipconfig to be sure that there isn't a internet connection at all (since invalid hosts still seem to resolve, but that might just be my DNS). Another problem is that most task kill programs kill all open tasks of that program, so killing the single process of internet explorer that was started isn't quite as simple as it seems at first glance- you wouldn't want the person running the batch to be using internet explorer (or even worse, a program using IE as an out of process COM component) and suddenly kill all instances of IE. Only other way is to provide the window title, but IE changes it's window title in such a way that it's somewhat difficult to predict. Ideal solution might require a third-party "<a href="https://interviewquestions.tuteehub.com/tag/application-25616" style="font-weight:bold;" target="_blank" title="Click to know more about APPLICATION">APPLICATION</a> starter" that allows you to get the Pid of the program, which can be used by tskill to kill a specific instance.I think, rather than ponder how to close the right instance of Internet Explorer, I would rather avoid opening it at all, and use something like wget or curl, or a vbscript to find out if the network connection, website and desired file are all available, if so to get the file, if not to take appropriate action.<br/><br/> Quote from: Salmon Trout on September 05, 2010, 12:31:40 AM<blockquote>I think, rather than ponder how to close the right instance of Internet Explorer, I would rather avoid opening it at all, and use something like wget or curl, or a vbscript to find out if the network connection, website and desired file are all available, if so to get the file, if not to take appropriate action.<br/><br/><br/></blockquote> <br/>For some reason that never even occurred to me, even though at the time I replied I was working on a <a href="https://interviewquestions.tuteehub.com/tag/class-18125" style="font-weight:bold;" target="_blank" title="Click to know more about CLASS">CLASS</a> that does something very similar in C#. Code: <a>[Select]</a>F:\>ping www.slkqjdfmlkjsdf.com<br/>Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name a<br/>nd try again.<br/> Quote from: Big on September 05, 2010, 09:07:40 AM<blockquote> Code: <a>[Select]</a>F:\>ping www.slkqjdfmlkjsdf.com<br/>Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name a<br/>nd try again.<br/></blockquote> <br/> Code: <a>[Select]</a>C:\Users\BC_Programming>ping www.slkqjdfmlkjsdf.com<br/><br/>Pinging www.slkqjdfmlkjsdf.com [67.215.<a href="https://interviewquestions.tuteehub.com/tag/65-242054" style="font-weight:bold;" target="_blank" title="Click to know more about 65">65</a>.132] with 32 bytes of data:<br/>Reply from 67.215.65.132: bytes=32 time=87ms TTL=55<br/>Reply from 67.215.65.132: bytes=32 time=86ms TTL=55<br/>Reply from 67.215.65.132: bytes=32 time=85ms TTL=55<br/>Reply from 67.215.65.132: bytes=32 time=100ms TTL=55<br/><br/>Ping statistics for 67.215.65.132:<br/> Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br/>Approximate round trip times in milli-seconds:<br/> Minimum = 85ms, Maximum = 100ms, Average = 89ms<br/><br/> Quote<blockquote>since invalid hosts still seem to resolve, <strong>but that might just be my DNS</strong><br/></blockquote> <br/><br/>I'm pretty sure it is.<br/>Let's have a try...<br/><br/> Code: <a>[Select]</a>C:\>ping www.slkqjdfmlkjsdf.com<br/><br/>Pinging www.slkqjdfmlkjsdf.com [81.200.<a href="https://interviewquestions.tuteehub.com/tag/64-242053" style="font-weight:bold;" target="_blank" title="Click to know more about 64">64</a>.50] with 32 bytes of data:<br/>Reply from 81.200.64.50: bytes=32 time=29ms TTL=56<br/>Reply from 81.200.64.50: bytes=32 time=36ms TTL=56<br/>Reply from 81.200.64.50: bytes=32 time=28ms TTL=56<br/>Reply from 81.200.64.50: bytes=32 time=32ms TTL=56<br/><br/>Ping statistics for 81.200.64.50:<br/> Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br/>Approximate round trip times in milli-seconds:<br/> Minimum = 28ms, Maximum = 36ms, Average = 31ms<br/><br/>Hmmm... try a tracert...<br/><br/> Code: <a>[Select]</a>C:\>tracert 81.200.64.50<br/><br/>Tracing route to advancedsearch.virginmedia.com [81.200.64.50]<br/>over a maximum of 30 hops:<br/><br/> 1 7 ms 22 ms 37 ms 10.25.252.1<br/> 2 8 ms 37 ms 16 ms aztw-geam-1b-ge210.network.virginmedia.net [80.1.243.133]<br/> 3 48 ms 29 ms 23 ms aztw-core-1b-ae0-0.network.virginmedia.net [80.1.241.13]<br/> 4 8 ms 9 ms 37 ms brhm-bb-1b-as1-0.network.virginmedia.net [213.105.175.161<br/> 5 52 ms 79 ms 69 ms manc-bb-1a-as6-0.network.virginmedia.net [62.253.185.134]<br/> 6 14 ms 39 ms 14 ms manc-bb-1b-ae5-0.network.virginmedia.net [213.105.174.186<br/> 7 34 ms 25 ms 36 ms te-4-3.ar3.CDG2.gblx.net [204.246.200.177]<br/> 8 29 ms 28 ms 29 ms 64.214.140.138<br/> 9 30 ms 41 ms 37 ms advancedsearch.virginmedia.com [81.200.64.50]<br/><br/>Trace complete.<br/> Quote from: Tracert output<blockquote>advancedsearch.virginmedia.com</blockquote> <br/>Aha!<br/><br/><br/><br/><br/><br/><br/><br/> Code: <a>[Select]</a>C:\>ping www.slkqjdfmlkjsdf.com<br/>Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name and try again.<br/>That's better.<br/><br/> Quote from: BC_Programmer on September 05, 2010, 09:12:30 AM<blockquote><br/>I'm pretty sure it is.<br/><br/></blockquote> <br/>Sure looks that way<br/><br/> Code: <a>[Select]</a>C:\>tracert 67.215.65.132<br/><br/>Tracing route to hit-nxdomain.opendns.com [67.215.65.132]<br/>over a maximum of 30 hops:<br/><br/> 1 64 ms 14 ms 8 ms 10.25.252.1<br/> 2 45 ms 19 ms 233 ms aztw-geam-1a-ge147.network.virginmedia.net [80.1.243.1]<br/> 3 33 ms 10 ms 11 ms aztw-core-1a-ae0-0.network.virginmedia.net [80.1.241.9]<br/> 4 50 ms 31 ms 34 ms winn-bb-1a-as0-0.network.virginmedia.net [213.105.175.157]<br/> 5 12 ms 44 ms 12 ms brnt-bb-1b-as5-0.network.virginmedia.net [213.105.172.234]<br/> 6 59 ms 16 ms 16 ms 195.50.91.129<br/> 7 47 ms 17 ms 35 ms ae-32-52.ebr2.London2.Level3.net [4.68.117.62]<br/> 8 17 ms 70 ms 45 ms ae-3-3.ebr1.London1.Level3.net [4.69.141.189]<br/> 9 28 ms 15 ms 50 ms ae-100-100.ebr2.London1.Level3.net [4.69.141.166]<br/> 10 41 ms 31 ms 23 ms ae-48-48.ebr2.Amsterdam1.Level3.net [4.69.143.81]<br/> 11 68 ms 27 ms 24 ms ae-2-52.edge4.Amsterdam1.Level3.net [4.69.139.170]<br/> 12 35 ms 46 ms 65 ms SPLICE-COMM.edge4.Amsterdam1.Level3.net [212.72.40.98]<br/> 13 23 ms 54 ms 57 ms hit-nxdomain.opendns.com [67.215.65.132]<br/><br/>Trace complete.</body></html> | |
252. |
Solve : Command vs Batch file? |
Answer» <html><body><p>I am using the MOVE command, but running in to a problem. If I put the command in to a Command <a href="https://interviewquestions.tuteehub.com/tag/window-11540" style="font-weight:bold;" target="_blank" title="Click to know more about WINDOW">WINDOW</a> it works fine, but from a batch file I get errors. Why? I am running on a Windows 7(64 bit).<br/><br/>move /Y C:\#CAMS\Download\DST_exe\*.* C:\%Backup\DST\<br/><br/>If I use this at a DOS prompt it works great. <br/>If I use it in a batch file I get the messages "Cannot move multiple files to a single file"<br/><br/>Both folders do exist, and there are multiple files in them.<br/><br/>Maybe there is a better way. What I am doing is moving file I download then extract files from (exe files and zip files) to a different directory. For example, all DST Files are an EXE file that is then ran and put in a 'DST_Work' folder for the <a href="https://interviewquestions.tuteehub.com/tag/database-11539" style="font-weight:bold;" target="_blank" title="Click to know more about DATABASE">DATABASE</a> to <a href="https://interviewquestions.tuteehub.com/tag/process-11618" style="font-weight:bold;" target="_blank" title="Click to know more about PROCESS">PROCESS</a>. I clear the 'Work" folder, but I want to archive the files in the "DST_exe" folder. I have 5 vendors like this. Some are exe, some are zip, and another uses a different format.<br/><br/>Any advice is appreciated.<br/><br/>MichaelThere's a number of syntax problems with your line of code.<br/><br/>% needs to be escaped as %%. Better yet, you shouldn't use this character in folder or file names...<br/><br/>You should also surround your paths with <a href="https://interviewquestions.tuteehub.com/tag/quotation-1175219" style="font-weight:bold;" target="_blank" title="Click to know more about QUOTATION">QUOTATION</a> marks, so the command doesn't screw up when it encounters a space.<br/><br/>move /Y "C:\#CAMS\Download\DST_exe\*.*" "C:\%%Backup\DST\"<br/><br/>If Backup is supposed to be an expanded variable, it's because you forgot the second %.<br/><br/>move /Y "C:\#CAMS\Download\DST_exe\*.*" "C:\%Backup%\DST\"<br/><br/>You see, % is <a href="https://interviewquestions.tuteehub.com/tag/used-763273" style="font-weight:bold;" target="_blank" title="Click to know more about USED">USED</a> in expanding DOS variables.</p></body></html> | |
253. |
Solve : Reproduce unicode from text file?? |
Answer» <html><body><p>I'm writing a script which I want to support reading unicode paths from a text file. I want all the unicode to be reproduced the same as pasting the characters into DOS where it appears as a square-like character. (DOS has no problem dealing with unicode characters, they just can't be displayed and this is fine.)<br/><br/><strong>Type</strong> will <em>not</em> reproduce unicode from a text file properly, regardless of the file's encoding and the current code page. <strong>For</strong> cannot process <strong>type</strong>'s junky unicode output which makes it impossible to stick in a variable. <strong>For</strong> has no problem with pasted unicode as aforementioned...<br/><br/>So far:<br/>I open <strong>cmd.exe /u</strong> so I can redirect a unicode path to a text file. This encodes it as <strong>UTF-16LE</strong>. Let's say I have the path containing the Japanese hiragana "ki". The path and UTF-16LE-encoded text file look like this:<br/>"C:\Folder き"<br/><br/>Basically, I need a utility that works like <strong>type</strong> to read the text file and reproduce this string properly, as-is. I was told gawk might be able to do it, but I don't have a clue where to start with gawk.<br/><br/>Can anyone who knows vbscript accomplish this in vbscript? If it can't output the text properly to command prompt, if it can at least send the lines properly as arguments to an executable, that would be okay. I found <a href="http://www.xtremedotnettalk.com/showpost.php?p=457931&postcount=7">this</a> (second half, Unicode to ASCII) but don't know how much it could help. I've spent hours on this scouring the web and I've found next to nothing. Help please! Thanks!I am not sure I understand what you are trying to say in your description, but I do understand the question in the subject so <a href="https://interviewquestions.tuteehub.com/tag/thats-248329" style="font-weight:bold;" target="_blank" title="Click to know more about THATS">THATS</a> what I am going to answer.<br/><br/>I think in order to turn a ASCII text file into a unicode text file, you simply need to rewrite the file with every 2nd byte a null character. I might be wrong. If I am not, this could probably be accomplished in almost any programming language that supports file IO. In VB you could allocate two byte arrays. One of which twice the size of the other. The file could then be read into the first array and then copied to every other byte in the second array. Then every 2nd byte in the 2nd array could be set to 0. Finally, the second array could be written back to the file or to a new file if necessary.<br/><br/>If it is confirmed that my reasoning is correct, then I would write the code for you. I am just not sure that this is the correct way to convert.Thanks for responding. As you thought, you're not on the right track. Btw, Japanese characters overwrite that 00 padding, as part of unicode.<br/><br/>I have a text file encoded as UTF-16LE containing the following:<br/>"C:\Folder き"<br/><br/>I want to <strong>type</strong> this file in a batch script to the same effect as typing <strong>set <a href="https://interviewquestions.tuteehub.com/tag/myvar-1108041" style="font-weight:bold;" target="_blank" title="Click to know more about MYVAR">MYVAR</a>="C:\Folder き"</strong> manually in command prompt, where the き character would appear as a square (which means the character is there, it just can't be displayed). But as I described, the <strong>type</strong> command only works properly with ANSI text files, and <strong>type</strong>-ing the text file within a <strong>for</strong> loop to set the output to a variable does not work - <strong>for</strong> fails. <strong>For</strong> works fine when entering the text manually as I described though. It leads me to believe it's how <strong>type</strong> outputs the characters based on the current code page, which is apparently not the same.<br/><br/>Again, I believe I just need a vbscript or something that can output the text file properly - in the same character coding context as doing it manually.<br/><br/>Edit: I should probably show what I'm describing after all, lol.<br/><br/>for /f "delims=" %%x in ('type unicode_path.txt') do set myvar=%%x<br/><br/>Does not do anything, because <strong>type</strong> is outputting sloppy ANSI/code-page interpreted unicode and <strong>for</strong> doesn't like it.<br/><br/>I think it would be a command prompt <a href="https://interviewquestions.tuteehub.com/tag/revolution-247052" style="font-weight:bold;" target="_blank" title="Click to know more about REVOLUTION">REVOLUTION</a> of sorts if you could code a vbscript which works! This is a big issue! lol<br/><br/>I'm likely to reproduce my big script in PowerShell once it's done (I'll still complete it, unicode or not), but I'd like to exhaust any options first.Is this sufficient? It just reads a text file into the command prompt. There is a way to make it take the file name as an argument, but I can't remember that part right now. You probably could have done that yourself, but i figured I would respond anyway. I might be able to come up with something better later if needed. I am using a <a href="https://interviewquestions.tuteehub.com/tag/mac-546540" style="font-weight:bold;" target="_blank" title="Click to know more about MAC">MAC</a> now.<br/><br/> Code: <a>[Select]</a>Set objFSO = CreateObject("Scripting.FileSystemObject")<br/>Set objFile = objFSO.OpenTextFile("c:\blablabla.txt", 1)<br/>Do Until objFile.AtEndOfStream<br/>Wscript.Echo objFile.ReadLine<br/>Loop<br/>objFile.Close<br/><br/>EDIT: Be aware that you have to run this using cscript not wscript or it will just pop up a messagebox.I don't know vbscript at all actually, it's one of those things I can read but can't write.<br/><br/>I only need to process one file, so it doesn't need to accept a file name for an argument, but it does need to work with relative paths so hopefully that's not a problem.<br/><br/>I tested it and it's reading the text file similar to <strong>type</strong>, bad encoding. The only difference being that I can manipulate the output in <strong>for</strong>, so that's a good sign that it could just require some encoding work next.<br/><br/>There might be some vbscript clues in the link in my original post:<br/><br/><a href="http://www.xtremedotnettalk.com/showpost.php?p=457931&postcount=7">http://www.xtremedotnettalk.com/showpost.php?p=457931&postcount=7</a><br/><br/>Here is what they all output. UNI is the unicode file I'm working with. UTF is the unicode file converted to UTF-8. I also changed code pages from the default to UTF-8 just to see:<br/><br/><br/><br/>One more thing, if <strong>type utf.txt</strong> under the UTF-8 code page would work with <strong>for</strong>, that would almost solve the problem, except that I'd need a utility to convert the UTF-16LE file to UTF-8, and changing to code page 65001 makes batch scripts exit... <br/><br/>I think I did it. I decided to program it in c because I thought this may be a useful tool for other people to use and it seems more official to make an exe tool. I know you said you didn't need it to take arguments, but I added one anyway just encase someone else needs it.<br/><br/>I've attached the exe and code below.<br/><br/>[recovering disk space - old attachment deleted by admin]I just realized that what I posted might not work. Do you just want all the unicode characters removed from the string or do you want to replace them with a space or a box or what?<br/><br/>I will reply with new code when you confirm this. I have already put way too much time into this thread so bear with me until I can figure this out.If you can use Python, <br/> Code: <a>[Select]</a>import codecs<br/>import sys<br/>inputfile=sys.argv[1]<br/>f = codecs.open( inputfile, "r", "utf-16" )<br/>for line in f:<br/> print line<br/><br/>output<br/> Code: <a>[Select]</a>C:\test>more i.am.utf16.file.txt<br/>here i am , utf-16 encoded file<br/><br/>C:\test>file i.am.utf16.file.txt<br/>i.am.utf16.file.txt; Little-endian UTF-16 Unicode text, with no line terminators<br/><br/>C:\test>od -c i.am.utf16.file.txt<br/>0000000 ■ h \0 e \0 r \0 e \0 \0 i \0 \0<br/>0000020 a \0 m \0 \0 , \0 \0 u \0 t \0 f \0<br/>0000040 - \0 1 \0 6 \0 \0 e \0 <a href="https://interviewquestions.tuteehub.com/tag/n-236724" style="font-weight:bold;" target="_blank" title="Click to know more about N">N</a> \0 c \0 o \0<br/>0000060 d \0 e \0 d \0 \0 f \0 i \0 l \0 e \0<br/>0000100 \n \0<br/>0000102<br/><br/><br/>C:\test>python test.py i.am.utf16.file.txt<br/>here i am , utf-16 encoded file<br/><br/><br/>its so much easier Quote from: Linux711 on September 08, 2010, 03:31:39 PM</p><blockquote>I just realized that what I posted might not work. Do you just want all the unicode characters removed from the string or do you want to replace them with a space or a box or what?<br/><br/>I will reply with new code when you confirm this. I have already put way too much time into this thread so bear with me until I can figure this out.<br/></blockquote> <br/>Thanks for your help Linux but you're still misunderstanding what's required.<br/><br/>If you have Windows, open a command prompt window and paste this:<br/><br/> Code: <a>[Select]</a>for /f "usebackq delims=" %x in ('"C:\Folder き"') do set myvar=%x<br/>This sets myvar to "C:\Folder き". The き character is displayed as a square, but it is still read as き.<br/><br/>Do this to save a text file unicode.txt as UTF-16LE (Unicode) containing "C:\Folder き":<br/><br/> Code: <a>[Select]</a>%ComSpec% /u /c echo:"C:\Folder き">unicode.txt<br/>Then try this:<br/><br/> Code: <a>[Select]</a>for /f "delims=" %x in ('type unicode.txt') do set myvar=%x<br/>Does nothing because type fails. Then try:<br/><br/> Code: <a>[Select]</a>type unicode.txt<br/>You will see that this does not output "C:\Folder き", but instead:<br/><br/> Code: <a>[Select]</a> C : \ F o l d e r M0"<br/>So I need something that will output "C:\Folder き".<br/><br/>ghostdog74: I'll try your code as well. Thanks!ghostdog74, I installed Python 3.1.2 and saved your script as read.py.<br/><br/>My UTF-16LE file uni.txt contains:<br/>"C:\Folder き"<br/><br/>Both files are inside the current directory.<br/><br/>This is my MS-DOS command prompt:<br/><br/><br/><br/>What am I doing wrong? Quote from: orange_batch on September 08, 2010, 11:15:00 PM<blockquote>What am I doing wrong?<br/></blockquote> if you are using Python 3.1 ++, the print statement is now a function, so add brackets.<br/> Code: <a>[Select]</a>import codecs<br/>import sys<br/>inputfile=sys.argv[1]<br/>f = codecs.open( inputfile, "r", "utf-16" )<br/>for line in f:<br/> print(line)<br/>And Python is particular about indentation, so indent properly.I'm not 100% sure how much better it would be as an alternative but following your example, I used more < unicode.txt and I got this:<br/><br/> Code: <a>[Select]</a>D:\>more < unicode.txt<br/>"C:\Folder ?"<br/><br/>So I thought- maybe changing the codepage and THEN using this more to do it will work?<br/><br/> Code: <a>[Select]</a>D:\>chcp 65001<br/>Active code page: 65001<br/><br/>D:\>more < unicode.txt<br/>Not enough memory.<br/><br/>That was certainly an unexpected result. I wasn't able to get anything useful out of it either. ( tried copy unicode.txt con as well, which gave the same result as the type command). I found the fact that more wasn't displaying it spaced out and had a question mark rather then the ASCII-i-fied unicode promising, but redirecting that to a text file, even if I used the /u switch to start cmd still resulted in ASCII, with the double-byte character being converted to a question mark.<br/><br/>Personally, I'd go with GhostDog's solution.<br/><br/><br/> Quote from: orange_batch on September 08, 2010, 11:15:00 PM<blockquote>ghostdog74, I installed Python 3.1.2 and saved your script as read.py.<br/><br/>My UTF-16LE file uni.txt contains:<br/>"C:\Folder き"<br/><br/>Both files are inside the current directory.<br/><br/>This is my MS-DOS command prompt:<br/><br/><br/><br/>What am I doing wrong?<br/></blockquote> I think the codecs package/import is deprecated, or at least the codecs.open routine is, in python 3.1 and later.<br/><br/>works in activestate perl 2.6.4... or, to be more precise, it runs. (without a syntax error, not sure why you are getting that)<br/><br/>I do get this though:<br/><br/> Code: <a>[Select]</a>D:\>python D:\test.py unicode.txt<br/>Traceback (most recent call last):<br/> File "D:\test.py", line 5, in <module><br/> for line in f:<br/> File "C:\Python\lib\codecs.py", line 679, in next<br/> return self.reader.next()<br/> File "C:\Python\lib\codecs.py", line 610, in next<br/> line = self.readline()<br/> File "C:\Python\lib\codecs.py", line 525, in readline<br/> data = self.read(readsize, firstline=True)<br/> File "C:\Python\lib\codecs.py", line 472, in read<br/> newchars, decodedbytes = self.decode(data, self.errors)<br/> File "C:\Python\lib\encodings\utf_16.py", line 90, in decode<br/> raise UnicodeError,"UTF-16 stream does not start with BOM"<br/>UnicodeError: UTF-16 stream does not start with BOM<br/>for some reason the command prompt doesn't redirect it's unicode output with a Byte Order Marker. I did a little looking to see if there was a way to specify to the open method to pretend there isn't a BOM and go with either LE or BE ordering, but my search was fruitless.<br/><br/>It appeared to work for ghostdog, so I assume we are both doing something incorrect- your version is too new (no idea wether this is really the case) and probably changed something, whereas I... well, I'm not sure what I did wrong. perhaps I made the unicode file incorrectly.<br/><br/>Updated. Same here BC.<br/><br/>BC, Orange, first of all, the cmd.exe shell does not support utf-16, so its no use using it to run your script (although Python does process it normally at the back end). Secondly, I am using Python 2.6.x. so i am not sure about Python 3.1.X but, here's another method<br/><br/> Code: <a>[Select]</a>data = open("c:\\test\\file1", 'rb').read()<br/>decoded = data.decode('utf-16')<br/>print decoded<br/><br/>try the above using the Python Windows editor (comes with distribution) or some other platform that can display unicode..<br/>I only know the tip of the iceberg of unicode so for more information, check with the docs <br/><br/>1) <a href="https://docs.python.org/howto/unicode.html">Unicode</a> how to <br/>2) <a href="https://docs.python.org/library/codecs.html">codecs</a> module<br/>3) search at <a href="https://stackoverflow.com/search?q=python++utf16+">stackoverflow</a>Well, the script itself is not unicode (DOS fails spectacularly with that), but it deals with path names which might contain unicode.<br/><br/>Microsoft knows some dirty secret about this unicode business. <br/><br/><br/><br/>Still not working ghostdog. But I'm not disheartened, because jeb on DosTips.com made me realize a fair enough workaround:<br/><br/>First of all, I'm only dealing with folder names, but this can be applied to files as well.<br/><br/>Forget the whole <strong>cmd /u</strong> thing and it outputs the ? in place of unicode as usual. ? matches any single character in a path, including unicode.<br/><br/>Retrieve the unicode in a folder name:<br/><strong>for /d %%x in ("C:\Folder ?") set folder="%%x"</strong><br/><br/>(or retrieve the unicode in a file name:)<br/><strong>for %%x in ("C:\file ?") set file="%%x"</strong><br/><br/>There are two problems however:<br/><br/>1. "C:\Folder ?" will match both "C:\Folder き" and "C:\Folder こ", etc.<br/><br/>2. <strong>for /r "C:\Folder ?"...</strong> does not work. Other things might not work either, without retrieving the unicode.<br/>Solution: <strong>pushd "C:\Folder ?"</strong> then <strong>for /r</strong> with no <strong>"path"</strong> (processes current directory) then <strong>popd</strong>.<br/><br/>For the first problem, we can detect if it returns more than one result or not. If it does, have the user choose between which folders during run-time. This would have to verify each folder containing ? from the root folder to the most descendant folder. Parent folders can be filtered further by their descendants, unless the descendant folders exist in both parents, or something to that effect. I'm going to figure it out and work on a script for this.<br/><br/> It's the best that can be done. If anyone who comes across this can manage a solution to the original problem, it would still be desired.</body></html> | |
254. |
Solve : How to get back to the command line?? |
Answer» <html><body><p>Assume I have one <a href="https://interviewquestions.tuteehub.com/tag/excel-25682" style="font-weight:bold;" target="_blank" title="Click to know more about EXCEL">EXCEL</a> file locates at H:\My Documents\Docs\X.xls. I start it by command "<a href="https://interviewquestions.tuteehub.com/tag/call-412416" style="font-weight:bold;" target="_blank" title="Click to know more about CALL">CALL</a> H:\My Documents\Docs\X.xls". After X.xls is started, the command line can not accept <a href="https://interviewquestions.tuteehub.com/tag/new-1114486" style="font-weight:bold;" target="_blank" title="Click to know more about NEW">NEW</a> input until the X.xls file closed. Is there any <a href="https://interviewquestions.tuteehub.com/tag/solution-25781" style="font-weight:bold;" target="_blank" title="Click to know more about SOLUTION">SOLUTION</a> to get back to command line and make the new input workable and meanwhile no need to close X.xls? Thanks!H:\My Documents\Docs\X.xls just thatDont <a href="https://interviewquestions.tuteehub.com/tag/use-241643" style="font-weight:bold;" target="_blank" title="Click to know more about USE">USE</a> call, use start<br/>Thanks you two friends!! Both of your solutions work well!!</p></body></html> | |
255. |
Solve : Batch File- Delete Files (Folder Name is a Variable)? |
Answer» <html><body><p>So to make this as simple as possible... <br/><br/>Our department is running <a href="https://interviewquestions.tuteehub.com/tag/winxp-7304272" style="font-weight:bold;" target="_blank" title="Click to know more about WINXP">WINXP</a> X86, SP3. The <a href="https://interviewquestions.tuteehub.com/tag/problem-25530" style="font-weight:bold;" target="_blank" title="Click to know more about PROBLEM">PROBLEM</a> I am having pertains to Outlook 2007. When opening attachments, Outlook 07 dumps the attachment into a temp folder. The location can be found in the registry key. When this folder reaches maximum <a href="https://interviewquestions.tuteehub.com/tag/capacity-239235" style="font-weight:bold;" target="_blank" title="Click to know more about CAPACITY">CAPACITY</a>, Outlook will no longer allow attachments to be opened. Ultimately, my question is can a batch file be created to erase files from a folder that has a randomly assigned name? Or, instead, can a batch file be created to change the registry key <a href="https://interviewquestions.tuteehub.com/tag/value-238057" style="font-weight:bold;" target="_blank" title="Click to know more about VALUE">VALUE</a>, so the OLK cache folder can be assigned a specific name? Then, I believe I could create a batch file to be used universally on all of our desktops that <a href="https://interviewquestions.tuteehub.com/tag/would-3285927" style="font-weight:bold;" target="_blank" title="Click to know more about WOULD">WOULD</a> empty the temp folder. Any feedback would be appreciated. Quote</p><blockquote>So to make this as simple as possible... <br/></blockquote> <br/>Simple is good, but the post is a little short on specifics. It would have been nice to know the registry key.<br/><br/>You can use the <strong>reg query </strong>utility to extract the directory name from the registry and then use the <strong>del</strong> command with a wildcard. <br/><br/>Something like his may help:<br/><br/> Code: <a>[Select]</a>echo off<br/>for /f "skip=2 tokens=3" %%i in ('reg query HKLM\system\currentcontrolset\services\tcpip\parameters /v databasepath') do echo del %%i\*<br/><br/>The registry key is the path found in the left pane of the <strong>regedit</strong> program. The <strong>/v </strong>switch value is the name field found in the right pane of the <strong>regedit</strong> program. The value returned by the <strong>for</strong> statement is the data field in the right pane of the <strong>regedit</strong> program.<br/><br/>The code snippet contains an <strong>echo</strong> instruction to prevent any deletions until you are satisfied the returned directory is valid. Remove when you are ready. The snippet can be modified to delete the files (attachments) individually in case you need to keep some based on name or date or whatever.<br/><br/>Good luck. <br/></body></html> | |
256. |
Solve : datestamp help? |
Answer» <html><body><p>hi all - I need a batch file to search in a directory. If all the files have the current date stamp then execute command1 if files are not current then execute command2.<br/>thank you.This can be done via Perl or a number of other languages which have abilities to compare <a href="https://interviewquestions.tuteehub.com/tag/strings-13382" style="font-weight:bold;" target="_blank" title="Click to know more about STRINGS">STRINGS</a>, but I cant see doing this in raw batch. Quote from: DaveLembke on September 21, 2010, 10:10:00 PM</p><blockquote>This can be done via Perl or a number of other languages which have abilities to compare strings, but I cant see doing this in raw batch.<br/></blockquote> <br/>It is a commonplace everyday task for batch. It can easily be done... using FOR and the ~t variable modifier you can get the "date" (created or last modified?) of each file, and it is trivially easy to get today's date. <br/><br/>However we do not know the OP's local date format or the format returned on his system by ~t<br/><br/>The output of this script will <a href="https://interviewquestions.tuteehub.com/tag/tell-1240910" style="font-weight:bold;" target="_blank" title="Click to know more about TELL">TELL</a> us those things.<br/><br/> Code: <a>[Select]</a>echo off<br/>echo local date format [%date%]<br/>echo.>temp$$$<br/>for /f %%A in ("temp$$$") do echo file date format [%%~tA]<br/>del temp$$$<br/>pause<br/><br/><br/>For example, I get this<br/><br/> Code: <a>[Select]</a>local date format [22/09/2010]<br/>file date format [22/09/2010 07:46 AM]<br/>But I am worried about this in the question<br/><br/> Quote<blockquote>I need a batch file to search in a directory. If<em><strong> all the files have the current date stamp</strong></em> then execute command1 if files are not current then execute command2.<br/>thank you.</blockquote> <br/>All the files? What if 99 do and 1 does not? Likewise for the converse situation.<br/><br/>these files will <a href="https://interviewquestions.tuteehub.com/tag/always-373607" style="font-weight:bold;" target="_blank" title="Click to know more about ALWAYS">ALWAYS</a> have the same date. I guess we can look in one particular file to check for the date.<br/>thanks Quote from: x3g on September 22, 2010, 07:58:01 AM<blockquote>these files will always have the same date. I guess we can look in one particular file to check for the date.<br/>thanks<br/></blockquote> <br/>So did you run my script?<br/>your script works good but it is missing the logic I need.<br/> Quote from: x3g on September 22, 2010, 09:44:19 AM<blockquote>your script works good but it is missing the logic I need.<br/><br/></blockquote> <br/>I asked you to run the script so I could see your local date format. Then I can make a script for you with the logic that you need.<br/>ah here it is<br/>local date format [Wed 09/22/2010]<br/>file date format [09/22/2010 11:14 AM]<br/><br/>thank you. Code: <a>[Select]</a>echo off<br/>setlocal enabledelayedexpansion<br/><br/>REM Of course you <a href="https://interviewquestions.tuteehub.com/tag/understand-720010" style="font-weight:bold;" target="_blank" title="Click to know more about UNDERSTAND">UNDERSTAND</a> you need to edit this<br/>set foldername="S:\Test\Batch\After 03-07-2010\test-file-date"<br/><br/>set pdate=%date%<br/>set today=%pdate:~4,10%<br/><br/>REM get file date of latest file in folder<br/>for /f "delims=" %%A in ( ' dir /b /a-d /od %foldername% ' ) do (<br/> set fdate=%%~tA<br/> set fdate=!fdate:~0,10!<br/> )<br/><br/>if "%fdate%"=="%today%" (<br/> goto yes<br/>) else (<br/> goto no<br/> )<br/><br/>:yes<br/>echo YES!!!<br/>rem Code to execute if file date is today<br/>goto next<br/><br/>:no<br/>rem Code to execute if file date is not today<br/>echo NO!!!<br/><br/>:next<br/>REM whatever happens next...<br/><br/>pause<br/><br/><br/><br/> <br/> <br/> this looks very promising. I'll let you know my feedback once I've tested.<br/>Thank you.<br/>the YES condition works great but the NO logic only works for files that are older than 1 day. If the latest files are from yesterday it will still run the YES logic. Quote from: x3g on September 22, 2010, 01:13:29 PM<blockquote>the YES condition works great but the NO logic only works for files that are older than 1 day. If the latest files are from yesterday it will still run the YES logic.<br/></blockquote> <br/>are you quite sure about this? Because the test would be<br/><br/>if "09/21/2010"=="09/22/2010" <br/><br/>which should fail and therefore the else <a href="https://interviewquestions.tuteehub.com/tag/clause-246677" style="font-weight:bold;" target="_blank" title="Click to know more about CLAUSE">CLAUSE</a> gets triggered.<br/><br/>Could you insert these diagnostic lines shown in red?<br/><br/><br/>echo off<br/>setlocal enabledelayedexpansion<br/><br/>REM Of course you understand you need to edit this<br/>set foldername="S:\Test\Batch\After 03-07-2010\test-file-date"<br/><br/>set pdate=%date%<br/>set today=%pdate:~4,10%<br/><br/>REM get file date of latest file in folder<br/>for /f "delims=" %%A in ( ' dir /b /a-d /od %foldername% ' ) do (<br/> set fdate=%%~tA<br/> set fdate=!fdate:~0,10!<br/> )<br/><br/><br/><br/><strong><br/>echo today is %today%<br/>echo fdate is %fdate%<br/>echo comparing [%fdate%] with [%today%]<br/></strong><br/><br/>if "%fdate%"=="%today%" (<br/> goto yes<br/>) else (<br/> goto no<br/> )<br/><br/>:yes<br/>echo YES!!!<br/>rem Code to execute if file date is today<br/>goto next<br/><br/>:no<br/>rem Code to execute if file date is not today<br/>echo NO!!!<br/><br/>:next<br/>REM whatever happens next...<br/><br/>pause<br/><br/><br/>even though the files are dated 9/21/2010 fdate still shows 9/22<br/><br/>today is 09/22/2010<br/>fdate is 09/22/2010<br/>comparing [09/22/2010] with [09/22/2010]<br/>YES<br/>Press any key to continue . . .<br/><br/>are you quite sure there is no file dated 09/22/2010 in that folder, including hidden files?<br/>I replaced the 9/21 files with some 9/14 & 9/20 files and get this <br/><br/>today is 09/22/2010<br/>fdate is ~0,10<br/>comparing [~0,10] with [09/22/2010]<br/>NO<br/>Press any key to continue . . .</body></html> | |
257. |
Solve : Replacing characters in a large amount of folders? |
Answer» <html><body><p>Hi,<br/><br/>I'm having troubles renaming folders<br/><br/>a colleague has a large amount of folders that contain # and she wants to replace these characters to _<br/><br/>123#12#12raw --> 123_12_12raw<br/><br/>What I have done today as a <a href="https://interviewquestions.tuteehub.com/tag/quick-1174961" style="font-weight:bold;" target="_blank" title="Click to know more about QUICK">QUICK</a> fix was list all the folders in a txt<br/>dir /b *#* > print.txt<br/><br/>then I opened this txt in excel and generated <a href="https://interviewquestions.tuteehub.com/tag/lines-240113" style="font-weight:bold;" target="_blank" title="Click to know more about LINES">LINES</a> for each folder and pasted these in a *.bat<br/><br/>move 123#12#12raw 123_12_12raw<br/>move 123#12#13raw 123_12_13raw<br/>.....<br/><br/>This worked perfectly but it is not very user friendly<br/><br/>Is there a way to use the move command with wildcards?<br/><br/>I tried <br/>move *#*#* *_*_*<br/>but this (probably obvious) doesn't work.<br/><br/>If I try to find the files like that it does work<br/>dir /b *#*#*<br/><br/>I spent the last 2 hours googeling but didn't find a decent solution yet<br/><br/>I also tried to do something with<br/>for %1 in (*#*) do move %1 xxxxxx<br/>but I can't figure out how to alter the variable so that # gets replaced with _ in %1 <br/><br/>Anyone with suggestions?<br/><br/>Thanks,<br/><br/>JupkeGot an answer onan other (car)forum <br/><br/>Wanted to share it here as well<br/><br/> Code: <a>[Select]</a>C:\Users\Roel\test>FOR /F "tokens=1,2,3 delims=#" %A IN ('dir /b *#*') DO move %<br/>A#%B#%C %A_%B_%C<br/><br/>C:\Users\Roel\test>move 2123#12#14 2123_12_14<br/>Er zijn 1 map(pen) verplaatst.<br/><br/>C:\Users\Roel\test>move 22123#12#13 22123_12_13<br/>Er zijn 1 map(pen) verplaatst.<br/><br/>C:\Users\Roel\test>what's all that weird euro language stuff?<br/> Quote from: Salmon Trout on September 15, 2010, 01:03:22 PM</p><blockquote>what's all that weird euro language stuff?<br/><br/></blockquote> <br/>I 'm sorry, I forgot to paste only the relevant part, edited the code now<br/><br/>"Er zijn 1 map(pen) verplaatst." means 1 folder has been moved.An alternative, maybe: if you want to take folder names containing # and replace that character with _ why bother using move? Just get the folder name into a string variable, use the replace function of the SET command, and rename the folder with the new string. E.g<br/><br/> Code: <a>[Select]</a>echo off<br/>setlocal enabledelayedexpansion<br/>for /f "delims=" %%A in ('dir /b /ad *#*') do (<br/> set oldname=%%A<br/> set newname=!oldname:#=_!<br/> echo renaming "!oldname!" to "!newname!"<br/> REN "!oldname!" "!newname!"<br/> )<br/> <br/>To do all subdirectories change dir /b /ad to dir /s /b /ad<br/><br/>Before...<br/><br/> Code: <a>[Select]</a>C:\test>dir<br/> Volume in drive S is USBHD<br/> Volume Serial Number is 2C51-AA7F<br/><br/> Directory of C:\Test<br/>15/09/2010 08:45 PM <DIR> .<br/>15/09/2010 08:45 PM <DIR> ..<br/>15/09/2010 08:44 PM <DIR> folder#1<br/>15/09/2010 08:44 PM <DIR> folder#2<br/>15/09/2010 08:44 PM <DIR> folder#3<br/>15/09/2010 08:44 PM <DIR> folder#<a href="https://interviewquestions.tuteehub.com/tag/4-238406" style="font-weight:bold;" target="_blank" title="Click to know more about 4">4</a><br/>15/09/2010 08:45 PM <DIR> folder#4#5#6#####7<br/>15/09/2010 08:44 PM 215 test1.bat<br/> 1 File(s) 217 bytes<br/> 7 Dir(s) 188,506,218,496 bytes free<br/><br/> Code: <a>[Select]</a>c:\Test\>test1.bat<br/>renaming "folder#1" to "folder_1"<br/>renaming "folder#2" to "folder_2"<br/>renaming "folder#3" to "folder_3"<br/>renaming "folder#4" to "folder_4"<br/>renaming "folder#4#5#6#####7" to "folder_4_5_6_____7"<br/><br/>After...<br/><br/> Code: <a>[Select]</a>C:\Test>dir<br/> Volume in drive S is USBHD<br/> Volume Serial Number is 2C51-AA7F<br/><br/> Directory of C:\Test<br/><br/>15/09/2010 08:48 PM <DIR> .<br/>15/09/2010 08:48 PM <DIR> ..<br/>15/09/2010 08:44 PM <DIR> folder_1<br/>15/09/2010 08:44 PM <DIR> folder_2<br/>15/09/2010 08:44 PM <DIR> folder_3<br/>15/09/2010 08:44 PM <DIR> folder_4<br/>15/09/2010 08:45 PM <DIR> folder_4_5_6_____7<br/>15/09/2010 08:48 PM 217 test1.bat<br/> 1 File(s) 217 bytes<br/> 7 Dir(s) 188,506,218,496 bytes free<br/>Indeed, this also works, but the effect is in this case exactly the sale with move as rename here?<br/><br/>I'm not sure in win7 but I thought rename didn't work for folder in XP? Quote from: Jupke on September 15, 2010, 02:18:59 PM<blockquote>Indeed, this also works, but the effect is in this case exactly the sale with move as rename here?</blockquote> <br/>Yes, however move has a potential ambiguity that ren does not, viz: <br/><br/>move folder1 folder2 (if folder2 does not exist!) is equivalent to ren folder1 folder2; BUT if folder2 does exist, folder1 can be moved to be a subfolder of folder2, unless its attributes forbid this . However, ren only renames, never <a href="https://interviewquestions.tuteehub.com/tag/moves-239392" style="font-weight:bold;" target="_blank" title="Click to know more about MOVES">MOVES</a>.<br/><br/> Quote<blockquote>I'm not sure in win7 but I thought rename didn't work for folder in XP?</blockquote> <br/>1. Where did you get that idea?<br/>2. Could you not have done an experiment?<br/>3. It works for all Windows, as far as I know, as long as you have the right permissions and the folder attributes allow it.<br/><br/> Code: <a>[Select]</a>G:\test>ver<br/><br/>Microsoft Windows XP [Version 5.1.2600]<br/><br/>G:\test>md testdir<br/><br/>G:\test>dir<br/> Volume in drive G is DATA1<br/> Volume Serial Number is 9476-662D<br/><br/> Directory of G:\test<br/><br/>15/09/2010 22:42 <DIR> ..<br/>15/09/2010 22:42 <DIR> testdir<br/>15/09/2010 22:42 <DIR> .<br/> 0 File(s) 0 bytes<br/> 3 Dir(s) 16,695,369,728 bytes free<br/><br/>G:\test>ren testdir cakes-and-coffee<br/><br/>G:\test>dir<br/> Volume in drive G is DATA1<br/> Volume Serial Number is 9476-662D<br/><br/> Directory of G:\test<br/><br/>15/09/2010 22:42 <DIR> ..<br/>15/09/2010 22:42 <DIR> cakes-and-coffee<br/>15/09/2010 22:42 <DIR> .<br/> 0 File(s) 0 bytes<br/> 3 Dir(s) 16,695,369,728 bytes free<br/><br/>G:\test></body></html> | |
258. |
Solve : DOS opens Internet Explorer and...? |
Answer» <html><body><p>I'm trying to figure out how to use <a href="https://interviewquestions.tuteehub.com/tag/dos-432778" style="font-weight:bold;" target="_blank" title="Click to know more about DOS">DOS</a> <a href="https://interviewquestions.tuteehub.com/tag/coding-25511" style="font-weight:bold;" target="_blank" title="Click to know more about CODING">CODING</a> to open up Internet Explorer and make it go to a specific site. I know to make it go to IE, I <a href="https://interviewquestions.tuteehub.com/tag/need-25476" style="font-weight:bold;" target="_blank" title="Click to know more about NEED">NEED</a> something lie:<br/><br/>echo off<br/>START xxx/xxx/xxx/xxx/IE.exe<br/><br/>But how do I get it to go to a specific website?if you want to use DOS to start IE and then go to specific website and then do nothing else, you might as <a href="https://interviewquestions.tuteehub.com/tag/well-734398" style="font-weight:bold;" target="_blank" title="Click to know more about WELL">WELL</a> go to your "Start" button and launch it. Its faster that way. BUT if you want to go to the website and download stuff and maybe you want to schedule it, then use vbscript for native or use a tool such as wget/curl to do it.The web page is entered an an argument for IEXPLORE.EXE. Use the following link to Google as an example:<br/> Code: <a>[<a href="https://interviewquestions.tuteehub.com/tag/select-630282" style="font-weight:bold;" target="_blank" title="Click to know more about SELECT">SELECT</a>]</a>(path to ie directory)\IEXPLORE.EXE http://www.google.com<br/>Interesting, would you be able to link in multiple sites? Like using && and just link in more?</p></body></html> | |
259. |
Solve : Rename multiple files whose names are contained in an XML file.? |
Answer» <html><body><p>Hi Guys,<br/><br/>I have a bunch of 'm4a' files that i need to <a href="https://interviewquestions.tuteehub.com/tag/rename-613846" style="font-weight:bold;" target="_blank" title="Click to know more about RENAME">RENAME</a>, literally thousands, they're voice memos from my iPhone.<br/><br/>I have them stored on my hard disk in the directory 'C:\Memos'.<br/><br/>I have an xml file which contains the name of the file and the tag that the file should be called <br/><br/>The xml file contains all the file names, and all the tags that the files should be named.<br/><br/>I've included a sample of the xml file below to give a better idea of how it's structured.<br/><br/> <br/> <br/>- <br/>- <br/> 20090816 104438.m4a <br/> Autosleep <br/> 20090816 124708.m4a <br/> Head pillow <br/> <br/> <br/><br/>So the file '20090816 104438.m4a' needs to be renamed 'Autosleep.m4a', the file '20090816 124708.m4a' needs to be renamed 'Head pillow.m4a' , etc.<br/><br/>Is there a way of doing this automatically with python or vbscript perhaps?<br/><br/>Any help or advice would be much appreciated as I am new to this and have been doing the renaming manually so far, but i've thousands of files to get through. <br/><br/>Thanks again,<br/><br/>JP<br/>I'm sure you'll get a Python solution but I went with VBScript because it comes installed with Windows and there is no download required for those that won't or can't download third party products.<br/><br/> Code: <a>[Select]</a>Dim arrKey()<br/>Dim arrString()<br/><br/>Set xmlDoc = CreateObject("Microsoft.XMLDOM")<br/>Set fso = CreateObject("Scripting.FileSystemObject")<br/><br/>xmlDoc.async = False<br/>xmlDoc.load("c:\temp\ch.xml") 'change path\filename as required<br/><br/>Set KeyList = xmlDoc.documentElement.selectNodes("dict/key")<br/>i = -<a href="https://interviewquestions.tuteehub.com/tag/1-236780" style="font-weight:bold;" target="_blank" title="Click to know more about 1">1</a><br/>For Each key in KeyList<br/> i = i + 1<br/> ReDim Preserve arrKey(i)<br/> arrKey(i) = key.text<br/>Next<br/><br/>Set StringList = xmlDoc.documentElement.selectNodes("dict/string")<br/>i = -1<br/>For Each str in StringList<br/> i = i + 1<br/> ReDim Preserve arrString(i)<br/> arrString(i) = str.text<br/>Next<br/><br/>For i = <a href="https://interviewquestions.tuteehub.com/tag/0-242464" style="font-weight:bold;" target="_blank" title="Click to know more about 0">0</a> To UBound(arrKey) <br/> Set f = fso.GetFile(arrKey(i))<br/> newName = arrString(i)<br/> f.Name = newName & "." & fso.GetExtensionName(arrKey(i))<br/>Next <br/><br/>There is probably a simpler way to do this with the XMLDOM object, but I chose to go with brute force. Save the snippet with a <strong>vbs</strong> extension and run from the command line as <strong>cscript <em>scriptname.vbs</em></strong> Be sure to change the path\file name as required.<br/><br/>Good luck. Here's a Python solution. Note you should really use an XML parser like lxml, but since your sample XML is simple enough.....<br/> Code: <a>[Select]</a>import os<br/>import sys<br/>inputfile=sys.argv[1]<br/>keys=[]<br/>strings=[]<br/>for line in open(inputfile):<br/> s=line.rstrip()<br/> if "<key&<a href="https://interviewquestions.tuteehub.com/tag/gt-249387" style="font-weight:bold;" target="_blank" title="Click to know more about GT">GT</a>;" in s:<br/> keys.append(s[s.index(">")+1:].replace("</key>",""))<br/> if "<string>" in s:<br/> strings.append(s[s.index(">")+1:].replace("</string>",""))<br/>for k,v in zip(keys,strings):<br/> try:<br/> print "Renaming %s to %s"%(k, v)<br/> os.rename(k,v)<br/> except OSError,e:<br/> print e<br/> else:<br/> print "Renamed %s to %s." %(k,v)<br/><br/><br/>on command line<br/> Code: <a>[Select]</a>c:\test> python myscript.py myxml.xml<br/>Thanks a million for your help.<br/><br/>Having a slight problem here<br/><br/>The vb script is called 'memos.vbs', the xml file is 'C:\memo\l.xml'<br/><br/>When i run the script from command prompt using 'cscript memos.vbs' i get the error:<br/><br/>C:\memo.vbs(27,2) Microsoft VBScript runtime error: File not found'<br/><br/>Any advice on <a href="https://interviewquestions.tuteehub.com/tag/resolving-2248888" style="font-weight:bold;" target="_blank" title="Click to know more about RESOLVING">RESOLVING</a> the above would be much appreciated! Thanks again for your help. <br/><br/>My script is:<br/><br/>Dim arrKey()<br/>Dim arrString()<br/><br/>Set xmlDoc = CreateObject("Microsoft.XMLDOM")<br/>Set fso = CreateObject("Scripting.FileSystemObject")<br/><br/>xmlDoc.async = False<br/>xmlDoc.load("C:\memo\l.xml") 'change path\filename as required<br/><br/>Set KeyList = xmlDoc.documentElement.selectNodes("dict/key")<br/>i = -1<br/>For Each key in KeyList<br/> i = i + 1<br/> ReDim Preserve arrKey(i)<br/> arrKey(i) = key.text<br/>Next<br/><br/>Set StringList = xmlDoc.documentElement.selectNodes("dict/string")<br/>i = -1<br/>For Each str in StringList<br/> i = i + 1<br/> ReDim Preserve arrString(i)<br/> arrString(i) = str.text<br/>Next<br/><br/>For i = 0 To UBound(arrKey) <br/> Set f = fso.GetFile(arrKey(i))<br/> newName = arrString(i)<br/> f.Name = newName & "." & fso.GetExtensionName(arrKey(i))<br/>Next Thanks ghostdog!<br/><br/>The python scrit doesn't give the files the 'm4a' extension, but does change all the file names to the correct tag.<br/><br/>Is there a way to change the extension of multiple files, or perhaps include it in the python script?<br/><br/>Thanks again,<br/><br/>Jp Quote from: jpm999 on September 11, 2010, 07:43:03 PM</p><blockquote>Thanks ghostdog!<br/><br/>The python scrit doesn't give the files the 'm4a' extension, but does change all the file names to the correct tag.<br/><br/>Is there a way to change the extension of multiple files, or perhaps include it in the python script?<br/><br/>Thanks again,<br/><br/>Jp<br/></blockquote> <br/>then add the string ".m4a" <br/> Code: <a>[Select]</a>os.rename(k,v+".m4a")<br/>Its not that difficult. Now, go read up Python docs.</body></html> | |
260. |
Solve : How to keep FTP connection alive in command line?? |
Answer» <html><body><a href="https://interviewquestions.tuteehub.com/tag/hi-479908" style="font-weight:bold;" target="_blank" title="Click to know more about HI">HI</a> Friends,<br/><br/>As you know, in default, <a href="https://interviewquestions.tuteehub.com/tag/ftp-20066" style="font-weight:bold;" target="_blank" title="Click to know more about FTP">FTP</a> connection time out is 120 seconds. It is very boring to re-connect frequently. So is there any way to make ftp connection alive for specified long time or for ever until close it explicitly?<br/><br/> I often encountered the following boring message:<br/><strong>Connection <a href="https://interviewquestions.tuteehub.com/tag/closed-919469" style="font-weight:bold;" target="_blank" title="Click to know more about CLOSED">CLOSED</a> by <a href="https://interviewquestions.tuteehub.com/tag/remote-621964" style="font-weight:bold;" target="_blank" title="Click to know more about REMOTE">REMOTE</a> host.</strong><br/><br/>Hope you can help me out of this <a href="https://interviewquestions.tuteehub.com/tag/trouble-344061" style="font-weight:bold;" target="_blank" title="Click to know more about TROUBLE">TROUBLE</a>!! Thanks!!possibilities, FTP server configured to close connection after certain time of idling, OR a firewall in between can close the connection.</body></html> | |
261. |
Solve : shortcut keys for copy and paste in command line? |
Answer» <html><body><p>Hi Friends,<br/><br/>not sure if there are some shortcut keys for <a href="https://interviewquestions.tuteehub.com/tag/copy-25621" style="font-weight:bold;" target="_blank" title="Click to know more about COPY">COPY</a> and paste content in command line?<br/><br/>normally, I must use right click->mark->select <a href="https://interviewquestions.tuteehub.com/tag/target-25812" style="font-weight:bold;" target="_blank" title="Click to know more about TARGET">TARGET</a> text->enter to copy target text and right-click->paste.<br/><br/>it is boring to do so even it is frequent, so could you please do me a favor on this?<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/thanks-665909" style="font-weight:bold;" target="_blank" title="Click to know more about THANKS">THANKS</a>!If you enable the Quick <a href="https://interviewquestions.tuteehub.com/tag/edit-11544" style="font-weight:bold;" target="_blank" title="Click to know more about EDIT">EDIT</a> Mode, and Insert Mode properties in the command <a href="https://interviewquestions.tuteehub.com/tag/window-11540" style="font-weight:bold;" target="_blank" title="Click to know more about WINDOW">WINDOW</a>, then you can select the text with the left mouse button, click the right button to copy, and again to paste.</p></body></html> | |
262. |
Solve : "For" and "If" command doubt? |
Answer» <html><body><p>Hi,<br/><br/>This is my first post. I'm here for asking a question about a doubt I can't solve. I've already read most of on line help available, but I cannot do my batch work correctly.<br/><br/>This batch should look for every *inside.jpg files under my Music folder and if the file "Front Cover Inside.jpg" doesn't exist it should rename *inside.jpg file to "Front Cover Inside.jpg". <br/>But if "Front Cover Inside.jpg" exist and there's some *inside file, it should log <em>"Similar file to '*inside.jpg' already exists"</em><br/><br/>My batch:<br/> Code: <a>[Select]</a>for /R %%x in (*inside.jpg) do if not exist "Front Cover Inside.jpg" (<br/>ren "%%x" "Front Cover Inside.jpg"<br/>echo "%%x" renamed to "Front Cover Inside.jpg" >> Log.txt<br/>) <a href="https://interviewquestions.tuteehub.com/tag/else-printfy-344787" style="font-weight:bold;" target="_blank" title="Click to know more about ELSE">ELSE</a> (<br/>echo Similar file to "%%x" already exists >> Log.txt<br/>)<br/><br/>PS: Log.txt file already exists. I'm working on a Windows XP Professional SP3 machine.I just ran your script twice, and the first time, it renamed "0D0A inside.jpg" to "Front Cover Inside.jpg", and added this line to log.txt<br/><br/>"S:\Test\Batch\After 03-07-2010\for-if\0D0A inside.jpg" renamed to "Front Cover Inside.jpg" <br/><br/>The second time it did nothing and wrote this line<br/><br/>Similar file to "S:\Test\Batch\After 03-07-2010\for-if\Front Cover Inside.jpg" already exists <br/><br/>Isn't this what you want?<br/><br/> Quote from: Salmon Trout on September 08, 2010, 02:13:06 PM</p><blockquote>I just ran your script twice, and the first time, it renamed "0D0A inside.jpg" to "Front Cover Inside.jpg", and added this line to log.txt<br/><br/>"S:\Test\Batch\After 03-07-2010\for-if\0D0A inside.jpg" renamed to "Front Cover Inside.jpg" <br/><br/>The second time it did nothing and wrote this line<br/><br/>Similar file to "S:\Test\Batch\After 03-07-2010\for-if\Front Cover Inside.jpg" already exists <br/><br/>Isn't this what you want?<br/></blockquote> <br/>My problem is when "Front Cover Inside.jpg" <strong>coexists</strong> with some file like "0D0A inside.jpg".<br/>What I want to be logged is:<br/> Code: <a>[Select]</a>"Similar file to "S:\Test\Batch\After 03-07-2010\for-if\0D0A inside.jpg" already exists" which in this case is "Front Cover Inside.jpg").<br/><br/>Then, after reading the log, I will manually check which file is "0D0A inside.jpg" and if it's quality is better than "Front Cover Inside.jpg" it will delete this one.<br/>I need this because I have thousands of album art files I don't want to check then one by one...<br/><br/>TIAFinally I think I've solved my problem. My final batch looks like this:<br/><br/> Quote<blockquote>echo off<br/>for /R %%x in (*-inside.jpg) do if not exist "Front Cover Inside.jpg" (<br/>ren "%%x" "Front Cover Inside.jpg"<br/>if errorlevel 1 (<br/>echo Similar file to "%%x" already exists >> Log.txt<br/>goto end<br/>)<br/>echo "%%x" renamed to "Front Cover Inside.jpg" >> Log.txt<br/>)<br/><br/>:end</blockquote> <br/>The trick is using errorlevel. When trying to rename the file, if there's already a file with the same name, MS-DOS will return a error message. I've just use this to sove my problem.<br/>I've tried different scenarios and it worked the way I want it. So, I'm proud of myself, considering how newbie I'm in MS-DOS command line... Quote from: vitorb on September 11, 2010, 07:40:29 AM<blockquote>Finally I think I've solved my problem. My final batch looks like this:<br/><br/>The trick is using errorlevel. When trying to rename the file, if there's already a file with the same name, <strong>MS-DOS</strong> will return a error message. I've just use this to sove my problem.<br/>I've tried different scenarios and it worked the way I want it. So, I'm proud of myself, considering how newbie I'm in <strong>MS-DOS</strong> command line...<br/></blockquote> <br/><br/>This is going to start driving me completely <a href="https://interviewquestions.tuteehub.com/tag/insane-516431" style="font-weight:bold;" target="_blank" title="Click to know more about INSANE">INSANE</a>. Quote from: BC_Programmer on September 11, 2010, 08:33:52 AM<blockquote><br/>This is going to start driving me completely insane.<br/></blockquote> <br/> Sorry... You're completely right! I know that MS-DOS it's a operating system and what I'm using is just a command line interpreter. <br/>Ten <a href="https://interviewquestions.tuteehub.com/tag/years-239545" style="font-weight:bold;" target="_blank" title="Click to know more about YEARS">YEARS</a> ago I <a href="https://interviewquestions.tuteehub.com/tag/used-763273" style="font-weight:bold;" target="_blank" title="Click to know more about USED">USED</a> MS-DOS for a few months, but I never developed any <a href="https://interviewquestions.tuteehub.com/tag/skills-25483" style="font-weight:bold;" target="_blank" title="Click to know more about SKILLS">SKILLS</a> on it's usage...And the tweaking goes on...<br/><br/>My previous batch had one problem. This code:<br/> Code: <a>[Select]</a>for /R %%x in (*inside.jpg) do if not exist "Front Cover Inside.jpg"doesn't seems to work correctly because after the batch finish I saw that every "Front Cover Inside.jpg" files in various directories had been renamed again to it's current name.<br/><br/> Code: <a>[Select]</a>ren "%%x" "Front Cover Inside.jpg"Whenever %x is "Front Cover Inside.jpg" it will be:<br/> Code: <a>[Select]</a>ren "Front Cover Inside.jpg" "Front Cover Inside.jpg" which is useless...<br/><br/>So I've change it this way:<br/> Code: <a>[Select]</a>for /R %%x in (*inside.jpg) do if "%%~nxx"=="Front Cover Inside.jpg" (<br/>echo "Front Cover Inside.jpg" already exists<br/>) else (<br/>ren "%%x" "Front Cover Inside.jpg"<br/>if errorlevel 1 (<br/>echo Similar file to "%%x" already exists >> Log.txt<br/>) else (<br/>echo "%%x" renomed to "Front Cover Inside.jpg" >> Log.txt<br/>)<br/>)</body></html> | |
263. |
Solve : sorting folders according to content file extension!? |
Answer» <html><body><p>Hello .. guys.. <br/><br/>As i cannot find any batchfile wich can do my job,and <br/>since i got a unsorted folder with more then 20000 files to be sorted, i am <a href="https://interviewquestions.tuteehub.com/tag/tired-661145" style="font-weight:bold;" target="_blank" title="Click to know more about TIRED">TIRED</a> of doing it manualy<br/>can or is it possible to batch this. <br/>can some one tell me if this is possible in a msdos batch file ..<br/>folders has more then one files but particular file extensions makes my decision where to put the folder. <br/>this is the situation in unsorted <br/> <br/>\---root<br/> +---sorted<br/> | +---te1<br/> | +---te2<br/> | \---te3<br/> \---unsorted<br/> +---folder1<br/> | pre.te3<br/> | <br/> +---folder2<br/> | pre.te1<br/> | <br/> \---<a href="https://interviewquestions.tuteehub.com/tag/folder3-2085922" style="font-weight:bold;" target="_blank" title="Click to know more about FOLDER3">FOLDER3</a><br/> pre.te2 <br/><br/>this is what i want to end up sorted all files in the corrsponding folders.<br/><br/>| <br/>\---root<br/> +---sorted<br/> | +---te1<br/> | | \---folder2<br/> | | pre.te1<br/> | | <br/> | +---te2<br/> | | \---folder3<br/> | | pre.te2<br/> | | <br/> | \---te3<br/> | \---folder1<br/> | pre.te3<br/> | <br/> \---unsorted<br/><br/><br/>In short i wanne sort files but keep the folder names in the new sorted map structure. <br/><br/>i have tried to use different aproaches like dir *.te1 /D/B/S > te1.log<br/>and use this log file to sort, but got stuck on how to use this log in a "for" environement<br/><br/>help is appreciateddo you actually just need to view the output (at your screen) as sorted, or do you actually want to move the files from "unsorted" folder into the the "sorted" folder, then display them ? define your problem clearlymoving the folders as shown above.<br/>or copy and use the unsorted as backup.<br/><br/>i do not need to view the output <br/>as i said in my first post just moving/copying into the sorted folder<br/><br/>The folder structure shown above is only to clearify my problem. Since words are sometimes not enough and misunderstood.<br/><br/> Quote from: mazhive on September 06, 2010, 12:27:02 PM</p><blockquote>can some one tell me if this is possible in a msdos batch file ..<br/></blockquote> yes, its possible. My solution is not batch, so if you can install Python, here's a script you can use<br/><br/> Code: <a>[Select]</a>import os<br/>import shutil<br/>root="C:\\"<br/>dirsortedpath=os.path.join(root,"test","sorted") # put sorted path here<br/>dirunsortedpath=os.path.join(root,"test","unsorted") # unsorted path<br/>os.chdir(dirsortedpath)<br/>dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ]<br/>for r,d,f in os.walk(dirunsortedpath):<br/> for files in f:<br/> ext=files[-3:].lower() #get the extension<br/> if ext in dirsorted:<br/> try:<br/> shutil.move(r, os.path.join(dirsortedpath,ext))<br/> except Exception,e:<br/> print e<br/> else:<br/> print "moved .."<br/>save as myscript.py on the command line<br/> Code: <a>[Select]</a>c:\test> python myscript.py<br/><br/><br/>If not, you can wait for your batch solution.that would be no problem.<br/>thanx !!!! gone chek it out later this evening thanx... it seems that it moves only the file not the folder <br/><br/>so i get root\sorted\te1\xxxxxx.te1<br/>not root\sorted\te1\folder 3\xxxxx.te1<br/><br/>do i have to change more than only the sorted path and unsorted path.<br/><br/>thanx.. alot for this piece of code... i use cygwin to do some linux like stuf and it has python installed on default. Quote from: mazhive on September <a href="https://interviewquestions.tuteehub.com/tag/09-256415" style="font-weight:bold;" target="_blank" title="Click to know more about 09">09</a>, 2010, 05:22:41 AM<blockquote>it seems that it moves only the file not the folder <br/><br/>so i get root\sorted\te1\xxxxxx.te1<br/>not root\sorted\te1\folder 3\xxxxx.te1<br/><br/>do i have to change more than only the sorted path and unsorted path.<br/><br/>thanx.. alot for this piece of code... i use cygwin to do some linux like stuf and it has python installed on default. <br/></blockquote> <br/>you can always debug your script by using print . First comment out shutil.move line , then just insert a print statement<br/> Code: <a>[Select]</a>print "Moving " r , " to ", os.path.join(dirsortedpath,ext)<br/># shutil.move(r, os.path.join(dirsortedpath,ext))<br/><br/>see if its what you want. If yes, then the shutil.move should not be the problem.<br/>sorry but i get an error message.<br/><br/>print "Moving " r , " to ", os.path.join(dirsortedpath,ext)<br/> ^<br/>IndentationError: unident does not match any outer indentation level<br/><br/>####BOF<br/><br/>import os<br/>import shutil<br/>root="C:\\"<br/>dirsortedpath=os.path.join(root,"TEMP","batch","root","sorted") # put sorted path here<br/>dirunsortedpath=os.path.join(root,"TEMP","batch","root","unsorted") # unsorted path<br/>os.chdir(dirsortedpath)<br/>dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ]<br/>for r,d,f in os.walk(dirunsortedpath):<br/> for files in f:<br/> ext=files[-3:].lower() #get the extension<br/> if ext in dirsorted:<br/> try:<br/> print "Moving " r , " to ", os.path.join(dirsortedpath,ext)<br/># shutil.move(r, os.path.join(dirsortedpath,ext))<br/> except Exception,e:<br/> print e<br/> else:<br/> print "moved .."<br/><br/>###EOF<br/><br/><br/>I am using Nano to add or change a line of the python script.<br/> Python is particular about indentation, so indent properly(use spaces, not tabs)<br/><br/> Code: <a>[Select]</a>import os<br/>import shutil<br/>root="C:\\"<br/>dirsortedpath=os.path.join(root,"TEMP","batch","root","sorted") # put sorted path here<br/>dirunsortedpath=os.path.join(root,"TEMP","batch","root","unsorted") # unsorted path<br/>os.chdir(dirsortedpath)<br/>dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ]<br/>for r,d,f in os.walk(dirunsortedpath):<br/> for files in f:<br/> ext=files[-3:].lower() #get the extension<br/> if ext in dirsorted:<br/> try:<br/> print "Moving " r , " to ", os.path.join(dirsortedpath,ext)<br/> #shutil.move(r, os.path.join(dirsortedpath,ext))<br/> except Exception,e:<br/> print e<br/> else:<br/> print "moved .."<br/><br/>thanx i didn't know,... i am not that familiar with python scripting.<br/><br/>but now i got this,...<br/><br/>print "Moving " r , " to ", os.path.join(dirsortedpath,ext)<br/> ^<br/>SyntaxError: Invalid syntax<br/><br/>i greatly appreciate your help and patience.<br/> Quote from: mazhive on September 09, 2010, 05:21:08 PM<blockquote>thanx i didn't know,... i am not that familiar with python scripting.<br/><br/>but now i got this,...<br/><br/>print "Moving " r , " to ", os.path.join(dirsortedpath,ext)<br/> ^<br/>SyntaxError: Invalid syntax<br/><br/>i greatly appreciate your help and patience.<br/> <br/></blockquote> <br/>sorry, it should be<br/> Code: <a>[Select]</a>print "Moving ", r , " to ", os.path.join(dirsortedpath,ext)<br/><br/>Now proceed to look at the <a href="https://www.python.org/doc/">Python</a> documentations. Take the tutorial if you are not familiarthanx ,... hmm i feel like stupid right now ,....<br/>now it doesn't move anything.<br/>and no error... Quote from: mazhive on September 09, 2010, 06:13:35 PM<blockquote>thanx ,... hmm i feel like stupid right now ,....<br/>now it doesn't move anything.<br/>and no error... <br/></blockquote> of course it doesn't because the shutil.move line is commented right ?? Uncomment the line when you are ready to move, but in the meantime, just use the print statements to see if you have got the correct files <br/><br/> And what does your output <a href="https://interviewquestions.tuteehub.com/tag/show-236642" style="font-weight:bold;" target="_blank" title="Click to know more about SHOW">SHOW</a>? If you have print statements in your script, it will show when you run the script. If it did not show, then it shows that the<br/><br/> Code: <a>[Select]</a>if ext in dirsorted:<br/>is not executed. Like i told you, if you are not sure, put in print statements to show the execution<br/><br/> Code: <a>[Select]</a>....<br/>for r,d,f in os.walk(dirunsortedpath):<br/> for files in f: <br/> print "now doing file: " , os.path.join(r,files)<br/> ext=files[-3:].lower() #get the extension<br/> print "Extension is ", ext<br/> .....<br/>Just a question, will the folders only contain <strong><em>1</em></strong> file type?oke,..<br/><br/>well some <a href="https://interviewquestions.tuteehub.com/tag/times-344892" style="font-weight:bold;" target="_blank" title="Click to know more about TIMES">TIMES</a> it has 3 files but only 1 is important for me to decide <br/>the actual extensions would be ,t64 ,d64 ,crt ,p00 ,prg with these files, sometime a txt file or nfo or doc are within that folder but that does not make my decision to move it in a folder<br/> so these te1 or te2 are just for experimental environment so i can use it in my actual folder and files later.<br/><br/>ghostdog... well thats the point it does do a output but doesn't move the folder now i put the other piece of code in it and it gives me output but no moved folders yet it moved the files.<br/><br/>###BOF<br/><br/>import os<br/>import shutil<br/>root="C:\\"<br/>dirsortedpath=os.path.join(root,"TEMP","batch","root","sorted") # put sorted path here<br/>dirunsortedpath=os.path.join(root,"TEMP","batch","root","unsorted") # unsorted path<br/>os.chdir(dirsortedpath)<br/>dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ]<br/>for r,d,f in os.walk(dirunsortedpath):<br/> for files in f: <br/> print "now doing file: " , os.path.join(r,files)<br/> ext=files[-3:].lower() #get the extension<br/> print "Extension is ", ext<br/>for r,d,f in os.walk(dirunsortedpath):<br/> for files in f:<br/> ext=files[-3:].lower() #get the extension<br/> if ext in dirsorted:<br/> try:<br/> print "Moving ", r , " to ", os.path.join(dirsortedpath,ext)<br/> shutil.move(r, os.path.join(dirsortedpath,ext))<br/> except Exception,e:<br/> print e<br/> else:<br/> print "moved .."<br/><br/>###EOF</body></html> | |
264. |
Solve : Change drive in CMD? |
Answer» <html><body><p>I can't change drive by using D:<br/><br/>I tried using the CD command and specifying the full location but that doesn't work either.<br/><br/>Someone help a newbie out?<br/>Are you positive that you have a drive D? Can you access it via <a href="https://interviewquestions.tuteehub.com/tag/windows-22662" style="font-weight:bold;" target="_blank" title="Click to know more about WINDOWS">WINDOWS</a> explorer?Yes. It certainly is there. I'm using a windows 7 starter edition because I'm in a foreign country running a netbook, is that helpfull?What if you create a shortcut to cmd.exe and under the "Start in" field or something <a href="https://interviewquestions.tuteehub.com/tag/similar-1207900" style="font-weight:bold;" target="_blank" title="Click to know more about SIMILAR">SIMILAR</a>, type D:\. Now when you run that shortcut, does it work?If that doesn't work you could try command.com instead of cmd.exeThat "Start in" option worked. Now when I start up cmd I'm in the D partition... and I cannot change to my C drive. It keeps saying my syntax is not in order but all I type in is C: or I tried C:\ or CD C:\somefolder and hit returnthe way to change <a href="https://interviewquestions.tuteehub.com/tag/drives-959782" style="font-weight:bold;" target="_blank" title="Click to know more about DRIVES">DRIVES</a> is to type the letter, upper case or lower case, followed by a colon. A full colon like this <strong>:</strong> <br/><br/> Code: <a>[Select]</a>c:\>D:<br/><br/>D:\><br/> Quote</p><blockquote>It keeps saying my syntax is not in order </blockquote> <br/>What does it say <em><strong>exactly</strong></em>?<br/><br/>Is your keyboard OK? Is the layout <a href="https://interviewquestions.tuteehub.com/tag/setting-241130" style="font-weight:bold;" target="_blank" title="Click to know more about SETTING">SETTING</a> right? Can you type colons? like this ::::::::::::::::::: Do you see them on the screen?<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/another-876628" style="font-weight:bold;" target="_blank" title="Click to know more about ANOTHER">ANOTHER</a> way to change drives is to use CD with the /D switch, Does this work?<br/><br/> Code: <a>[Select]</a>D:\>CD /D C:<br/><br/>c:\><br/>Ha! It was a keyboard settings thing. I bought this thing in Colombia, I'm not exactly Colombian. Tnx for the help.</body></html> | |
265. |
Solve : If statements in command line? |
Answer» <html><body><p>Hi,<br/><br/> I'm trying to create a command script(.cmd file) with if statements.I don't think the if statements work here.Because even though the first if condition fails,the <a href="https://interviewquestions.tuteehub.com/tag/control-425557" style="font-weight:bold;" target="_blank" title="Click to know more about CONTROL">CONTROL</a> always goes to LAST STEP.<br/><br/>Also can you please explain how to do if<> and <><br/><br/>Thanks and appreciate your help on this.<br/><br/>Here is the code:<br/><br/>ECHO ON<br/><br/>SET JOBNAME=TEST<br/><br/>for /F %%G in ('sqlcmd -E -S TAMANS-SQ12DCL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do (echo %BATCH_QUERY%:%%G)<br/><br/><br/>if %ERRORLEVEL% equ 0 if %BATCH_QUERY% gtr 0 (GOTO LASTSTEP)<br/>if %ERRORLEVEL% NEQ 0 (GOTO ERROR1)<br/><br/>:LASTSTEP<br/>echo ********************************************** <br/>echo * <a href="https://interviewquestions.tuteehub.com/tag/completion-926298" style="font-weight:bold;" target="_blank" title="Click to know more about COMPLETION">COMPLETION</a> OK *<br/>echo ********************************************** <br/>:NORMAL<br/>ECHO <a href="https://interviewquestions.tuteehub.com/tag/sucessful-3085234" style="font-weight:bold;" target="_blank" title="Click to know more about SUCESSFUL">SUCESSFUL</a> Completion of ICV001. <br/>SET ControlM=0<br/>GOTO END<br/><br/><br/>:ERROR1<br/>echo ********************************************** <br/>echo * %JOBNAME% NOT OK *<br/>echo ********************************************** <br/>echo %JOBNAME% Abended<br/>REM THERE WAS AN ERROR!<br/>SET CONTROLM=1<br/>goto END<br/><br/><br/>:END<br/>ECHO %JOBNAME% done. <br/><br/> Where does the variable %BATCH_QUERY% get a value?<br/>from %%G after the query executes.<br/><br/>for /F %%G in ('sqlcmd -E -S TAMANS-SQ12DCL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do (echo %BATCH_QUERY%:%%G)<br/> Quote</p><blockquote>from %%G after the query executes.</blockquote> <br/>That does not set the value; it echoes %BATCH_QUERY%, a colon, and <a href="https://interviewquestions.tuteehub.com/tag/whatever-736216" style="font-weight:bold;" target="_blank" title="Click to know more about WHATEVER">WHATEVER</a> %%G happens to be. If you did not do <br/><br/>SET BATCH_QUERY=<br/><br/>before, it will be undefined (blank).<br/><br/><br/><br/><br/>So,should it be like this......<br/><br/>set BATCH_QUERY=0<br/><br/>set BATCH_QUERY=for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do echo %%G<br/> Quote from: priyabala on September 20, 2010, 02:58:22 PM<blockquote>So,should it be like this......<br/><br/>set set BATCH_QUERY=0<br/><br/>set BATCH_QUERY=for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do echo %%G<br/><br/></blockquote> <br/>If you want the output of the sqlcmd command to be assigned to the variable BATCH_QUERY you could do something like this<br/><br/> Code: <a>[Select]</a>for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do set BATCH_QUERY=%%G<br/>is it going to be a number?<br/><br/>Sorry about the delayed reply.<br/><br/>Yes, it is going to be a number.<br/><br/>Also,can you please let me know how to do multiple conditions in if statments.Is this correct.<br/><br/>if %ERRORLEVEL% equ 0 if %BATCH_QUERY% gtr 0 (GOTO LASTSTEP)<br/>if %ERRORLEVEL% NEQ 0 (GOTO ERROR1)<br/><br/><br/>Please let me know.I really appreciate your help on this.<br/><br/>Thanks.<br/> Code: <a>[Select]</a><br/>REM put this test FIRST<br/>if %errorlevel% neq 0 goto error1<br/><br/>REM You will only get here if errorlevel is 0<br/>if %batch_query% gtr 0 goto laststep<br/><br/>REM If you get here errorlevel is 0 and batch_query is 0<br/>REM What are you going to do?<br/>REM Maybe goto end?<br/>REM If you do nothing you will go to the next line.<br/>REM Which is laststep...<br/><br/>:laststep<br/>REM Your code<br/>goto end<br/><br/>:error1<br/>REM your code<br/><br/>:end<br/><br/><br/>Also... in your code...<br/><br/> Code: <a>[Select]</a>echo %JOBNAME% Abended<br/>REM THERE WAS AN ERROR!<br/>SET CONTROLM=1<br/>goto END<br/><br/><br/>:END<br/>1. The goto END statement is superfluous, because you are going there anyway.<br/><br/>2. "Abended" is not an <a href="https://interviewquestions.tuteehub.com/tag/english-273" style="font-weight:bold;" target="_blank" title="Click to know more about ENGLISH">ENGLISH</a> word.<br/><br/><br/><br/>Thanks for all your replies.I'll try these.I have always found life easier if a script commences<br/>ECHO OFF<br/>or even<br/>ECHO OFF<br/><br/>I rather doubt that there is any benefit from starting with<br/>ECHO ON<br/><br/>Alan<br/></body></html> | |
266. |
Solve : can a *.bat answer prompted the questions automatically for a program?? |
Answer» <html><body><p>I'm trying to make a batch file that will answer prompted questions automatically for a program. I need to click "next" 4 times and click "enter". Quote from: DaveIsRacerX on September 17, 2010, 07:42:21 PM</p><blockquote>I'm trying to make a batch file that will answer prompted questions automatically for a program. I need to click "next" 4 times and click "enter". <br/></blockquote> Batch operates with a <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a> <a href="https://interviewquestions.tuteehub.com/tag/line-239358" style="font-weight:bold;" target="_blank" title="Click to know more about LINE">LINE</a> Interface. There is no way to click things with just batch. You will probably be able to <a href="https://interviewquestions.tuteehub.com/tag/accomplish-846960" style="font-weight:bold;" target="_blank" title="Click to know more about ACCOMPLISH">ACCOMPLISH</a> this with VBS, but not batch. Quote from: DaveIsRacerX on September 17, 2010, 07:42:21 PM<blockquote>I'm trying to make a batch file that will answer prompted questions automatically for a program. I need to click "next" 4 times and click "enter". <br/></blockquote> <br/>Clicking "next" and "enter" sounds like you're <a href="https://interviewquestions.tuteehub.com/tag/dealing-2566191" style="font-weight:bold;" target="_blank" title="Click to know more about DEALING">DEALING</a> with a GUI. Batch language barely knows Windows exists much less interacting with it. It is possible to create a response file for a command line program using redirection.<br/><br/>For a Windows program you can use VBScript and program the keys (no mouse movements) needed to accomplish the task. There is a discussion of this going on in this thread. Check it out.<br/><br/>Good luck.</body></html> | |
267. |
Solve : What values does the IF command compare?? |
Answer» <html><body><p>Win XP Home. Batch script.<br/><br/>Newbie.<br/><br/>Does the If command <a href="https://interviewquestions.tuteehub.com/tag/compare-11929" style="font-weight:bold;" target="_blank" title="Click to know more about COMPARE">COMPARE</a> the ASCII decimal value when comparing strings? If so why does the following return True when the ASCII values would show that the return should be False?<br/><br/>Thanks<br/><br/> Code: <a>[<a href="https://interviewquestions.tuteehub.com/tag/select-630282" style="font-weight:bold;" target="_blank" title="Click to know more about SELECT">SELECT</a>]</a>echo off<br/>cls<br/><br/>if "2" gtr ";" echo 2 is greater than ;<br/>The cmd.exe IF <a href="https://interviewquestions.tuteehub.com/tag/test-13460" style="font-weight:bold;" target="_blank" title="Click to know more about TEST">TEST</a> does not do a plain ASCII comparison. Numerals come before letters; letters are normalized to lower case. For example 4 has a lower character value than 6, so 49 is <a href="https://interviewquestions.tuteehub.com/tag/less-536996" style="font-weight:bold;" target="_blank" title="Click to know more about LESS">LESS</a> than 6.1 when compared as strings; ',' is less than ';', etc. <a href="https://interviewquestions.tuteehub.com/tag/according-366619" style="font-weight:bold;" target="_blank" title="Click to know more about ACCORDING">ACCORDING</a> to the byte value of the characters. <br/></p></body></html> | |
268. |
Solve : Student stuck with batch files taht will not work, HELP? |
Answer» <html><body><p>I have created several <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> programs and saved them in a directory, updated my search <a href="https://interviewquestions.tuteehub.com/tag/path-11833" style="font-weight:bold;" target="_blank" title="Click to know more about PATH">PATH</a> to include directory, and whenever i am in a different directory, the batch files do not <a href="https://interviewquestions.tuteehub.com/tag/work-20377" style="font-weight:bold;" target="_blank" title="Click to know more about WORK">WORK</a>, why?1. What do you mean they "don't work"? Do you mean you cannot start them by typing the batch name, or that you can start them but they don't work in the <a href="https://interviewquestions.tuteehub.com/tag/way-246442" style="font-weight:bold;" target="_blank" title="Click to know more about WAY">WAY</a> that you want them to? <br/>2. What is this "search path"?<br/>3. How did you "update" it?<br/>If your talking about updating the PATH variable to include the directory with your batch files and after doing so, not being able to access the batch files, then. . .<br/><br/>You need to <a href="https://interviewquestions.tuteehub.com/tag/restart-622780" style="font-weight:bold;" target="_blank" title="Click to know more about RESTART">RESTART</a> the comp.</p></body></html> | |
269. |
Solve : ftp commands? |
Answer» <html><body><p>Hi all,<br/><br/>I'm cracking my head with a small and simple thing, that unfortunately seems out of reach for my head...<br/>I need to transfer files from a ftp server to my computer in a automatic way. The problem is that the <a href="https://interviewquestions.tuteehub.com/tag/folder-246959" style="font-weight:bold;" target="_blank" title="Click to know more about FOLDER">FOLDER</a> in the ftp, were these files are, acts as a backup as well, having files with 3 weeks <a href="https://interviewquestions.tuteehub.com/tag/old-585313" style="font-weight:bold;" target="_blank" title="Click to know more about OLD">OLD</a>. Is there a way of <a href="https://interviewquestions.tuteehub.com/tag/sorting-11834" style="font-weight:bold;" target="_blank" title="Click to know more about SORTING">SORTING</a> the files by date, and just download these ones instead of everything? <br/><br/>Thanks in advance<br/><br/>Regardsthe windows ftp client that came with <a href="https://interviewquestions.tuteehub.com/tag/installation-16361" style="font-weight:bold;" target="_blank" title="Click to know more about INSTALLATION">INSTALLATION</a> is primitive. Instead, use a programming language, eg Python (or any others) that provides you FTP libraries for file transfer. eg in Python<br/> Code: <a>[Select]</a>import ftplib<br/>server="localhost"<br/>user="anonymous"<br/>password="<a href="/cdn-cgi/l/email-protection">[email protected]</a>"<br/>filelist=[]<br/><a href="https://interviewquestions.tuteehub.com/tag/def-431442" style="font-weight:bold;" target="_blank" title="Click to know more about DEF">DEF</a> download(ftp, filename):<br/> ftp.retrbinary("RETR " + filename, open(filename,"wb").write)<br/>try:<br/> ftp = ftplib.FTP()<br/> ftp.debug(3)<br/> ftp.connect(server,21)<br/> ftp.login(user,password)<br/>except Exception,e:<br/> print e<br/>else:<br/> ftp.cwd("directory to change if any")<br/> ftp.retrlines('LIST',filelist.append)<br/> for latest in filelist:<br/> if latest.startswith("-") and "latest file pattern if any" in latest:<br/> print latest<br/> download(ftp,latest)<br/> ftp.quit()<br/>sys.exit()<br/><br/>this assumes that your old files are named in a distinct format, such as file.bak or something, and your latest file is not in that format.<br/><br/>usage:<br/> Code: <a>[Select]</a>C:\test> python myscript.py<br/></p></body></html> | |
270. |
Solve : ms dos computer has 2 lost allocation units? |
Answer» <html><body><p>Hello,<br/><br/>I need help. When I start computer and it starts it setup it stops and has 2 LOST ALLOCATION <a href="https://interviewquestions.tuteehub.com/tag/units-239517" style="font-weight:bold;" target="_blank" title="Click to know more about UNITS">UNITS</a> FOUND 1 CHANINS.<br/>CONVERT LOST CHANINS TO FILES Y-N, so here is where I should be <a href="https://interviewquestions.tuteehub.com/tag/able-361137" style="font-weight:bold;" target="_blank" title="Click to know more about ABLE">ABLE</a> to type and I can't. It will not let me do anything, so I restart computer and hit the key to go to the amibios simple setup utility(ver 1.19), but can't find anywhere in setup to <a href="https://interviewquestions.tuteehub.com/tag/run-1192138" style="font-weight:bold;" target="_blank" title="Click to know more about RUN">RUN</a> the -CHKDSK- for fix my <a href="https://interviewquestions.tuteehub.com/tag/problem-25530" style="font-weight:bold;" target="_blank" title="Click to know more about PROBLEM">PROBLEM</a>. I have read in many places on the web that this will fix computer, but can't get to a C: or a CHKDSK file. <br/>Any ideas would be amazing! Thanks you Quote</p><blockquote>so here is where I should be able to type and I can't. It will not let me do anything, so I restart computer</blockquote> <br/>Is it a USB keyboard. Sometimes you have to go into the BIOS and enable Legacy USB for it to work.Yes, I do have a USB keyboard, will try. Thank you, I am running a PC DOS, don't know if it <a href="https://interviewquestions.tuteehub.com/tag/makes-248623" style="font-weight:bold;" target="_blank" title="Click to know more about MAKES">MAKES</a> any difference.Sounds like System files are corrupted. You'll have to boot to a Boot Disk and reinstall system files.<br/>Get the version you need from here: <a href="http://www.bootdisk.com">www.bootdisk.com</a><br/>Boot to the floppy disk or CD. <br/>Then type: <strong>sys c:</strong><br/>Hit return.<br/>Remove boot disk and restart computer.</body></html> | |
271. |
Solve : File name problem...? |
Answer» <html><body><p>I have a batch file "Test.bat":<br/> Code: <a>[Select]</a>echo on<br/>msg * This is a test.<br/>del Test.bat<br/>pause<br/><br/>Well this script looks fine but if i change the file name "Test.bat" to "Testing.bat" (Not the name in script).<br/>The script seems not to work. The error is:<br/>Del Test.bat<br/>Could Not Find C:\Test.bat<br/><br/>I need a script that can detect its own file name.<br/>Could anyone help me find a way out of this problem?As long has you have not used the SHIFT command, then<br/>%~f0<br/>refers to the fully qualified name of the batch file<br/>Thats a zero at the end btwI am sure a script can detect itself,<br/>and can even copy itself,<br/>but I would expect the O.S. to <a href="https://interviewquestions.tuteehub.com/tag/consider-2017521" style="font-weight:bold;" target="_blank" title="Click to know more about CONSIDER">CONSIDER</a> the file in use if it tried to move or delete itself.<br/><br/>Alan<br/>It is certainly possible for a batch file to delete or rename itself, but there will be an error message when cmd.exe comes back from carrying out the del or ren command to find the script gone or renamed.<br/><br/>consider...<br/><br/> Code: <a>[Select]</a>C:\>echo del %~f0>test.bat<br/><br/>C:\>test.bat<br/><br/>C:\>del test.bat<br/>The batch file cannot be found.<br/>and...<br/><br/> Code: <a>[Select]</a>C:\>echo ren %~f0 test1.bat>test.bat<br/><br/>C:\>test.bat<br/><br/>C:\>ren test.bat test1.bat<br/>The batch file cannot be found.<br/><br/><br/><br/> Quote from: ALAN_BR on September 24, 2010, 02:08:19 PM</p><blockquote>I am sure a script can detect itself,<br/>and can even copy itself,<br/>but I would expect the O.S. to consider the file in use if it tried to move or delete itself.<br/><br/>Alan<br/><br/></blockquote> <br/>Simply opening a file doesn't constitute "in-use".<br/><br/>The call to CreateFile() would need to explicitly lock the file, by not specifying any of the FILE_SHARE_X flags.<br/><br/>For example, if the CreateFile() is passed FILE_SHARE_READ, other programs can open the file for reading, but cannot write to the file or open it with write flags, or delete the file. FILE_SHARE_WRITE will allow programs to write to the file but not read or delete it, and FILE_SHARE_DELETE will allow the file to be deleted.<br/><br/><a href="https://blogs.msdn.com/b/larryosterman/archive/2004/05/13/131263.aspx">Larry Osterman</a> writes about this, and although he doesn't explicitly note anything to do with batch files there is an implication there; he notes that by default, DOS applications would open files in a manner so that any other program could access them, because of the single-tasking nature of DOS nobody considered this to be a problem. Therefore it's safe to assume that CMD.EXE opens batch files in the same mode that command.com does- that is, in a mode whereby the file is free to be changed (FILE_SHARE_WRITE+FILE_SHARE_READ+FILE_SHARE_DELETE). <br/><br/>He also mentions that the NT Loader will open Executables with the FILE_SHARE_DELETE flag; this means that the file cannot be opened for READ or WRITE access by any program. additional invocations of the executable don't cause a problem, because the loader simply uses the same Mapped View of the executable file that it created the first time around. <br/><br/>It's not as cut-and-dried as "if the file is open, no other program can access it".<br/><br/>Wether that is truly the case for cmd, I don't know. It's entirely possible it opens the batch file, reads the next line, and then closes it, too.Sorry, you are right and I was wrong.<br/><br/>I was remembering past experiences before CMD.EXE and before Windows 98,<br/>possibly back in the days of DOS v3.?,<br/>and I learnt then to expect grief from a *.BAT script if it tried to alter itself.<br/>I assumed the same was true now.<br/><br/>My more recent experience with XP is that the O.S. may complain that a file is in use when I try to delete it,<br/>so I thought my old memories still applied.<br/><br/>Sorry<br/><br/>Regards<br/>Alan<br/> Quote from: ALAN_BR on September 25, 2010, 02:03:18 AM<blockquote>I was remembering past experiences before CMD.EXE and before Windows 98,<br/>possibly back in the days of DOS v3.?,<br/>and I learnt then to expect grief from a *.BAT script if it tried to alter itself.<br/>I assumed the same was true now.<br/><br/>My more recent experience with XP is that the O.S. may complain that a file is in use when I try to delete it,<br/>so I thought my old memories still applied.<br/><br/>Sorry<br/><br/>Regards<br/>Alan<br/></blockquote> <br/>Alan, this is just my 2 (euro) cents <a href="https://interviewquestions.tuteehub.com/tag/worth-1461684" style="font-weight:bold;" target="_blank" title="Click to know more about WORTH">WORTH</a>, but I don't really think you have any reason to apologise or say 'sorry' to anybody over this. You may have been inaccurate to say that a batch script is prevented from modifying or deleting itself, but you are certainly correct in your recollection that writing self-modifying code can be a risky business. A script that cuts the legs from under itself can lurch to <a href="https://interviewquestions.tuteehub.com/tag/destruction-949662" style="font-weight:bold;" target="_blank" title="Click to know more about DESTRUCTION">DESTRUCTION</a>. Having said that, self-modification is not always a bad thing. There is a good summary here<br/><br/><a href="https://en.wikipedia.org/wiki/Self-modifying_code">http://en.wikipedia.org/wiki/Self-modifying_code</a><br/><br/>As Wikipedia notes, "Because of the security implications of self-modifying code, all of the major operating systems are careful to remove such vulnerabilities as they become known. The concern is typically not that programs will intentionally modify themselves, but that they could be maliciously changed by an exploit." and "Self-modifying code is also sometimes used by programs that do not want to reveal their presence — such as computer viruses and some shellcodes. Viruses and shellcodes that use self-modifying code mostly do this in combination with polymorphic code. Modifying a piece of running code is also used in certain attacks, such as buffer overflows."<br/><br/>In this regard, I am curious about the intentions of the OP.<br/><br/><br/><br/><br/><br/><br/>Thank you Salmon<br/><br/>I remember the good old days when an anti-virus was pleased with itself if it could find and delete a suspect batch file.<br/>The I.T. department chose one that excelled in deleting any batch file that had the command FORMAT C:\<br/><br/>I had problems with self modifying code.<br/>I created a batch file called CD#.bat which <a href="https://interviewquestions.tuteehub.com/tag/looked-1733988" style="font-weight:bold;" target="_blank" title="Click to know more about LOOKED">LOOKED</a> for arguments,<br/>and in the absence of arguments would skip to the end and execute the final line,<br/>which was something like<br/>CD C:\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\<br/>If it was given the argument '#' it would alter the final line to aim at whatever the current path was,<br/>and the next day I immediately returned to yesterday's weird and wonderful directory with<br/>CD#<br/>Typically the new path was one extra 'z\'<br/>I tried to design self modifying code but failed.<br/>I finished with a "template" which CD#.bat duplicated as CD#.TMP<br/>The template was identical to CD#.BAT excepting the final line was "CD " without any CRLF or CtrlZ,<br/>then CD#.bat invoked<br/>CD >> CD#.TMP<br/>Then CD#.BAT deleted itself and renamed CD#.TMP as CD#.BAT<br/>That at least was the result I wanted, but achieving the result involved the use of intermediate scripts.<br/><br/>The purpose of C:\z\z\z\z\z\z\z etc was that the first z\ held the first stage of a software product,<br/>and successive z\ held the previous plus a new feature,<br/>and the final z\ held the final product with all features.<br/>If a feature was found to be broken it was easy to test its operation at each z\ to identify what broke it and then fix it.<br/>This was when CVS etc version control was not available, and every man had to "roll his own".<br/><br/>I remember the aggravation when the I.T. dept changed to an anti-virus which deleted my master template.<br/>It assumed that any *.BAT was up to no good and had to be deleted if it had a final command without a terminating CRLF<br/><br/>I remember the wonderful feeling of revenge when the IT department went round one night with a FAST application to detect any unlicensed software,<br/>and the FAST application choked when it <a href="https://interviewquestions.tuteehub.com/tag/encountered-446037" style="font-weight:bold;" target="_blank" title="Click to know more about ENCOUNTERED">ENCOUNTERED</a> my path with 80 or more 'z\' in a line.<br/>(I forget what the character length was for a command.com command, but I took my path up to the limit)<br/>This is a memory worth keeping ! !<br/><br/>Regards<br/>Alan<br/></body></html> | |
272. |
Solve : Batch File, moves only jpg? |
Answer» <html><body><p>Hello all. <br/>Been <a href="https://interviewquestions.tuteehub.com/tag/coming-922990" style="font-weight:bold;" target="_blank" title="Click to know more about COMING">COMING</a> to this site for <a href="https://interviewquestions.tuteehub.com/tag/years-239545" style="font-weight:bold;" target="_blank" title="Click to know more about YEARS">YEARS</a> for answers.<br/><br/>I do a lot of 4chan surfing an even have an auto download tool (beware it <a href="https://interviewquestions.tuteehub.com/tag/cares-244056" style="font-weight:bold;" target="_blank" title="Click to know more about CARES">CARES</a> less what it grabs lol)<br/><br/>so I have alot of mix file types I'd like a bat to send to their own folders. <br/>I'm using win7 (netbook) <br/><br/>I thought this would work for sure<br/><br/>echo on<br/>move *.JPG C:\Users\******\Documents\Batch Testing 2\File Sort testing<br/>pause<br/><br/>I'm getting " Cannot move multiple files to a single file "<br/><br/>I had a <a href="https://interviewquestions.tuteehub.com/tag/feeling-986094" style="font-weight:bold;" target="_blank" title="Click to know more about FEELING">FEELING</a> to try another drive so I plugged my flashdrive in an it worked fine.<br/><br/>does the C drive stop such ?<br/>Try This<br/><br/><br/>move *.JPG C:\Users\******\Documents\"Batch Testing 2"\"File Sort testing"\*.* Quote</p><blockquote>C:\Users\******\Documents\Batch Testing 2\File Sort testing</blockquote> <br/>Does this folder actually exist?<br/> Quote from: Salmon Trout on September 23, 2010, 03:44:25 PM<blockquote>Does this folder actually exist?<br/><br/></blockquote> <br/>Yeah, the ***** is my name so I did that <br/><br/> Quote from: mat123 on September 23, 2010, 03:22:01 PM<blockquote>Try This<br/><br/><br/>move *.JPG C:\Users\******\Documents\"Batch Testing 2"\"File Sort testing"\*.*<br/></blockquote> nope. got this <br/><br/>C:\Users\******\Documents\Batch Testing 2\File Sort testing>move *.JPG C:\<br/>Users\*******\Documents\"Batch Testing 2"\"File Sort testing"\*.*<br/>The syntax of the command is incorrect.<br/><br/>C:\******\Documents\Batch Testing 2\File Sort testing>pause<br/>Press any key to continue . . .The quotes need to go around the whole path<br/><br/> Code: <a>[<a href="https://interviewquestions.tuteehub.com/tag/select-630282" style="font-weight:bold;" target="_blank" title="Click to know more about SELECT">SELECT</a>]</a>move *.JPG "C:\Users\******\Documents\Batch Testing 2\File Sort testing"<br/>this should do it<br/>Graham Quote from: gpl on September 24, 2010, 12:32:52 AM<blockquote>The quotes need to go around the whole path<br/><br/> Code: <a>[Select]</a>move *.JPG "C:\Users\******\Documents\Batch Testing 2\File Sort testing"<br/>this should do it<br/>Graham<br/></blockquote> <br/>Success <br/>When I was added the path for the source it " syntax of the command is incorrect."<br/>however when I ran it in the source folder it works fine.</body></html> | |
273. |
Solve : secure problem in ftp? |
Answer» <html><body><p>Hello <a href="https://interviewquestions.tuteehub.com/tag/everybody-245583" style="font-weight:bold;" target="_blank" title="Click to know more about EVERYBODY">EVERYBODY</a>,<br/><br/>I need your help. I have created a batch file that I make ftp to my server and I transfer some files, <a href="https://interviewquestions.tuteehub.com/tag/one-241053" style="font-weight:bold;" target="_blank" title="Click to know more about ONE">ONE</a> time per month. I have scheduled this batch using the scheduled tasks of windows xp. The script works fine but I have a secure problem. The <a href="https://interviewquestions.tuteehub.com/tag/password-597077" style="font-weight:bold;" target="_blank" title="Click to know more about PASSWORD">PASSWORD</a> is visible!! <br/><br/>I give to you the commands that I use:<br/><br/>FTP -s:ftpwlk.txt env.meteo.noa.gr<br/><br/>this command open a txt file that contains the following details<br/><br/>"username"<br/>"password"<br/>binary<br/>prompt n<br/>cd stations/seli<br/>mput <a href="https://interviewquestions.tuteehub.com/tag/c-3540" style="font-weight:bold;" target="_blank" title="Click to know more about C">C</a>:\transfer.wlk\*.*<br/>quit<br/><br/>There is any way to keep the password <a href="https://interviewquestions.tuteehub.com/tag/invisible-499587" style="font-weight:bold;" target="_blank" title="Click to know more about INVISIBLE">INVISIBLE</a>?You could get your batch to prompt for the password, or protect the directory that the batch executes from so that only you can see itnowadays the secure way to transfer files is through SSH protocol. Try using SFTP/SCP for file transfer. You can set up passwordless keys so you don't have to hard code any password in your batch files.</p></body></html> | |
274. |
Solve : QBasic Help!? |
Answer» <html><body><p>I needed help with a question for my class, QBasic Programming. This is the question.<br/><br/>If you have the book its on page 118 number 4<br/><br/>4. Write a program to <a href="https://interviewquestions.tuteehub.com/tag/list-11333" style="font-weight:bold;" target="_blank" title="Click to know more about LIST">LIST</a> several <a href="https://interviewquestions.tuteehub.com/tag/activities-238494" style="font-weight:bold;" target="_blank" title="Click to know more about ACTIVITIES">ACTIVITIES</a> and the number of calories expended during <a href="https://interviewquestions.tuteehub.com/tag/15-237501" style="font-weight:bold;" target="_blank" title="Click to know more about 15">15</a>, 30, and 60 minutes of each activity. Use the following Data:<br/><br/>Activity Calories Burned per Minute<br/>Sleeping 2.3<br/>Jogging 15.0<br/>Sitting 1.7<br/><br/>Use READ and DATA statements to place the data in variables. Then use commas to space the output so that is looks similar to the following:<br/><br/>Activity 15 Minutes 30 Minutes 60 Minutes<br/>Sleeping xxx.xx xxx.xx xxx.xx<br/>Jogging xxx.xx xxx.xx xxx.xx<br/>Sitting xxx.xx xxx.xx xxx.xxwow, didn't know anyone would still <a href="https://interviewquestions.tuteehub.com/tag/want-1448756" style="font-weight:bold;" target="_blank" title="Click to know more about WANT">WANT</a> to learn QBasic. I hope its a free class you are taking, if not, its certainly not worth the school fees you are paying for.well this class i am taking is free and it is just a beginning to comp progQbasic is out of date. Try using a better programming <a href="https://interviewquestions.tuteehub.com/tag/language-246575" style="font-weight:bold;" target="_blank" title="Click to know more about LANGUAGE">LANGUAGE</a> (eg Python), where you can learn about advance data structures like arrays/hashes/collections and much more.<br/><br/> Code: <a>[Select]</a>print "%-15s%-15s%-15s%-15s" %("Activity","15 min","30 min","60 min")<br/>f=open("file")<br/>f.readline() # get first line<br/>for line in f:<br/> act, t=line.rstrip().split()<br/> print "%-15s%-15s%-15s%-15s" %( act,float(t)*15,float(t)*30,float(t)*60 )<br/>f.close()<br/><br/>output<br/><br/> Code: <a>[Select]</a>C:\test>python test.py<br/>Activity 15 min 30 min 60 min<br/>Sleeping 34.5 69.0 138.0<br/>Jogging 225.0 450.0 900.0<br/>Sitting 25.5 51.0 102.0<br/><br/><br/>If you insist on something from M$, try learning vbscript instead. <a href="http://www.network54.com/forum/648955/">www.network54.com/forum/648955/</a></p></body></html> | |
275. |
Solve : Convert Tiff file only if condition applies? |
Answer» <html><body><p>Hello fellow msdos coders, I wish I could do this with python or some other uncluttered language, but it has to be dos... I thank you in advance for any input.<br/><br/>Here's the scenario.<br/><br/>I have a large number of Tiff image files in folders and subfolders, and I need to convert them to a different color profile ONLY if they <a href="https://interviewquestions.tuteehub.com/tag/happen-1015459" style="font-weight:bold;" target="_blank" title="Click to know more about HAPPEN">HAPPEN</a> to be with the 'wrong' profile.<br/><br/>I'm <a href="https://interviewquestions.tuteehub.com/tag/confused-409756" style="font-weight:bold;" target="_blank" title="Click to know more about CONFUSED">CONFUSED</a> as to how the 'for' works, i'd like to get 'secondary' action in my for loop, but can't figure out how<br/><br/> Code: <a>[Select]</a>for /r %%a in (*.tif) do (identify -verbose "%%~<a href="https://interviewquestions.tuteehub.com/tag/fa0-456538" style="font-weight:bold;" target="_blank" title="Click to know more about FA">FA</a>" >> t.txt) <br/><br/>will print some info (using 'imagemagick') and somewhere in there should (or shouldn't) be a line with "<a href="https://interviewquestions.tuteehub.com/tag/adobe-12925" style="font-weight:bold;" target="_blank" title="Click to know more about ADOBE">ADOBE</a> RGB" in it<br/><br/>so I should add<br/><br/> Code: <a>[Select]</a>& if find "Adobe RGB" < (output of the 'identify' above)<br/><br/>or something that looks like it<br/><br/>then according to the result<br/><br/>do this:<br/><br/> Code: <a>[Select]</a>convert -profile AdobeRGB1998.icc -profile sRGB.icm %%a sRGB_%%~na.tif <br/><br/>Which is the only bit that I know works =)<br/><br/>If you can help me stitch the whole thing together, I'll give you a million internet hugs =)<br/><br/>Thanks and have a good day<br/><br/>BernieYou could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert<br/><br/> Code: <a>[Select]</a>for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "sRGB_%%~na.tif" Quote from: Salmon Trout on September 28, 2010, 11:29:06 AM</p><blockquote>You could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert<br/><br/> Code: <a>[Select]</a>for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "sRGB_%%~na.tif" </blockquote> <br/>thanks, it does the trick!Ahah, so I have a little more <a href="https://interviewquestions.tuteehub.com/tag/work-20377" style="font-weight:bold;" target="_blank" title="Click to know more about WORK">WORK</a> on that script, right now it works, but instead of using a prefix, I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop!<br/><br/>Any ideas?<br/><br/> Code: <a>[Select]</a>for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB (1998)" && mkdir "%%~pa/sRGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "%%~pa/sRGB/%%~na.tif"<br/>Copy them into a folder outside the tree being walked by FOR /R, or instead of FOR /R you can use FOR /F to parse the output of 'dir /b /s *.tif', use %%~pa to identify those tifs not in the converted folder, which you convert and move. <br/><br/><br/><br/> Quote<blockquote>I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop!</blockquote> <br/>But don't the converted files have a different profile? How do they get processed twice?</body></html> | |
276. |
Solve : emails with batch files? |
Answer» <html><body><p>i need to send emails with the help of using batch files. how can i send the mails with batch files.Have you tried the search function on this site, I know it has been answered beforeFor use in batch files you can use <a href="https://sourceforge.net/projects/blat/files/">Blat</a> or <a href="http://www.petri.co.il/send_mail_from_script.htm">MailSend</a>.<br/><br/>If you have <a href="https://interviewquestions.tuteehub.com/tag/windows-22662" style="font-weight:bold;" target="_blank" title="Click to know more about WINDOWS">WINDOWS</a>, you can use any of the above or VBScript (already installed) or any other script language you may have downloaded and installed.<br/><br/>If you have Windows 7, you can use any of the above or Powershell (Powershell may have to be activated)<br/><br/>You are limited only by your imagination.<br/><br/>Good luck. I am using mailsend to send out pages to people from a batch file. It should work for what you want to do. Code: <a>[Select]</a>echo off<br/>cd folderexample<br/>for %%* in (.) do set <a href="https://interviewquestions.tuteehub.com/tag/var-11596" style="font-weight:bold;" target="_blank" title="Click to know more about VAR">VAR</a>=%%~n*<br/>for /f %%a in ('time/t') do set vartime=%%a<br/>set body=-body "hello"<br/>set <a href="/cdn-cgi/l/email-protection">[email protected]</a><br/>set <a href="/cdn-cgi/l/email-protection">[email protected]</a><br/>set subj=-s "Test. FTP.%var%. New Files. %vartime%"<br/>set server=-server smtp.example.com<br/>set user=-u userexample<br/>set pass= -pw passwordexample<br/>C:\<a href="https://interviewquestions.tuteehub.com/tag/vishu-727999" style="font-weight:bold;" target="_blank" title="Click to know more about VISHU">VISHU</a> %0 -f %from% -b %to% %subj% %body% %server% %user% %pass%<br/><br/>I hope this will help you.<br/>if do click on thanksthis is what i am using to send alerts. Download the latest version of mailsend and put it in your windows/system32 dir<br/>this is the command. Its all one line but broken up here due to cut and paste. I need to use port 2525 due to my ISP. Change it to whatever works for you. <br/><br/>mailsend -d <em>your domain</em> -smtp <em>your SMTP server</em> -port 2525 -starttls -v -f <em>from address to show on email</em> +<a href="https://interviewquestions.tuteehub.com/tag/cc-251163" style="font-weight:bold;" target="_blank" title="Click to know more about CC">CC</a> +bc -auth-login -user <em>user on SMTP server</em> -pass "<em>user password</em>" -t <em>to:email address </em> -sub "<em>subject</em>" -M "<em><a href="https://interviewquestions.tuteehub.com/tag/message-25597" style="font-weight:bold;" target="_blank" title="Click to know more about MESSAGE">MESSAGE</a></em>"<br/><br/><br/><br/><br/>good luck</p></body></html> | |
277. |
Solve : Returning the date and time on file? |
Answer» <html><body><p>I picked up this <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a> from Salmon Trout from another post. When I look at files on my desktop the date and time are echoed fine. When I <a href="https://interviewquestions.tuteehub.com/tag/try-1428546" style="font-weight:bold;" target="_blank" title="Click to know more about TRY">TRY</a> to look at files on another drive or a server I get no echo at all.<br/><br/>Any thoughts?<br/><br/>echo off<br/>for /f "delims=" %%A in ( 'dir /b /a-d /od c\:docume~1\[username]\desktop\[filename]' ) do (<br/> set fdate=%%~tA<br/> )<br/>echo %fdate%I believe the ~t variable modifier only works on local drives. What <a href="https://interviewquestions.tuteehub.com/tag/happensbrbr-2691586" style="font-weight:bold;" target="_blank" title="Click to know more about HAPPENS">HAPPENS</a> if you try to get a full DIR listing (not using /b) of the folder? I mean this style of listing...<br/><br/> Code: <a>[Select]</a>Volume in drive C is Win07<br/> Volume Serial Number is E4DB-A92A<br/><br/> Directory of C:\<br/><br/>24/09/2010 06:26 PM 1,024 .rnd<br/>19/06/2010 03:16 PM 1,414 backup.log<br/>28/03/2010 10:46 PM 956 dir.txt<br/>06/10/2010 05:35 PM 3,169,705,984 hiberfil.sys<br/>02/01/2010 08:03 PM 57,310 Logon001.jpg<br/>14/03/2010 09:52 PM 1,106 makespecialfolders.bat<br/>03/03/2007 05:44 PM 15,658 mike.jpg<br/>28/03/2010 10:45 PM 870 mike.jpg.lnk<br/>06/10/2010 05:35 PM 314,572,800 pagefile.sys<br/>13/07/2010 06:26 PM 111,562,752 PM11_Pers_full_ea_x64.msi<br/>29/07/2010 10:47 PM 79 whatever.scf<br/> 12 File(s) 3,595,930,401 bytes<br/> 0 Dir(s) 72,403,623,936 bytes freeWhen I get the full listing I have the file names and dates and <a href="https://interviewquestions.tuteehub.com/tag/times-344892" style="font-weight:bold;" target="_blank" title="Click to know more about TIMES">TIMES</a> as you have shown. When I use the /b switch I just get the names. Quote</p><blockquote>When I get the full listing I have the file names and dates and times as you have shown.</blockquote> <br/>If you can show me (by copy and paste) the format of such a listing I can tell you how to extract the date and time information. I need to see this to know the character positions. It looks from your code as if you require the date and time of the last (<a href="https://interviewquestions.tuteehub.com/tag/latest-1069479" style="font-weight:bold;" target="_blank" title="Click to know more about LATEST">LATEST</a>) file in the folder.<br/><br/>Here it is<br/><br/> Volume in drive C has no label.<br/> Volume Serial Number is 984C-4C03<br/><br/> Directory of C:\D_Drive\workspaces\0102\batch\gisdb\wad<br/><br/>10/07/2010 10:39 AM .<br/>10/07/2010 10:39 AM ..<br/>10/28/2009 03:34 PM 193 0102bsav.addr<br/>09/16/2007 03:32 PM 193 0102bsav.bld<br/>08/10/2010 11:30 AM 1,543,341 0102bsav.dbf<br/>08/10/2010 11:30 AM 2 0102bsav.lab<br/>10/28/2009 03:34 PM 193 0102bsav.sub<br/>10/05/2010 08:48 AM 50,684 0102ds.addr<br/>10/28/2009 01:33 PM 288 0102ds.alt<br/>09/16/2007 03:32 PM 193 0102ds.bld<br/>10/06/2010 12:03 PM 1,234,550 0102ds.dbf<br/>10/06/2010 12:03 PM 2 0102ds.lab<br/>10/06/2010 11:40 AM 9,278,082 0102ds.seq<br/>10/01/2010 12:50 PM 19,634 0102ds.sub<br/>10/07/2010 10:39 AM 0 myfile.txt<br/> 13 File(s) 12,127,355 bytes<br/> 2 Dir(s) 10,652,610,560 bytes free Code: <a>[Select]</a><br/>echo off<br/>setlocal enabledelayedexpansion<br/>set dirname="S:\Test"<br/>set dirswitches=/a-d /od<br/>for /f "tokens=1-4* delims= " %%A in ('dir %dirswitches% "%dirname%" ^| findstr /v "File(s) Dir(s) Volume Directory"') do (<br/> set fdate=%%A<br/> set ftime=%%B<br/> set AM-PM=%%C<br/> set fname=%%E<br/> )<br/>echo File date %fdate%<br/>echo File time %ftime% %AM-PM%<br/>echo File name %fname% <br/></body></html> | |
278. |
Solve : User-input in PC-DOS? |
Answer» <html><body><p>Hello. I <a href="https://interviewquestions.tuteehub.com/tag/sometimes-648384" style="font-weight:bold;" target="_blank" title="Click to know more about SOMETIMES">SOMETIMES</a> boot my computer from a live PC-DOS 7.1 CD, but I've noticed that I can't <a href="https://interviewquestions.tuteehub.com/tag/use-241643" style="font-weight:bold;" target="_blank" title="Click to know more about USE">USE</a> 'SET /P' to take input from the user. When I <a href="https://interviewquestions.tuteehub.com/tag/try-1428546" style="font-weight:bold;" target="_blank" title="Click to know more about TRY">TRY</a> using 'CHOICE' it just says "Bad command or file name.' How can I do this?<br/><br/>Please <a href="https://interviewquestions.tuteehub.com/tag/help-239643" style="font-weight:bold;" target="_blank" title="Click to know more about HELP">HELP</a>!<br/>Thanks,<br/>phillid</p></body></html> | |
279. |
Solve : ethernet ipaddress keeps changing and won't let me on internet? |
Answer» <html><body><p>RIght now I am using wireless on my WIndows XP. THis started happening recently when I switched over to RR cable from dial-up. THis is a 3 yr <a href="https://interviewquestions.tuteehub.com/tag/old-585313" style="font-weight:bold;" target="_blank" title="Click to know more about OLD">OLD</a> Toshiba laptop. I have spent the last 4 weeks dealing with techs from both companies(RR & Toshiba) and the problem is still erratic. Sometimes it works and sometimes it doesn't. I have done all of their suggestions like going thru the ipconfig---release---and renew stuff. I went thru the one of taking out the battery, shutting it off, pushing the off swicth for 15 seconds waiting and putting it all back together. I tried a different Ethernet cord and it worked for about three days. I also did the RR thing of disconnecting the laptop power source/modem and turning it back on after counting the required number of seconds. I was about to try black magic when I ran across this site (I was learning about external commands). Retirement sucks when I cannot use my internet. Help. Please.Road Runner, not so beep beep? <br/><br/>Does the RR cable run through the telephone exchange?<br/>I assume the 'modem' is actually a wired router?<br/><br/>I <a href="https://interviewquestions.tuteehub.com/tag/suggest-1733190" style="font-weight:bold;" target="_blank" title="Click to know more about SUGGEST">SUGGEST</a> first looking under your router admin gateway. <br/>To go to that your'll need to type '//' (without quotes) and the router's IP address in your web-browser and enter your admin details. Read the manual that came with the router if stuck.<br/><br/>Under connection details, you should see 'Uptime', 'Bandwidth (Up/Down)', etc...<br/><br/>Find 'Line Attenuation (Up/Down)' and 'SN Margin', ensure the [dB] doesn't change a lot when refreshing that page. <br/><br/>You might also want to check:<br/>Loss of Signal / Power (Local/Remote)<br/>FEC, CRC, and HEC Errors (Up/Down)<br/><br/>Depending on your router model, they should be all on the same page. Post the results here if possible and note any continous changes on refreshing that page.<br/><br/><br/>If you have a noisy line, another way of testing this is pick up the phone and dial just one number to clear the dial tone and <a href="https://interviewquestions.tuteehub.com/tag/listen-1075634" style="font-weight:bold;" target="_blank" title="Click to know more about LISTEN">LISTEN</a> for <a href="https://interviewquestions.tuteehub.com/tag/static-344918" style="font-weight:bold;" target="_blank" title="Click to know more about STATIC">STATIC</a> or noise. Noise on the line hugely decreases internet performancee and it get's too much, the line will cut and attempt to reconnect with another IP address. This might be your issue?</p></body></html> | |
280. |
Solve : mass rename in MS-DOS? |
Answer» <html><body><br/>I have files existing with same names in the folders with date as display below<br/><br/> Code: <a>[Select]</a><br/><br/><a href="https://interviewquestions.tuteehub.com/tag/c-3540" style="font-weight:bold;" target="_blank" title="Click to know more about C">C</a>:\2010-09-10 <==== folder<br/> arr1.jpg<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/><br/>c:\2010-09-09 <==== folder<br/> arr1.jpg<br/> arr2.jpg<br/><br/>c:\2010-09-08 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/> arr5.jpg<br/> arr8.jpg<br/> arr9.jpg<br/> arr10.jpg<br/> arr11.jpg<br/><br/> c:\2010-09-07 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/> arr10.jpg<br/> arr11.jpg<br/><br/>c:\2010-09-06 <==== folder<br/> arr9.jpg<br/> arr10.jpg<br/> arr11.jpg<br/><br/>c:\2010-09-05 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/> arr5.jpg<br/> arr6.jpg<br/> arr7.jpg<br/> arr8.jpg<br/><br/>c:\2010-09-04 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr5.jpg<br/> arr6.jpg<br/> arr7.jpg<br/> arr8.jpg<br/> arr9.jpg<br/> arr10.jpg<br/> arr11.jpg<br/><br/>c:\2010-09-03 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/> arr5.jpg<br/> arr6.jpg<br/> arr7.jpg<br/> arr10.jpg<br/> arr11.jpg<br/><br/>c:\2010-09-02 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/> arr5.jpg<br/> arr6.jpg<br/> arr7.jpg<br/> arr8.jpg<br/> arr11.jpg<br/><br/>c:\2010-09-01 <==== folder<br/> arr2.jpg<br/> arr3.jpg<br/> arr4.jpg<br/><br/><br/><br/>I would like to rename those files as _.jpg. and move all the files in single folder <a href="https://interviewquestions.tuteehub.com/tag/called-907796" style="font-weight:bold;" target="_blank" title="Click to know more about CALLED">CALLED</a> All_pics<br/>The SrNo is a continous running number serial number. <br/><br/> Code: <a>[Select]</a>C:\All_pics\<br/> 2010-09-10_54.jpg <br/> 2010-09-10_55.jpg <br/> 2010-09-10_56.jpg <br/> 2010-09-10_57.jpg <br/> <br/> 2010-09-09_52.jpg <br/> 2010-09-09_53.jpg <br/> 2010-09-08_44.jpg <br/> <br/> 2010-09-08_45.jpg <br/> 2010-09-08_46.jpg <br/> 2010-09-08_47.jpg <br/> 2010-09-08_48.jpg <br/> 2010-09-08_49.jpg <br/> 2010-09-08_50.jpg <br/> 2010-09-08_51.jpg <br/> <br/> 2010-09-07_39.jpg <br/> 2010-09-07_40.jpg <br/> 2010-09-07_41.jpg <br/> 2010-09-07_42.jpg <br/> 2010-09-07_43.jpg <br/> <br/> 2010-09-06_36.jpg <br/> 2010-09-06_37.jpg <br/> 2010-09-06_38.jpg <br/> 2010-09-05_29.jpg <br/> 2010-09-05_30.jpg <br/> 2010-09-05_31.jpg <br/> 2010-09-05_32.jpg <br/> 2010-09-05_33.jpg <br/> 2010-09-05_34.jpg <br/> 2010-09-05_35.jpg <br/> <br/> 2010-09-04_20.jpg <br/> 2010-09-04_21.jpg <br/> 2010-09-04_22.jpg <br/> 2010-09-04_23.jpg <br/> 2010-09-04_24.jpg <br/> 2010-09-04_25.jpg <br/> 2010-09-04_26.jpg <br/> 2010-09-04_27.jpg <br/> 2010-09-04_28.jpg <br/> <br/> 2010-09-03_12.jpg <br/> 2010-09-03_13.jpg <br/> 2010-09-03_14.jpg <br/> 2010-09-03_15.jpg <br/> 2010-09-03_16.jpg <br/> 2010-09-03_17.jpg <br/> 2010-09-03_18.jpg <br/> 2010-09-03_19.jpg <br/> <br/> 2010-09-02_04.jpg <br/> 2010-09-02_05.jpg <br/> 2010-09-02_06.jpg <br/> 2010-09-02_07.jpg <br/> 2010-09-02_08.jpg <br/> 2010-09-02_09.jpg <br/> 2010-09-02_10.jpg <br/> 2010-09-02_11.jpg <br/> <br/> 2010-09-01_01.jpg <br/> 2010-09-01_02.jpg <br/> 2010-09-01_03.jpg <br/><br/> Which version of MS-DOS are you running? Advice given may alter with the version.<br/><br/>However, if you mean the Command Shell in Windows try the following:<br/><br/> Code: <a>[Select]</a><a href="https://interviewquestions.tuteehub.com/tag/echo-11626" style="font-weight:bold;" target="_blank" title="Click to know more about ECHO">ECHO</a> off<br/>cls<br/>setlocal enabledelayedexpansion<br/><br/>echo y | del all-pics\*.*>nul<br/><br/>set nbr=1<br/>if not exist all-pics\ md all-pics\<br/><br/>for /<a href="https://interviewquestions.tuteehub.com/tag/f-236701" style="font-weight:bold;" target="_blank" title="Click to know more about F">F</a> "tokens=*" %%1 in ('dir /ad /b 2010*') do (<br/> set folder=%%1<br/><br/> for /f "tokens=*" %%A in ('dir /b "!folder!"') do (<br/> if !nbr! <a href="https://interviewquestions.tuteehub.com/tag/lss-537887" style="font-weight:bold;" target="_blank" title="Click to know more about LSS">LSS</a> 10 set nbr=0!nbr!<br/> copy !folder!\%%A all-pics\!folder!_!nbr!.jpg>nul<br/> if !nbr! lss 10 set nbr=!nbr:~-1!<br/> set /a nbr+=1<br/> )<br/>)<br/><br/></body></html> | |
281. |
Solve : Variables in For Loops (And If statements)? |
Answer» <html><body><p>It seems Variables I declare within a FOR loops (or if statements) are getting <a href="https://interviewquestions.tuteehub.com/tag/forgotten-7375779" style="font-weight:bold;" target="_blank" title="Click to know more about FORGOTTEN">FORGOTTEN</a> about <a href="https://interviewquestions.tuteehub.com/tag/right-239192" style="font-weight:bold;" target="_blank" title="Click to know more about RIGHT">RIGHT</a> away. The %%A of the FOR head works fine throughout the loop but a simple<br/><br/>SET TEST=%%A<br/><br/>will vanish...<br/><br/>Any idea why?Please show your script.He's deleted his acoount; I expect he found out about <a href="https://interviewquestions.tuteehub.com/tag/delayed-431487" style="font-weight:bold;" target="_blank" title="Click to know more about DELAYED">DELAYED</a> expansion.<br/></p></body></html> | |
282. |
Solve : %PATH% - Environment Looking for a PATH? |
Answer» <html><body><p>Looking for a way to pull a directory out of the <a href="https://interviewquestions.tuteehub.com/tag/path-11833" style="font-weight:bold;" target="_blank" title="Click to know more about PATH">PATH</a> environmental <a href="https://interviewquestions.tuteehub.com/tag/variable-772077" style="font-weight:bold;" target="_blank" title="Click to know more about VARIABLE">VARIABLE</a>. Guess I'm more so looking for the drive letter. I know my path will <a href="https://interviewquestions.tuteehub.com/tag/contain-409810" style="font-weight:bold;" target="_blank" title="Click to know more about CONTAIN">CONTAIN</a> \vision\bin ... I was thinking I could do a FOR loop but I'm just not getting it at midnight. Help is appreciated. <br/><br/> Code: <a>[Select]</a>for /<a href="https://interviewquestions.tuteehub.com/tag/f-236701" style="font-weight:bold;" target="_blank" title="Click to know more about F">F</a> "tokens=1-26 delims=;" %%a in ('echo %PATH% ^ <a href="https://interviewquestions.tuteehub.com/tag/find-11616" style="font-weight:bold;" target="_blank" title="Click to know more about FIND">FIND</a> /I "\vision\bin"') do set direct=%%a<br/>I figured I would use delims=; to separate each path out, but then again maybe that is my problem that when I set <strong>direct</strong> %%a isn't my path? I'm not sure.<br/><br/>Nevermind ... I got something to work. <br/><br/> Code: <a>[Select]</a>ECHO off<br/>setlocal enabledelayedexpansion<br/> for %%G in ("%PATH:;=" "%") do (<br/> echo %%G | find /I "\vision\bin" >nul<br/> if !errorlevel! EQU 0 set direct=%%G<br/> )<br/>setlocal disabledelayedexpansion<br/>if "%direct%"=="" ECHO direct equals nothing & pause<br/>set direct=%direct:"=%<br/>set direct=%direct:~0,9%<br/>echo "%direct%"<br/>Pause</p></body></html> | |
283. |
Solve : Conditional sentence in MS-DOS? |
Answer» <html><body><p>Hi, I'm not an expert in MS-DOS, that's the reason of my question. How could I <a href="https://interviewquestions.tuteehub.com/tag/put-11868" style="font-weight:bold;" target="_blank" title="Click to know more about PUT">PUT</a> a conditional question in a DOS batch?<br/><br/>For example:<br/><br/><strong>Would you like to execute the next process? Y/N</strong><br/><br/>Best regards.several options; the "easiest" is to use pause:<br/><br/> Code: <a>[Select]</a>ECHO OFF<br/>pause To process the next item, press any key. To Cancel, Press Control+Break.<br/><br/>REM etc..<br/><br/>or, use CHOICE:<br/><br/> Code: <a>[Select]</a>ECHO OFF<br/>REM CLEAR DONEXT:<br/>set DONEXT=<br/>:RECHOICE<br/>choice Would you like to execute the next process?<br/>IF ERRORLEVEL==2 GOTO PRESSEDN<br/>IF ERRORLEVEL==1 GOTO PRESSEDY<br/>ECHO Please Enter Y OR N.<br/>GOTO RECHOICE<br/>:PRESSEDN<br/>REM N was pressed in CHOICE.<br/>SET DONEXT=N<br/>GOTO ENDING<br/>:PRESSEDY<br/>REM Y was pressed<br/>SET DONEXT=Y<br/>:ENDING<br/><br/>REM return to caller.<br/><br/><br/>I wrote the second one with the intent that it may be used as "module" <a href="https://interviewquestions.tuteehub.com/tag/sort-238033" style="font-weight:bold;" target="_blank" title="Click to know more about SORT">SORT</a> of of fashion; that is, it may be called from multiple locations in the same batch file. You can of course paste this in if there is only a single location, but otherwise, you would need to make it a new BAT file- say, "DOCHOICE.BAT" or something.<br/><br/>Then, in the main batch, you would simply do:<br/><br/> Code: <a>[Select]</a>REM check if we should execute the next process...<br/>DOCHOICE<br/>if %DONEXT%==Y GOTO GOTONEXT<br/>if %DONEXT%==N GOTO NONEXT<br/><br/>You would of course define the GOTONEXT label to continue the process, and NONEXT to abort the procedure or display a warning like "not all <a href="https://interviewquestions.tuteehub.com/tag/processes-21463" style="font-weight:bold;" target="_blank" title="Click to know more about PROCESSES">PROCESSES</a> run" or whatever, depending on your use case.<br/><br/>You'll note something particularly rare these days, is that I was able to provide a batch that actually used only DOS features, and didn't try to suggest "YOU CAN USE SET /P" or something stupid like that. That sort of annoys me when I see folks asking for help with DOS and then self-proclaimed "Batch masters" coming in with their advice that requires NT extensions. This is especially annoying since the original poster probably doesn't even know about these extensions and therefore will try to follow their advice. I've seen 3 <a href="https://interviewquestions.tuteehub.com/tag/page-25452" style="font-weight:bold;" target="_blank" title="Click to know more about PAGE">PAGE</a> threads here where poor folks are led on a wild-goose chase while the "batch master" tries to figure out why set /p doesn't work.<br/><br/>I'll <a href="https://interviewquestions.tuteehub.com/tag/shut-643388" style="font-weight:bold;" target="_blank" title="Click to know more about SHUT">SHUT</a> up now.Thanks a Lot!</p></body></html> | |
284. |
Solve : How to copy files to two words name folder? |
Answer» <html><body><p>Problem is:<br/> when I tried to copy files to c:/Program Files/Folder. got the error message as<br/><em>E:\SomeDirectory\Patches>copy *.* C:\Program Files\Destination\<br/>The syntax of the <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a> is incorrect.</em><br/><a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a>:<br/> Code: <a>[Select]</a>cd E:\SomeDirectory\Patches<br/>copy *.* %VALUE%I believe it because of space between Program Files.<br/>In to the other destination all files were copied ok.<br/>How can I solve this problem?I found it!<br/>If you using path to <a href="https://interviewquestions.tuteehub.com/tag/two-241629" style="font-weight:bold;" target="_blank" title="Click to know more about TWO">TWO</a> word name folder just put it between " " <br/>In my case it looks like <br/> Code: <a>[Select]</a>"C:\Program Files\iWay60\"</p></body></html> | |
285. |
Solve : Getting duration of .wmv files using: dir >filelist.txt? |
Answer» <html><body><p>Hi there, <br/><br/>I can see the "duration" (length of the video) for each of our .wmv files in windows explorer by turning on that column, but can't find how to <a href="https://interviewquestions.tuteehub.com/tag/get-11812" style="font-weight:bold;" target="_blank" title="Click to know more about GET">GET</a> that into a text file. We have hundreds and hundreds of files that we need the duration for, and obviously we don't want to have to type it all in by hand when the information is displayed right there in front of us. <br/><br/>I've tried .js as well, but am stumped. My .bat file currently looks like this:<br/><br/>dir /n /a /-p /o:gen >filelisting.txt <br/><br/>This allows me to capture most of the information I need and port it over to our database, but lacks the duration info. <br/><br/>Note that I did come across something called "verbose" (/v) that is supposed to list more information, but the batch file fails when I add it in, and I'm not even sure that would show the duration.<br/><br/>Help? The information you see in Windows Explorer about multimedia files (duration, bitrate, etc) is not available to the command prompt, certainly not via DIR. There is no /V switch for DIR.<br/><br/>But you can use <strong>ffmpeg</strong> to provide multimedia information, and <strong>find</strong> to isolate the line with the duration information. <br/><br/><a href="https://www.ffmpeg.org/">http://www.ffmpeg.org/</a><br/><br/>Example 1. Use ffmpeg with the -i option to get information about a file<br/><br/> Code: <a>[Select]</a>C:\Users\Public\<a href="https://interviewquestions.tuteehub.com/tag/videos-25654" style="font-weight:bold;" target="_blank" title="Click to know more about VIDEOS">VIDEOS</a>\Sample Videos>ffmpeg -i wildlife.wmv<br/>FFmpeg version SVN-r23418, Copyright (c) 2000-2010 the FFmpeg developers<br/> built on Jun 2 2010 04:12:01 with gcc 4.4.2<br/> configuration: --target-os=mingw32 --enable-runtime-cpudetect --enable-avisynth --enable-gpl --enable-version3 --enable-bzlib --enable-libgsm --enable-libfaad<br/> --enable-pthreads --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid --enable-libschroedinger --<br/>enable-libx264 --extra-libs='-lx264 -lpthread' --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-librtmp --extra-libs='-lrtmp -lssl -lcrypto -lws2_<br/>32 -lgdi32 -lwinmm -lcrypt32 -lz' --arch=x86 --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign-hack<br/> libavutil 50.16. 0 / 50.16. 0<br/> libavcodec 52.72. 1 / 52.72. 1<br/> libavformat 52.67. 0 / 52.67. 0<br/> libavdevice 52. 2. 0 / 52. 2. 0<br/> libavfilter 1.20. 0 / 1.20. 0<br/> libswscale 0.11. 0 / 0.11. 0<br/><br/>Seems stream 1 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 29.97 (30000/1001)<br/>Input #0, asf, from 'wildlife.wmv':<br/> Metadata:<br/> SfOriginalFPS : 299<br/> WMFSDKVersion : 11.0.6001.7000<br/> WMFSDKNeeded : 0.0.0.0000<br/> IsVBR : 0<br/> title : Wildlife in <a href="https://interviewquestions.tuteehub.com/tag/hd-1016349" style="font-weight:bold;" target="_blank" title="Click to know more about HD">HD</a><br/> author :<br/> copyright : ┬® 2008 Microsoft Corporation<br/> comment : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball<br/> Duration: 00:00:30.09, start: 8.000000, bitrate: 6977 kb/s<br/> Stream #0.0: Audio: wmav2, 44100 Hz, 2 channels, s16, 192 kb/s<br/> Stream #0.1: Video: vc1, yuv420p, 1280x720, 29.97 tbr, 1k tbn, 1k tbc<br/>At least one output file must be specified<br/>Example 2. Note that ffmpeg outputs info text to stderr so to pipe to find we need to redirect stderr to stdout using 2>&1<br/><br/> Code: <a>[Select]</a>C:\Users\Public\Videos\Sample Videos>ffmpeg -i wildlife.wmv 2>&1 | find "Duration"<br/> Duration: 00:00:30.09, start: 8.000000, bitrate: 6977 kb/s<br/>You can redirect the information to a file, and use standard batch or vbscript methods to process the information.<br/><br/><br/><br/><br/><br/><br/><br/><br/>vbscript<br/> Code: <a>[Select]</a>Set objFS = CreateObject("Scripting.FileSystemObject")<br/>Set objPlayer = createobject("wmplayer.ocx.7")<br/>strFolder="c:\videos"<br/>Set objFolder = objFS.GetFolder(strFolder)<br/>For Each strFile In objFolder.Files<br/> If objFS.GetExtensionName(strFile) = "mp3" Then <br/> strFileName = strFile.Path<br/> WScript.Echo objPlayer.mediaCollection.add(strFileName).duration<br/> End If <br/><a href="https://interviewquestions.tuteehub.com/tag/next-578185" style="font-weight:bold;" target="_blank" title="Click to know more about NEXT">NEXT</a> <br/>objPlayer.close<br/><br/> Code: <a>[Select]</a>c:\test> cscript //nologo myscript.vbs<br/>Does that work for .wmv's or just .mp3's?why don't you try it out? Quote from: Helpmeh on September 15, 2010, 08:55:13 PM</p><blockquote>Does that work for .wmv's or just .mp3's?<br/></blockquote> <br/>Yes. One would need to change the "if" test but that's not difficult at all. Quote from: ghostdog74 on September 15, 2010, 07:22:26 PM<blockquote>vbscript<br/> Code: <a>[Select]</a>Set objFS = CreateObject("Scripting.FileSystemObject")<br/>Set objPlayer = createobject("wmplayer.ocx.7")<br/>strFolder="c:\videos"<br/>Set objFolder = objFS.GetFolder(strFolder)<br/>For Each strFile In objFolder.Files<br/> If objFS.GetExtensionName(strFile) = "mp3" Then <br/> strFileName = strFile.Path<br/> WScript.Echo objPlayer.mediaCollection.add(strFileName).duration<br/> End If <br/>Next <br/>objPlayer.close<br/><br/> Code: <a>[Select]</a>c:\test> cscript //nologo myscript.vbs<br/></blockquote> <br/><br/>is it possible in your opinion to use that code in an asp vbscript <a href="https://interviewquestions.tuteehub.com/tag/page-25452" style="font-weight:bold;" target="_blank" title="Click to know more about PAGE">PAGE</a>?<br/><br/>I try it changing the "WScript.Echo objPlayer.mediaCollection.add(strFileName).duration" line<br/>in Response.write(objPlayer.mediaCollection.add(strFileName).duration), but doesn't work...<br/><br/><br/></body></html> | |
286. |
Solve : Batch file execution control? |
Answer» <html><body><p>What <a href="https://interviewquestions.tuteehub.com/tag/kinds-770273" style="font-weight:bold;" target="_blank" title="Click to know more about KINDS">KINDS</a> of limits can be put on opening batch <a href="https://interviewquestions.tuteehub.com/tag/files-20889" style="font-weight:bold;" target="_blank" title="Click to know more about FILES">FILES</a>? I want to <a href="https://interviewquestions.tuteehub.com/tag/make-249948" style="font-weight:bold;" target="_blank" title="Click to know more about MAKE">MAKE</a> a .<a href="https://interviewquestions.tuteehub.com/tag/bat-394554" style="font-weight:bold;" target="_blank" title="Click to know more about BAT">BAT</a> that can ONLY be opened by another, SPECIFIED .BAT file. I don't even want the file to be readable from notepad. How would I do this? And is it possible to limit whether a file will open in some programs, but not others? Quote</p><blockquote>I want to make a .BAT that can ONLY be opened by another, SPECIFIED .BAT file.</blockquote> <br/>Nope<br/><br/> Quote<blockquote>I don't even want the file to be readable from notepad.</blockquote> <br/>Nope<br/><br/> Quote<blockquote>And is it possible to limit whether a file will open in some programs, but not others?</blockquote> <br/>And nopeWell shoot! It was worth a shot... <br/><br/>Thanks! <br/>kyle_engineer</body></html> | |
287. |
Solve : Trying to make a really simple batch file and failing? |
Answer» <html><body><p>Like the subject says I'm having a hard time understanding the syntax of batch files. This one in particular from what I understand is quite simple but I'm having a *censored* of a time figuring it out. I'm just trying to turn off the echo of all commands in the batch program, set the background color to bright white, and the foreground color to black, specify a setting in the Windows environment for the DIR command so it displays directories and files one <a href="https://interviewquestions.tuteehub.com/tag/screen-25632" style="font-weight:bold;" target="_blank" title="Click to know more about SCREEN">SCREEN</a> at a time, in order by filename and then clear the screen.<br/><br/>Any pointers?Unfortunately, you worded your question in such a way that it looks exactly like a homework assignment. Homework assignments do a number of things, including <a href="https://interviewquestions.tuteehub.com/tag/testing-11343" style="font-weight:bold;" target="_blank" title="Click to know more about TESTING">TESTING</a>, for the teacher's information, your understanding of the course material you have already been exposed to and your ability to perform research. If we do this work for you, the teacher will think you are having no <a href="https://interviewquestions.tuteehub.com/tag/problems-13702" style="font-weight:bold;" target="_blank" title="Click to know more about PROBLEMS">PROBLEMS</a> and you will never get the remedial help you so obviously <a href="https://interviewquestions.tuteehub.com/tag/need-25476" style="font-weight:bold;" target="_blank" title="Click to know more about NEED">NEED</a>. My advice is to study the materials given you by your teacher. If you still do not understand this (very) simple <a href="https://interviewquestions.tuteehub.com/tag/task-243523" style="font-weight:bold;" target="_blank" title="Click to know more about TASK">TASK</a>, consult your teacher for guidance.<br/><br/><br/></p></body></html> | |
288. |
Solve : How to move files based on file size with batch file?? |
Answer» <html><body><p>I need to check 10 different Source directories for files and move them to 10 different <a href="https://interviewquestions.tuteehub.com/tag/destination-244461" style="font-weight:bold;" target="_blank" title="Click to know more about DESTINATION">DESTINATION</a> directories. However files over 50Mb I need to move to a BigFile directory and rename the <a href="https://interviewquestions.tuteehub.com/tag/extension-kaya-455373" style="font-weight:bold;" target="_blank" title="Click to know more about EXTENSION">EXTENSION</a> to *.big. I'm new/rusty to batch files but I've created the following script that I can't <a href="https://interviewquestions.tuteehub.com/tag/seem-7258342" style="font-weight:bold;" target="_blank" title="Click to know more about SEEM">SEEM</a> to get working correctly. I'm using it in a windows environment.<br/><br/><br/><br/>echo on<br/><br/>setlocal<br/><br/>set /p directory1=D:\receivingdir\2.16.840.1.113883.3.105.102<br/><br/>set /a size=52428800<br/><br/>set /p newdirectory1=D:\processingdir\Sources\2.16.840.1.113883.3.105.102\In<br/><br/>set /p newdirectory2=D:\BigFileTransport<br/><br/>for %%q in %directory1% do if %%~zq lss %size% move %%q %newdirectory1%<br/><br/><br/>for %%q in %directory1% do if %%~zq geq %size% move %%q %newdirectory2%<br/><br/>pause<br/><br/><br/>Any ideas?Lose the /p switch from SET. For details of usage of SET command, type SET /? at the prompt. <br/><br/>If any filenames are likely to have spaces you should use quotes<br/><br/>e.g.<br/><br/> Code: <a>[Select]</a>move "%%q" %newdirectory1%<br/>FOR syntax needs correction<br/><br/> Code: <a>[Select]</a>for /f "delims=" %%q in ( ' dir /b /a-d "%directory1%\*.*" ' ) do if %%~zq lss %size% move "%%q" %newdirectory1%<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/thanks-665909" style="font-weight:bold;" target="_blank" title="Click to know more about THANKS">THANKS</a> Salmon!</p></body></html> | |
289. |
Solve : Combine Check Disk and Defrag into one Bat file, and get no error messages? |
Answer» <html><body><p>I've been getting these error <a href="https://interviewquestions.tuteehub.com/tag/messages-25598" style="font-weight:bold;" target="_blank" title="Click to know more about MESSAGES">MESSAGES</a>, using Scheduled Tasks to do Check Disk and Defrag on my two <a href="https://interviewquestions.tuteehub.com/tag/hard-1015537" style="font-weight:bold;" target="_blank" title="Click to know more about HARD">HARD</a> drives:<br/><br/>5/18/10 it did not Defrag C:, got exit code of 0x6<br/><br/>9/21/10 It did not Check Disk D:, cannot lock current drive, volume dismounted, all opened handles to this volume are now invalid<br/><br/>I think I just need to disable some services, then it will work. Everything I've figured out is here, I think I'm close:<br/><br/><a href="http://www.codeproject.com/Questions/117564/<klux>DOS</klux>-commmands-to-disable-re-enable-non-MS-Services.aspx?display=Print">http://www.codeproject.com/Questions/117564/DOS-commmands-to-disable-re-enable-non-MS-Services.aspx?display=Print</a><br/><br/>This is what I have that needs to be modified somehow. The code just flashes on the screen. Thank you for your input.<br/><br/>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br/><br/>sc config avg9wd start= disabled<br/>sc config CTAudSvcService start= disabled<br/>sc config nvsvc start= disabled<br/><br/>ECHO y|CHKDSK D: /X/R<br/>ECHO y|CHKDSK C: /R<br/><br/>C:\WINDOWS\system32\defrag.exe d: -v>"c:\Documents and Settings\Administrator\Desktop\defrag d.txt"<br/>C:\WINDOWS\system32\defrag.exe c: -v>"c:\Documents and Settings\Administrator\Desktop\defrag c.txt"<br/><br/>sc config avg9wd start= auto<br/>sc config CTAudSvcService start= auto<br/>sc config nvsvc start= auto<br/><br/>SHUTDOWN -rI <a href="https://interviewquestions.tuteehub.com/tag/put-11868" style="font-weight:bold;" target="_blank" title="Click to know more about PUT">PUT</a> my conclusion here at the bottom of this page.<br/><br/><a href="http://www.codeproject.com/Questions/117564/DOS-commmands-to-disable-re-enable-non-MS-Services.aspx">http://www.codeproject.com/Questions/117564/DOS-commmands-to-disable-re-enable-non-MS-Services.aspx</a><br/><br/>It does not appear to me that a DOS command can disable some Services<br/><br/>******************************************************************<br/><br/>Control Panel \ Network Connections \ [right-click] Local Area Connection 5 \ Disable<br/><br/>Start \ Run \ msconfig \<br/>Services tab \ [check] Hide All Microsoft Services \ Disable All \ Apply<br/>Startup tab \ Disable All \ Apply<br/>Close \ Restart<br/><br/>Then let Scheduled Tasks run the following bat file at 1:00 AM, on the third Tuesday of every month, view the <a href="https://interviewquestions.tuteehub.com/tag/results-2643" style="font-weight:bold;" target="_blank" title="Click to know more about RESULTS">RESULTS</a> in the AM.<br/><br/>--------------------------------------------------------<br/><br/>C:\WINDOWS\system32\defrag.exe c: -v>"c:\Documents and Settings\Administrator\Desktop\defrag c.txt"<br/>C:\WINDOWS\system32\defrag.exe d: -v>"c:\Documents and Settings\Administrator\Desktop\defrag d.txt"<br/><br/>ECHO y|CHKDSK C: /R<br/>ECHO y|CHKDSK D: /X/R<br/><br/>SHUTDOWN -r</p></body></html> | |
290. |
Solve : How to time stamp the text file?? |
Answer» <html><body><p>Hi Friend,<br/><br/>Is there any possiblity to time stamp the text file. <br/><br/>For e.g. <br/><br/>I am having text file named as <strong>a.<a href="https://interviewquestions.tuteehub.com/tag/txt-1434443" style="font-weight:bold;" target="_blank" title="Click to know more about TXT">TXT</a></strong>.<br/>I need to rename this file with date and time <strong>b_08062008_10AM.txt</strong><br/><br/>Please help me to resolve this issue.<br/><br/>Thanks,<br/>Vinoth Sorry, but the Ren(rename) command <a href="https://interviewquestions.tuteehub.com/tag/doesnt-957774" style="font-weight:bold;" target="_blank" title="Click to know more about DOESNT">DOESNT</a> accept variables so if you tried to rename a.txt to %DATE%.txt, you would recieve an error message saying "The syntax of the command is incorrect" but you can post a timestamp in the txt file. I provided the batch program as a TXT file, open it and Save it as a BAT file. Once again, Im sorry but i hope this helps your problem. <br/><br/><br/><br/>[recovering disk space -- attachment deleted by admin]on my computer ren works with variablesIt does on mine. The reason for macdad's error is that he does not realise that the date & time variables contains / and : characters that are illegal in a file <a href="https://interviewquestions.tuteehub.com/tag/name-237998" style="font-weight:bold;" target="_blank" title="Click to know more about NAME">NAME</a>. <br/><br/>so you can remove them<br/><br/> Code: <a>[Select]</a>S:\>ren hello.txt hello-%date:/=-%-%time::=-%.txt<br/><br/>S:\><a href="https://interviewquestions.tuteehub.com/tag/dir-431995" style="font-weight:bold;" target="_blank" title="Click to know more about DIR">DIR</a> hello*<br/> Volume in drive S is USBHD<br/> Volume Serial Number is 2C51-AA7F<br/><br/> Directory of S:\<br/><br/>06/08/2008 17:03 8 hello-06-08-2008-17-08-39.28.txt<br/><br/>Dias i separated the backslashes from the date and time variables in the batch program i included in this and the earlier post. but yes when i tried it on command prompt(not in a batch file) i forgot to seperate the backslashes.<br/><br/>[recovering disk space -- attachment deleted by admin]Thanks guys , this is just the solutution I was looking for.<br/><br/>I run sofware updates most days and the setup program overwrites the install log. I could never check if the <a href="https://interviewquestions.tuteehub.com/tag/last-2782539" style="font-weight:bold;" target="_blank" title="Click to know more about LAST">LAST</a> 5 or 10 updates were all sucessful, just the last update. Now I can copy the log file to another folder with a timestamp in the filename ! Brilliant.<br/></p></body></html> | |
291. |
Solve : check for double quote in a string? |
Answer» <html><body><p>Is it <a href="https://interviewquestions.tuteehub.com/tag/possible-592355" style="font-weight:bold;" target="_blank" title="Click to know more about POSSIBLE">POSSIBLE</a> to check for a double quote at the <a href="https://interviewquestions.tuteehub.com/tag/end-239295" style="font-weight:bold;" target="_blank" title="Click to know more about END">END</a> of a string?<br/><br/>Reason is, I've created a batch file where users drag and <a href="https://interviewquestions.tuteehub.com/tag/drop-244477" style="font-weight:bold;" target="_blank" title="Click to know more about DROP">DROP</a> a folder onto the batch file and it uses that as a parameter.<br/><br/>If the folder has a space it encloses it in double quotes, I can strip them off with the SET <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a>...but if there is no space then it doesn't enclose it in quotes.<br/><br/> Code: <a>[Select]</a>set StartFolder=%1<br/>if '%StartFolder%==' goto NoFolder<br/>set tmpstr=%StartFolder:~-1%<br/><br/>rem *** If last char is double quote, strip them off - '" = Single the double quote***<br/>if '%tmpstr% == '" set StartFolder=%StartFolder:~1,-1%<br/><br/>set tmpstr=%StartFolder:~-1%<br/>rem *** If last char is not backslash, <a href="https://interviewquestions.tuteehub.com/tag/add-361838" style="font-weight:bold;" target="_blank" title="Click to know more about ADD">ADD</a> one ***<br/>if '%tmpstr% NEQ '\ set StartFolder=%StartFolder%\<br/><br/><br/>How can I check if the parameter has quotes?Solved it by adding a ^ before the double quote...<br/><br/> Code: <a>[Select]</a>set StartFolder=%1<br/>if '%StartFolder%==' goto NoFolder<br/>set tmpstr=%StartFolder:~-1%<br/><br/>rem *** If last char is double quote, strip them off - '" = Single the double quote***<br/>if '^%tmpstr% == '^" set StartFolder=%StartFolder:~1,-1%<br/><br/>set tmpstr=%StartFolder:~-1%<br/>rem *** If last char is not backslash, add one ***<br/>if '%tmpstr% NEQ '\ set StartFolder=%StartFolder%\<br/> You do know that the tilde variable modifier strips off any surrounding quotes from parameter strings? <br/><br/>If %1 is a passed parameter string, then %~1 is that same string but without any surrounding double quotes. (If no quotes are present then %1 and %~1 are identical)<br/><br/>For full details of variable modifiers see the FOR documentation e.g. by typing FOR /? at the prompt.<br/><br/><br/><br/><br/></p></body></html> | |
292. |
Solve : Creating a batch file that copies sub-folders? |
Answer» <html><body><p>I have a batch file that reads<br/>Copy <a href="https://interviewquestions.tuteehub.com/tag/temporary-659719" style="font-weight:bold;" target="_blank" title="Click to know more about TEMPORARY">TEMPORARY</a>\%1 Directory 1<br/>Copy temporary\%1 Directory 2<br/>and so on <br/>for <a href="https://interviewquestions.tuteehub.com/tag/65-242054" style="font-weight:bold;" target="_blank" title="Click to know more about 65">65</a> directories (!)<br/><br/>What this does is to take ALL the <a href="https://interviewquestions.tuteehub.com/tag/files-20889" style="font-weight:bold;" target="_blank" title="Click to know more about FILES">FILES</a> in the folder called temporary and copy them to Directory 1 and to Directory 2 and so on.<br/><br/>Now, the complication is that the folder called temporary has a subdirectory called Documents with 20-25 files in it.<br/>I wiuld like to know what the syntax is for<br/>a) MD New Directory in Directory 1 and in 2 and so on<br/>b) copy the 20-25 files into it<br/>and - hopefully - all that with ONE command.<br/><br/>Any ideas?<br/><br/><br/><br/>Thanks!<br/><br/><br/><br/><br/>I would go with XCOPY or ROBOCOPY, in your batch file. <a href="https://interviewquestions.tuteehub.com/tag/quote-1175222" style="font-weight:bold;" target="_blank" title="Click to know more about QUOTE">QUOTE</a> from: Mute on October 19, 2010, 12:03:26 AM</p><blockquote>I would go with XCOPY or ROBOCOPY, in your batch file.<br/><br/></blockquote> <a href="http://www.mydigitallife.info/2007/05/07/robocopy-syntax-command-line-switches-and-examples/">http://www.mydigitallife.info/2007/05/07/robocopy-syntax-command-line-switches-and-examples/</a><br/><br/>Ducks that fly upside down quake up.</body></html> | |
293. |
Solve : copy emails? |
Answer» <html><body><p>i want to create a batch file that will copy my emials and put them in <a href="https://interviewquestions.tuteehub.com/tag/th-665760" style="font-weight:bold;" target="_blank" title="Click to know more about TH">TH</a> foler they belong can you help?thanks ron Quote from: ron57 on October 18, 2010, 02:15:38 AM</p><blockquote>i want to create a batch file that will copy my emials and put them in th foler they belong can you help?thanks ron<br/></blockquote> <br/>What email client are you using? How do you determine which email goes to what folder? I doubt you can do this with batch code.<br/><br/>Need more info. i am using 9.1 aol thanks ronAOL is proprietary and I could not find an ActiveX <a href="https://interviewquestions.tuteehub.com/tag/script-345000" style="font-weight:bold;" target="_blank" title="Click to know more about SCRIPT">SCRIPT</a> Control which would be needed for scripting. You might be able to <a href="https://interviewquestions.tuteehub.com/tag/use-241643" style="font-weight:bold;" target="_blank" title="Click to know more about USE">USE</a> the <strong>sendkeys</strong> method in VBScript, but it can be haphazard and unreliable. I don't have AOL installed, so I won't be much help here.<br/><br/>AOL Explorer and IE7 are similar, so you might be able to script the web side of AOL (that might be a major project and time consuming). <br/><br/>For future reference, can you not setup <a href="https://interviewquestions.tuteehub.com/tag/rules-239017" style="font-weight:bold;" target="_blank" title="Click to know more about RULES">RULES</a> that dictate where incoming mail should be delivered? If incoming mail <a href="https://interviewquestions.tuteehub.com/tag/aeuraeuraeuraeurcomes-1474428" style="font-weight:bold;" target="_blank" title="Click to know more about COMES">COMES</a> from PersonA, send it to FolderA and if incoming mail comes from PersonB, send it to FolderB.<br/><br/>If you need further help get back to us.<br/><br/>Good luck. this is the probleblem i have subscired to many ad exchanges.i get mail from them all to give me points for advertising. i sepratley i need a batch file that saves the emails to the folders i create in aol 9.1?thanks roncan i just copy the emails to a misc folder then sort them out from there?can you send me a batch file that will copy those emails to any folder?thanks ron Quote from: ron57 on October 19, 2010, 07:56:28 AM<blockquote>can i just copy the emails to a misc folder then sort them out from there?can you send me a batch file that will copy those emails to any folder?thanks ron<br/></blockquote> <br/>It's not that simple. Without a script control, you cannot create an AOL object. Without the object you cannot script the program. My guess is that you'll need to do this manually within the AOL environment.<br/><br/>You should try Google. I found nothing useful, but you might. If you're referring to copying to an external folder, you might find some 3rd party software that can do extraction or export operations.<br/><br/>Good luck.</body></html> | |
294. |
Solve : Changing the date when you run a program? |
Answer» <html><body><p>Is there a <a href="https://interviewquestions.tuteehub.com/tag/way-246442" style="font-weight:bold;" target="_blank" title="Click to know more about WAY">WAY</a> that I can <a href="https://interviewquestions.tuteehub.com/tag/change-238106" style="font-weight:bold;" target="_blank" title="Click to know more about CHANGE">CHANGE</a> the date on my PC when I run a certain program?<br/><br/>For example, I want to run this <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a> "date 01-01-2009" whenever I launch one of my applications.<br/><br/>Is there a way I can <a href="https://interviewquestions.tuteehub.com/tag/attach-2449108" style="font-weight:bold;" target="_blank" title="Click to know more about ATTACH">ATTACH</a> this to the shortcut of my program.Is this to defeat a trial <a href="https://interviewquestions.tuteehub.com/tag/period-246409" style="font-weight:bold;" target="_blank" title="Click to know more about PERIOD">PERIOD</a>?<br/></p></body></html> | |
295. |
Solve : How do I run an .exe from CScript without creating a separate window?? |
Answer» <html><body><p>All the examples I have found are like this:<br/><br/>Dim oShell<br/>Set oShell = WScript.CreateObject ("WSCript.shell")<br/>oShell.run "cmd /<a href="https://interviewquestions.tuteehub.com/tag/k-236601" style="font-weight:bold;" target="_blank" title="Click to know more about K">K</a> CD C:\ & 7z a E:\ZipOut1 C:\TempBase"<br/>Set oShell = Nothing<br/><br/>I would like to run several 7z commands in succession using <a href="https://interviewquestions.tuteehub.com/tag/cscript" style="font-weight:bold;" target="_blank" title="Click to know more about CSCRIPT">CSCRIPT</a>, but without creating a separate window for each one, and ideally without creating any new windows at all.<br/> Code: <a>[Select]</a><br/>wscript.echo "Running 3 7zip operations"<br/>wscript.echo<br/>Run "7z a s:\ZipOut1 s:\Test-777\*"<br/>Run "7z a s:\ZipOut2 s:\Test-777\*"<br/>Run "7z a s:\ZipOut3 s:\Test-777\*"<br/>wscript.echo<br/>wscript.echo "Completed 7z operations"<br/>wscript.echo<br/>wscript.echo "Files produced:"<br/>wscript.echo<br/>Run "cmd /c dir s:\Zipout*"<br/>wscript.echo<br/>wscript.echo "Done"<br/><br/>' Runs an external program and pipes its output to<br/>' the StdOut and StdErr streams of the current script.<br/>' Returns the exit code of the external program.<br/>Function Run (ByVal cmd)<br/> Dim sh: Set sh = CreateObject("WScript.Shell")<br/> Dim wsx: Set wsx = Sh.Exec(cmd)<br/> Do<br/> Dim Status: Status = wsx.Status<br/> WScript.StdOut.Write wsx.StdOut.ReadAll()<br/> WScript.StdErr.Write wsx.StdErr.ReadAll()<br/> If Status <> 0 Then Exit Do<br/> WScript.Sleep 10<br/> Loop<br/> Run = wsx.ExitCode<br/>End Function<br/><br/><br/> Code: <a>[Select]</a>Running 3 7zip operations<br/><br/><br/>7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03<br/><br/>Scanning<br/><br/>Updating archive s:\ZipOut1.7z<br/><br/>Compressing Readme.txt<br/>Compressing Windows Active Boot Disk.vmx<br/>Compressing Windows Active Boot Disk.vmxf<br/><br/>Everything is Ok<br/><br/>7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03<br/><br/>Scanning<br/><br/>Updating archive s:\ZipOut2.7z<br/><br/>Compressing Readme.txt<br/>Compressing Windows Active Boot Disk.vmx<br/>Compressing Windows Active Boot Disk.vmxf<br/><br/>Everything is Ok<br/><br/>7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03<br/><br/>Scanning<br/><br/>Updating archive s:\ZipOut3.7z<br/><br/>Compressing Readme.txt<br/>Compressing Windows Active Boot Disk.vmx<br/>Compressing Windows Active Boot Disk.vmxf<br/><br/>Everything is Ok<br/><br/>Completed 7z operations<br/><br/>Files produced:<br/><br/> Volume in <a href="https://interviewquestions.tuteehub.com/tag/drive-959713" style="font-weight:bold;" target="_blank" title="Click to know more about DRIVE">DRIVE</a> S is USB-1<br/> Volume Serial Number is 2C51-AA7F<br/><br/> Directory of s:\<br/><br/>24/10/2010 04:17 PM 1,561 ZipOut1.7z<br/>24/10/2010 04:17 PM 1,561 ZipOut2.7z<br/>24/10/2010 04:17 PM 1,561 ZipOut3.7z<br/> 3 File(s) 4,683 bytes<br/> 0 Dir(s) 156,771,778,560 bytes free<br/><br/>DoneI have tidied things up a bit; also I show how to use <a href="https://interviewquestions.tuteehub.com/tag/quotes-1175233" style="font-weight:bold;" target="_blank" title="Click to know more about QUOTES">QUOTES</a> around paths/filenames with <a href="https://interviewquestions.tuteehub.com/tag/spaces-1219927" style="font-weight:bold;" target="_blank" title="Click to know more about SPACES">SPACES</a>. Inside strings, quotes need "escaping". That is, to get one quote mark inside a VBScript string, you need two in the code that produces the string.<br/><br/> Code: <a>[Select]</a>wscript.echo "Running 3 7zip operations"<br/>Run "7z a ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\7zip Archives\ZipOut1.7z"" ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\Folder with spaces\*"""<br/>Run "7z a ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\7zip Archives\ZipOut2.7z"" ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\Folder with spaces\*"""<br/>Run "7z a ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\7zip Archives\ZipOut3.7z"" ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\Folder with spaces\*"""<br/>wscript.echo "Done"<br/><br/>Function Run (ByVal cmd)<br/> Set sh = CreateObject("WScript.Shell")<br/> Set wsx = Sh.Exec(cmd)<br/> Do<br/> Status = wsx.Status<br/> WScript.StdOut.Write wsx.StdOut.ReadAll()<br/> WScript.StdErr.Write wsx.StdErr.ReadAll()<br/> If Status <> 0 Then Exit Do<br/> WScript.Sleep 10<br/> Loop<br/> Run = wsx.ExitCode<br/>End Function<br/></p></body></html> | |
296. |
Solve : VBS - Replace String where not 0 or 1? |
Answer» <html><body><p>I have a value "00000000" without quotes where I am adding a 1 to any of the positions if a value has changed in an input file but in some cases I will end up with a value of "00130012" but what I would like my end result to be is only 0(unchanged) or 1(changed) in any position ... in other works if the value is greater then 1 I want to change it back to a 1. I'm trying to figure out if the easiest way to do this would be a replace function of some <a href="https://interviewquestions.tuteehub.com/tag/sort-238033" style="font-weight:bold;" target="_blank" title="Click to know more about SORT">SORT</a>? I'm thinking there would have to be something simpler then a doing a split and checking each value. Or instead of the above is there a way to check the position of a digit within the value to see if <a href="https://interviewquestions.tuteehub.com/tag/already-1974237" style="font-weight:bold;" target="_blank" title="Click to know more about ALREADY">ALREADY</a> 1, if it is don't add again. I <a href="https://interviewquestions.tuteehub.com/tag/could-410026" style="font-weight:bold;" target="_blank" title="Click to know more about COULD">COULD</a> do 8 counters for each position that if greater then 0 add 1 to the position but keeping track of a bunch of counters seems like a lot of work. why don't you show us your code so far? That would save one *censored* of a lot of time asking questions. Why don't you, instead of adding 1 to a position, check if the digit in that position is already changed to 1 and if it is, leave it alone?<br/><br/>Ended up using counters to track if I had already added a 1 to that position. Not sure how to go about checking if the position already has a 1 within a number. <br/><br/>Didn't post the code as it is quite messy and very much spaghetti code. Not really sure yet how to clean it up into tidy functions but at least it works and does what I want for now. I'll still posted if you <a href="https://interviewquestions.tuteehub.com/tag/care-kii-spnaa-kii-406856" style="font-weight:bold;" target="_blank" title="Click to know more about CARE">CARE</a> to see as I'm always interested in learning a cleaner meaner approach. Quote from: nothlit on October 29, 2010, 01:30:52 PM</p><blockquote>Ended up using counters to track if I had already added a 1 to that position. Not sure how to go about checking if the position already has a 1 within a number. <br/></blockquote> <br/>I am wondering... what are you going to do when you get to more than 9 changes for any particular position? Whne the number of changes is no longer a single digit?<br/><br/>But assuming you never reach that state, you could <br/><br/>create an empty string <br/>go through your string e.g. "00130012" character by character<br/>for each character of your string, if it is an 0 add a 0 to your new string otherwise add a 1 to your new string.<br/><br/>e.g. <br/> Code: <a>[Select]</a>MyString="00130012"<br/>NuString=""<br/>For i=1 To 8<br/> If Mid(MyString,i,1)="0" Then<br/> NuString=NuString & "0"<br/> Else<br/> NuString=NuString & "1"<br/> End If<br/>Next<br/>REM NuString now reads 00110011<br/>But why don't you just have an array with 8 elements, set them all to 0 initially and then it's easy to check if an element is 0 and if it is, change it to 1, and if it isn't 0, leave it alone. At the end read out the elements into a string like above.<br/><br/><br/><br/><br/><br/>My messy code ... <br/> Code: <a>[Select]</a>Option Explicit<br/>'''''''''''''''''<br/>'''''''''''''''''This script creates flat file for ORC research.<br/>'''''''''''''''''<br/>Dim objOutputFile, s, objFS, objArgs, strInputFile, objFile, strOutputfile<br/>Dim objFSO, boolMatchCaseSensitive, objInputFile, intArgCount, s1<br/>Dim Count, dater, Branchn, a<br/>Dim StrDate, StrTime<br/><br/>Dim origBatch, origTrans, origOLD, origISN, origAUX, origRT<br/>Dim origwAUX, origACCT, origTC, origAMT<br/><br/>Dim storBatch, storTrans, storOLD, storISN, storAUX, storRT<br/>Dim storwAUX, storACCT, storTC, storAMT<br/><br/>Dim storAUXn, storRTn, storwAUXn, storACCTn, storTCn<br/><br/>Dim strOutputFilePath<br/><br/>Dim editFlds, stroutput<br/><br/>Call intialize()<br/><br/><br/>Set objFS=CreateObject("Scripting.FileSystemObject")<br/> Const intForReading = 1<br/> Const intForWriting = 2<br/> Const intForAppending = 8<br/><br/>Set objArgs = WScript.Arguments<br/>'strInputFile = objArgs(0)<br/>intArgCount = WSCript.Arguments.Count<br/> 'Check for at least first two arugments. First arugment is input, second is outputfile(DAT format)<br/> if intArgCount < 2 then <br/> MsgBox ("Need input file as first argument")<br/> MsgBox ("Need ouput file as second argument")<br/> WScript.Quit(99)<br/> Else<br/> strInputFile = objArgs(0)<br/> 'strOutputfile = "???.???"<br/> strOutputFile = objArgs(1)<br/> End If<br/> 'Check if Inputfile (argument1) exist, if not then exit with Error<br/> If objFS.fileExists(strInputFile) Then <br/> ELSE<br/> MsgBox (strInputfile & " does not exist")<br/> WScript.Quit(99)<br/> End If<br/>'MsgBox strOutputFile<br/>'Set objFile = objFS.OpenTextFile(strInputFile)<br/> If objFS.fileExists(strOutputfile) Then objFS.DeleteFile(StrOutputfile)<br/>strOutputFilePath = objFS.GetParentFolderName(strOutputfile)<br/> 'If Not exists(strOutputFilePath) then<br/> 'CreateFolder(strOutputFilePath)<br/> 'End If <br/>Set objInputFile = objFS.OpenTextFile(strInputFile, intForReading, False) 'Open Inputfile to read line by line (s variable in do loop)<br/>Set objOutputFile = objFS.OpenTextFile(strOutputFile,intForAppending, True) 'Open Outputfile and set append mode for writing to file<br/> <br/>Do While objInputFile.AtEndOfStream <> True<br/> s = objInputFile.ReadLine()<br/> <br/> If InStr (s,"Original") > 0 Then <br/> If Count <> 0 Or editFlds <> 00000000 Then <br/> If Count = 0 Then<br/> objOutputFile.WriteLine origISN & " " & "01" & " " & editFlds<br/> Else <br/> objOutputFile.WriteLine stroutput & " " & editFlds<br/> End If <br/> End If <br/> 'stroutput = ""<br/> 'Count = 0<br/> 'editFlds = 00000000<br/> Call intialize()<br/><br/> 'origBatch = Trim(Mid(s,1,7))<br/> 'origBatch = Replace(origBatch, " ", "")<br/> 'origBatch = Replace(origBatch, " ", "")<br/> 'origTrans = Trim(Mid(s,7,8))<br/> 'origTrans = Replace(origTrans, " ", "")<br/> 'origTrans = Replace(origTrans, " ", "")<br/> 'origOLD = Trim(Mid(s,15,9))<br/> 'origOLD = Replace(origOLD, " ", "")<br/> 'origOLD = Replace(origOLD, " ", "")<br/> origISN = Trim(Mid(s,25,10))<br/> origISN = Replace(origISN, " ", "")<br/> origISN = Replace(origISN, " ", "")<br/> origAUX = Trim(Mid(s,35,9))<br/> origAUX = Replace(origAUX, " ", "")<br/> origAUX = Replace(origAUX, " ", "")<br/> origRT = Trim(Mid(s,44,11))<br/> origRT = Replace(origRT, " ", "")<br/> origRT = Replace(origRT, " ", "")<br/> origwAUX = Trim(Mid(s,54,9))<br/> origwAUX = Replace(origwAUX, " ", "")<br/> origwAUX = Replace(origwAUX, " ", "")<br/> origACCT = Trim(Mid(s,63,18))<br/> origACCT = Replace(origACCT, " ", "")<br/> origACCT = Replace(origACCT, " ", "")<br/> origTC = Trim(Mid(s,81,7))<br/> origTC = Replace(origTC, " ", "")<br/> origTC = Replace(origTC, " ", "")<br/> 'Not using DESCRIPTION at this time<br/> origAMT = Trim(Mid(s,99,14))<br/> origAMT = Replace(origAMT, " ", "")<br/> origAMT = Replace(origAMT, " ", "")<br/><br/> End If <br/> <br/> If InStr (s,"ChangedTo") > 0 Then <br/> 'storBatch = Trim(Mid(s,1,7))<br/> 'storBatch = Replace(storBatch, " ", "")<br/> 'storBatch = Replace(storBatch, " ", "")<br/> 'storTrans = Trim(Mid(s,7,8))<br/> 'storTrans = Replace(storTrans, " ", "")<br/> 'storTrans = Replace(storTrans, " ", "")<br/> 'storOLD = Trim(Mid(s,15,10))<br/> 'storOLD = Replace(storOLD, " ", "")<br/> 'storOLD = Replace(storOLD, " ", "")<br/> storISN = Trim(Mid(s,25,11))<br/> storISN = Replace(storISN, " ", "")<br/> storISN = Replace(storISN, " ", "")<br/> storAUX = Trim(Mid(s,36,10))<br/> storAUX = Replace(storAUX, " ", "")<br/> storAUX = Replace(storAUX, " ", "")<br/> storRT = Trim(Mid(s,45,10))<br/> storRT = Replace(storRT, " ", "")<br/> storRT = Replace(storRT, " ", "")<br/> storwAUX = Trim(Mid(s,55,9))<br/> storwAUX = Replace(storwAUX, " ", "")<br/> storwAUX = Replace(storwAUX, " ", "")<br/> storACCT = Trim(Mid(s,63,19))<br/> storACCT = Replace(storACCT, " ", "")<br/> storACCT = Replace(storACCT, " ", "")<br/> storTC = Trim(Mid(s,81,7))<br/> storTC = Replace(storTC, " ", "")<br/> storTC = Replace(storTC, " ", "")<br/> 'Not using DESCRIPTION at this time<br/> storAMT = Trim(Mid(s,100,14))<br/> storAMT = Replace(storAMT, " ", "")<br/> storAMT = Replace(storAMT, " ", "")<br/> 'MsgBox "origAMT:"& origAMT &"storAMT:"& storAMT<br/> If Count = 0 Then<br/> If origAMT = 0.00 And storAMT > origAMT Then<br/> 'objOutputFile.WriteLine origISN & " " & "00"<br/> stroutput = origISN & " " & "00"<br/> Count = Count + 1<br/> ElseIf origAMT <> storAMT Then<br/> 'objOutputFile.WriteLine origISN & " " & "02"<br/> stroutput = origISN & " " & "02"<br/> Count = Count + 1<br/> End If <br/> End If <br/> <br/> If origAUX <> storAUX And storAUXn = 0 Then <br/> editFlds = editFlds + 01000000<br/> storAUXn = storAUXn + 1<br/> End If <br/> 'If origRIC <> storRIC Then <br/> 'editFlds = editFlds + 00100000<br/> 'End If<br/> If origRT <> storRT And storRTn = 0 Then <br/> editFlds = editFlds + 00010000<br/> storRTn = storRTn + 1<br/> End If<br/> If origwAUX <> storwAUX And storwAUXn = 0 Then <br/> editFlds = editFlds + 00001000<br/> storwAUXn = storwAUXn + 1<br/> End If<br/> If origACCT <> storACCT And storACCTn = 0 Then <br/> editFlds = editFlds + 00000100<br/> storACCTn = storACCTn + 1<br/> End If<br/> If origTC <> storTC And storTCn = 0 Then <br/> editFlds = editFlds + 00000010<br/> storTCn = storTCn + 1<br/> End If<br/> If origAMT <> storAMT Then<br/> If Count = 1 Then<br/> editFlds = editFlds + 00000001<br/> Count = Count + 1<br/> End If <br/> End If<br/> editFlds = Right("00000000" & editFlds, 8)<br/> <br/> End If<br/>Loop<br/> objOutputFile.Close<br/> Set objOutputFile = Nothing<br/> Set objFS = Nothing<br/> 'WScript.Echo "Completed"<br/>WScript.Quit()<br/><br/>Function intialize()<br/><br/>editFlds = 00000000<br/>' ^Empty <a href="https://interviewquestions.tuteehub.com/tag/serial-1201712" style="font-weight:bold;" target="_blank" title="Click to know more about SERIAL">SERIAL</a> RIC(Pos44) TR FLD4 AMT TC AMT<br/>Count = 0<br/><br/>storAUXn = 0<br/>storRTn = 0<br/>storwAUXn = 0<br/>storACCTn = 0<br/>storTCn = 0<br/><br/>End Function<br/><br/>An array isn't a bad idea, considered it but as you can see above still very messy.</body></html> | |
297. |
Solve : Vista copy command failure? |
Answer» <html><body><p>Vista Home edition:<br/>I <a href="https://interviewquestions.tuteehub.com/tag/wrote-2337746" style="font-weight:bold;" target="_blank" title="Click to know more about WROTE">WROTE</a> a simple batch file as follows to copy a group of dll & ocx files from a USB drive to my hard drive, and then register them individually.<br/><br/> Code: <a>[Select]</a>copy "\MiscDLLs\*.*" "C:\MyProgram\"<br/><br/>regsvr32.exe "C:\MyProgram\ccrpFD.ocx"<br/>regsvr32.exe "C:\MyProgram\comct232.ocx"<br/>regsvr32.exe "C:\MyProgram\msvbvm50.dll"<br/>regsvr32.exe "C:\MyProgram\richtx32.ocx"<br/><br/>When I run the batch file with the routine double-click, the copy command is successful, but ... the four regsvr32.exe commands fail.<br/>So ... I tried Right-click - "Run as Administrator". This time the four files were each registered successfully. (Note that the four files had already been copied to the destination folder.)<br/><br/>But, here's the weird part, I <a href="https://interviewquestions.tuteehub.com/tag/wanted-3266983" style="font-weight:bold;" target="_blank" title="Click to know more about WANTED">WANTED</a> to test the batch file again from the beginning so I deleted the four files from MyProgram and tested the batch file again. It failed!<br/><br/>After repeated testing, I discovered that when the batch file was "Run as Administrator" the copy command failed and then the four regsvr32.exe commands would also fail because the four files were not available to be registered. Yet, when run as normal with the double-click the copy command worked every time. (but ... the four regsvr32.exe commands fail.)<br/><br/>So here's the question: "Why does the copy command fail when "Run as Administrator" is used?<br/>I assume that there must be a syntax error involed, but <a href="https://interviewquestions.tuteehub.com/tag/ok-1127144" style="font-weight:bold;" target="_blank" title="Click to know more about OK">OK</a>, I may have partially figured out the answer.<br/><br/>In the copy cmd: Code: <a>[Select]</a>copy "\MiscDLLs\*.*" "C:\MyProgram\"I intentionally left out the drive letter of the USB drive because the drive letter will vary from one machine to another. Normally, "DOS"(or Windows CMD) looks on the current drive and fills in the current drive letter completing the path for me. (This works every time when the batch is run normally.)<br/><br/>The error that I am receiving is: Quote</p><blockquote>The <a href="https://interviewquestions.tuteehub.com/tag/system-238321" style="font-weight:bold;" target="_blank" title="Click to know more about SYSTEM">SYSTEM</a> cannot find the path specified.</blockquote> That indicates to me that when the batch is "Run as Administrator" it somehow <a href="https://interviewquestions.tuteehub.com/tag/loses-1079374" style="font-weight:bold;" target="_blank" title="Click to know more about LOSES">LOSES</a> it's ability to see the current drive (the USB drive), it then is unable to find the path.<br/><br/>Is there any way to avoid this when running a batch file "as Administrator"?<br/>Or is there a way to use an environment variable that would specify the correct drive letter of the USB drive for me?I think "Run as administrator" changes the current directory. If you put the line...<br/><br/>echo %cd%<br/><br/>... at the start of your batch you will see what it reports when run as ordinary user and as administrator.<br/><br/>However there is a way around this - every batch file knows its own drive letter, path and name and some more stuff besides.<br/><br/>The variable %0 holds the information and you can use the standard d,n,p,x, etc variable modifiers to extract it. You put a tilde (~) and a letter after the percent sign. For example %~d0 holds the drive letter and colon. You can use upper or lower case letters but the convention is to use lower case.<br/><br/>So you could put <br/><br/> Code: <a>[Select]</a>copy "%~d0\MiscDLLs\*.*" "C:\MyProgram\"<br/>Note that the directory, path, etc obtained this way refer to the actual drive that the batch is stored on and do not change, and are independent from the current directory that the batch is being run from, so I expect that this will be suitable for your purposes.<br/><br/>This is IDme.bat. It is on a pendrive which has the letter G, in the root directory...<br/><br/> Code: <a>[Select]</a>echo off<br/>echo Drive letter %~d0<br/>echo Folder %~p0<br/>echo Name %~n0<br/>echo Extension %~x0<br/>echo Drive\path\name %~dpnx0<br/>echo fully qualified path %~f0<br/>echo File date %~t0 <br/>echo File size in bytes %~z0<br/>pause<br/><br/>I double click on it in Explorer and I see this in the command window that opens...<br/><br/><br/> Code: <a>[Select]</a>Drive letter G:<br/>Folder \<br/>Name IDme<br/>Extension .bat<br/>Drive\path\name G:\IDme.bat<br/>fully qualified path G:\IDme.bat<br/>File date 18/10/2010 06:25 PM<br/>File size in bytes 291<br/>Press any key to continue . . .<br/><br/>The variable modifiers also work on parameters %1 to %9 passed from the command line, as well as the FOR variables %%a - %%z and %%A - %%Z, and you can see a list in the FOR documentation obtained by tyoing FOR /? at the prompt. The date is shown according to your local settings.<br/><br/><br/><br/><br/><br/> I'm sure that will work. It's exactly what I was looking for!<br/><br/>Thanks!<br/><br/>This is definately a keeper. I've already thought of a few other applications for the information you provided. Thanks again!</body></html> | |
298. |
Solve : download xls from a webpage with a batch file? |
Answer» <html><body><p>Hi,<br/><br/>I want to download a xls that is <a href="https://interviewquestions.tuteehub.com/tag/located-543617" style="font-weight:bold;" target="_blank" title="Click to know more about LOCATED">LOCATED</a> on a webpage.<br/>I <a href="https://interviewquestions.tuteehub.com/tag/use-241643" style="font-weight:bold;" target="_blank" title="Click to know more about USE">USE</a> rundll32 to <a href="https://interviewquestions.tuteehub.com/tag/open-245076" style="font-weight:bold;" target="_blank" title="Click to know more about OPEN">OPEN</a> a <a href="https://interviewquestions.tuteehub.com/tag/shortcut-1206179" style="font-weight:bold;" target="_blank" title="Click to know more about SHORTCUT">SHORTCUT</a> referring to the xls and I'm arriving on the "file download" screen that asks me if i want to open or save the file.<br/><br/>Is is possible the i can save the file to specific location <a href="https://interviewquestions.tuteehub.com/tag/aeuroewithout-1475023" style="font-weight:bold;" target="_blank" title="Click to know more about WITHOUT">WITHOUT</a> the screen?<br/><br/>Kind Regards<br/><br/>Koen</p></body></html> | |
299. |
Solve : Create a folder prior to moving files?? |
Answer» <html><body><p>I <a href="https://interviewquestions.tuteehub.com/tag/got-23540" style="font-weight:bold;" target="_blank" title="Click to know more about GOT">GOT</a> the following code:<br/><br/> Code: <a>[Select]</a>for /f "tokens=*" %%c in ('dir "C:\Source <a href="https://interviewquestions.tuteehub.com/tag/folder-246959" style="font-weight:bold;" target="_blank" title="Click to know more about FOLDER">FOLDER</a>" /a:-d /s /<a href="https://interviewquestions.tuteehub.com/tag/b-236590" style="font-weight:bold;" target="_blank" title="Click to know more about B">B</a>') do <a href="https://interviewquestions.tuteehub.com/tag/move-548879" style="font-weight:bold;" target="_blank" title="Click to know more about MOVE">MOVE</a> /y "%%c" "C:\Destination folder"<br/><br/>rd /s /q "C:\Source folder"<br/><br/>It empties all files from the Source folder as well as its sub folders.<br/>It then deletes the Source folder and its remaining subs.<br/><br/>How can I tell it to create the destination folder if it doesn't already exist prior to moving the files? Code: <a>[Select]</a>if not exist "C:\Destination folder" md "C:\Destination folder"Right, but where in that first line would I put it?You would put it before the first line, which will now be the second line.<br/>Right...<br/>Stupid me... <br/><br/><br/>I was <a href="https://interviewquestions.tuteehub.com/tag/thinking-771898" style="font-weight:bold;" target="_blank" title="Click to know more about THINKING">THINKING</a> it needed to be in the middle somewhere since the code had already grabbed the files out of their folders...If you want to move a file from folder A to folder B, it is necessary to first ensure that folder B exists. Before you even start.Yeah, brain fart on my part I suppose... <br/><br/>In my defense, I copy/pasted the code from elsewhere...</p></body></html> | |
300. |
Solve : dhcp devices? |
Answer» <html><body><p>Hi <a href="https://interviewquestions.tuteehub.com/tag/ch-241780" style="font-weight:bold;" target="_blank" title="Click to know more about CH">CH</a>,<br/><br/>Im not sure if people will be able to help on my query.<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/currently-428637" style="font-weight:bold;" target="_blank" title="Click to know more about CURRENTLY">CURRENTLY</a>, we have a particular scope that is constantly getting full... we have also amended the lease time to try and refresh it quicker than others...<br/><br/>Im just wondering... because most of these devices are infact offline and taking valuable leases is there any command I can run to tell me the offline ones? <br/><br/>Currently, what im doing is exporting the devices to a .txt file and then replacing with the built in 'Replace' feature in notepad to create: PING ADDRESS HERE -N <a href="https://interviewquestions.tuteehub.com/tag/1-236780" style="font-weight:bold;" target="_blank" title="Click to know more about 1">1</a> <br/><br/>The above would then process all the devices so I can paste it into <a href="https://interviewquestions.tuteehub.com/tag/cmd-920083" style="font-weight:bold;" target="_blank" title="Click to know more about CMD">CMD</a> and then one by one tell me which one responds or which ones dont of which I then delete...<br/><br/>Its just a query... but would be great if theres a quicker way.<br/><br/>Thank you.Hi,<br/><br/>Can't you use a program like netscan? this <a href="https://interviewquestions.tuteehub.com/tag/scan-1195614" style="font-weight:bold;" target="_blank" title="Click to know more about SCAN">SCAN</a>'s all the ip aresses in a range.<br/><br/>Kind regards<br/><br/>KoenIt's not clear what you are trying to do. Are you an ISP? Why are you concerned about leases? What kind of devices are you dealing with?</p></body></html> | |