Explore topic-wise InterviewSolutions in Microsoft.

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.

8701.

Solve : Batch Problems and Executing Files with spaces in path?

Answer» <html><body><p>So I'm working on a batch file to help automate rather large repetitive install. The problem is that Start is unable to find the file for some reason and in general absolute pathing hasn't been working. I'm at somewhat of a loss as all the usual suspects don't appear to be the problem. I'm running Batch from a Windows 7 Command Prompt. Any ideas? <br/><br/>Code: <a>[Select]</a>Install.bat<br/>@echo off<br/><br/>:start<br/>cls<br/>set /p answer=Do you wish to Install updates? [Y/N]:<br/><br/>if %answer% == Y goto install<br/>if %answer% == y goto install<br/>if %answer% == n goto exit<br/>if %answer% == N goto exit<br/><br/><br/><br/>:install<br/>REM // Used these since absolute path was causing problems<br/>cd Win7 <br/>cd x64<br/><br/>echo Installing. Please Wait . . . . . . <br/><br/>FOR /F "eol=; tokens=1,2,3* delims=," %%i IN (list.txt) DO (<br/>set /p t=Installing %%i . . . . . . . &lt; NUL<br/>Start /wait "" "%%i /norestart /quiet"<br/>echo Success!!<br/>)<br/><br/>:exit<br/>exit<br/><br/>:shutdown<br/>REM shutdown /r /f /t 0<br/>REM set /p answer= Do you wish to Reboot? [Y/N]:<br/><br/>list.txtCode: <a>[Select]</a>"E:\Maintenance\Patches and Updates\Win7\x64\NDP40-KB2416472-x64.exe"<br/>"E:\Maintenance\Patches and Updates\Win7\x64\Windows6.1-KB958488-v6001-x64.msu"Make a simple test of critical parts of the code.<br/>Quote</p><blockquote>FOR /F "eol=; tokens=1,2,3* delims=," %%i IN (list.txt) DO (<br/>set /p t=Installing %%i . . . . . . . &lt; NUL<br/>Start /wait "" "%%i /norestart /quiet"<br/>echo Success!!<br/>)<br/></blockquote>You need to verify this block of code with a simple test. Make a dummy list of file names that are just 'stubs'. A stub is just a test program that does nothing. You want to see what happens just going through a list of files that do nothing. Never try to use a dubious block of code until it has been really verified. Unless you are a Genius. In which case you would not need help. The FOR /F thing is among the most difficult tools in DOS batch.<br/>I've tested and debugged it extensively. The file list.txt (bottom op) is my stub file. the FOR part works perfect the trouble happens when I add the start command in the loop.<br/><br/>Here's a summary of what I have done up to present (~ 18 hours, "What can i say.. i am stubborn").<br/><br/>Tested with echo as only command in loop, displays variable %%i no problems for entire stub.<br/>Add Start Into the Mix, Opens new Command Prompt at specified directory. --Not what I was expecting<br/>Added "" to the front of start after a little reading and received error invalid switch /quiet /norestart. --Progress!<br/>Added " " needed to be around the entire <a href="https://interviewquestions.tuteehub.com/tag/statement-16478" style="font-weight:bold;" target="_blank" title="Click to know more about STATEMENT">STATEMENT</a> after /wait and switches. <br/>30 minutes of work leads me to my current state of output at "cannot find E:\Maintenance\Patches and" --smack Brickwall.<br/>OP was posted sometime ~hour seven or nine, lost track of time as the sun was rising and sleep deprivation was kicking and you can bet my coworkers were peaches today <br/><br/>The weird thing is echo runs perfectly and I have double quotes surrounding not just the statement of the start, but <a href="https://interviewquestions.tuteehub.com/tag/also-373387" style="font-weight:bold;" target="_blank" title="Click to know more about ALSO">ALSO</a> around the path/[file].exe/msu which should deal with issues of long file names but apparently doesn't.<br/><br/>In retrospect I should have just written a perl script up to do what I needed done, but I hadn't programmed in batch before and thought it would have been a nice challenge of my programming skills. Oh well, C'est la Vie.<br/>I see you have used the set /p ... <br/>Code: <a>[Select]</a>FOR /F "eol=; tokens=1,2,3* delims=," %%i IN (list.txt) DO (<br/>This line looks a little odd, considering what you appear to want to do.<br/><br/>The delims block...<br/><br/>Code: <a>[Select]</a>"eol=; tokens=1,2,3* delims=,"<br/>says <br/><br/>Code: <a>[Select]</a>eol=;<br/>consider a semicolon to be the end of line marker, that is, override <a href="https://interviewquestions.tuteehub.com/tag/default-244456" style="font-weight:bold;" target="_blank" title="Click to know more about DEFAULT">DEFAULT</a> behaviour which is to <a href="https://interviewquestions.tuteehub.com/tag/ignore-497518" style="font-weight:bold;" target="_blank" title="Click to know more about IGNORE">IGNORE</a> lines starting with ; <br/><br/>Code: <a>[Select]</a>tokens=1,2,3*<br/>Split the line into 3 delimited tokens: %%i (explicit) %%j, %%k (implicit) plus the rest of the line %%l (implicit) (that's a lower case L)<br/><br/>Code: <a>[Select]</a> delims=,<br/>Set the token delimiter to be a comma<br/><br/>Since your example test.txt does not contain any lines that start with a semicolon, or have comma separated values, I don't quite see why you are doing this. The FOR /F command will pick up the entire line, but only because none of the things envisaged in the delims block are present!<br/><br/>You appear to want to take the whole line so you may as well do this<br/><br/>Code: <a>[Select]</a>FOR /F "delims=" %%i IN (list.txt) DO (<br/>This delims block...<br/><br/>Code: <a>[Select]</a>"delims=" <br/>...means "set the only token delimiters to be the start and end of the line"<br/><br/>However, I see that the paths and filenames that you show in test.txt are enclosed in double quotes. The FOR construct will pick these up and they will be included in the string to which %%i expands.<br/><br/>When you add further quotes fore-and-aft in the Start /wait line I believe you are causing the command to be parsed in a way otherwise than you intend.<br/><br/>One of the variable modifiers you can use with FOR metavariables of the %%x type is the tilde ~ which removes enclosing quotes (if present).<br/><br/>So try this - I have not got any KB files to test it on but I have tried others (.txt)<br/><br/>Code: <a>[Select]</a>@echo off<br/>FOR /F "delims=" %%i IN (list.txt) DO (<br/> set /p t=Installing %%i . . . . . . . &lt; NUL<br/> Start /wait "" "%%~i" /norestart /quiet<br/> echo Success!!<br/>)<br/><br/><br/><br/>Each command has its own sometimes extensive documentation which you can see by typing the command followed by a space and /?<br/><br/>e.g.<br/><br/>FOR /?<br/>Start /?<br/><br/><br/><br/><br/><br/><br/><br/>[Update]<br/><br/>The above seems to test out OK... the format for START in these circumstances is: quote the program drive\path\name and then pass the parameters:<br/><br/>start /wait "Window Title" "D:\Path\with spaces\program name.exe" /PARAM1 /PARAM2 /PARAMn<br/><br/>"Window Title" can be (and usually is) a null string ""<br/><br/>Code: <a>[Select]</a>FOR /F "eol=; tokens=1,2,3* delims=," %%i IN (list.txt) DO (<br/>Initially I was using semicolons in my stub file, but having the program ignore them was more trouble than not using them at all. Since the loop was operating correctly I neglected to change the working part until I had the rest of the pieces working.<br/><br/>Code: <a>[Select]</a> delims=," <br/>I was planning on splitting the drive, path, file into three variables so I could use them individually elsewhere more readily and tighten up the code but I never got the core functionality running properly so that fell by the wayside. (i.e. echoing filename .... installed! ).<br/><br/>As the script is now, it fails at each iteration of the start command. Using<br/>Code: <a>[Select]</a>START /wait "" "%%i /norestart /quiet" Where %%i = "E:\Maintenance\Patches and Updates\Win7\x64\[file].msu" in list.txt<br/>The output is an Alert Window (Title=E:\Maintenance\Patches) 'Windows cannot find "E:\Maintenance\Patches'. Make sure you typed the name correctly and then try again."<br/><br/>Its not displaying the full correct path, cutting off where the spaces are in the long path name, /Patches and Updates/, which leads me to <a href="https://interviewquestions.tuteehub.com/tag/think-661001" style="font-weight:bold;" target="_blank" title="Click to know more about THINK">THINK</a> its the long file name thats causing problems. I thought that correctly quoting would have dealt with that but apparently not.<br/><br/><br/>Update: Changed Working Directory to test whether it was the Patches and Updates -&gt; Patches and still same output. Something else is going on here than long path.</body></html>
8702.

Solve : Generating a Formatted File List?

Answer» <html><body><p>So I'm working on a batch file that will <a href="https://interviewquestions.tuteehub.com/tag/generate-245634" style="font-weight:bold;" target="_blank" title="Click to know more about GENERATE">GENERATE</a> a list of all files in the current directory with absolute path ready for input into another script.<br/>Here's what I've got so far.<br/><br/>list.bat<br/>Code: <a>[Select]</a>@ECHO OFF<br/>DIR /B /A:-D &gt; temp.txt<br/>FOR /F "tokens=1" %%i IN (temp.txt) DO (<br/>ECHO %~d1,%~p1,%%i &gt;&gt; list.txt<br/>)<br/>del temp.txt<br/><br/>The problem I am having is it runs perfect so long as list.bat is in the same directory as the other files to be listed.<br/>So for instance lets say I move list.bat to C:\Windows\ so I can call it from anywhere on the computer.<br/>I go to C:\Maintenance\Patches and Updates\, and then run list.bat<br/>Instead of getting C:,\Maintenance\Patches and Updates\,[File] I get an output of C:,\Windows\,[File]. Any Ideas?<br/>Also on a more minor note, temp.txt is added to the <a href="https://interviewquestions.tuteehub.com/tag/listing-1075650" style="font-weight:bold;" target="_blank" title="Click to know more about LISTING">LISTING</a> for some <a href="https://interviewquestions.tuteehub.com/tag/aeuroereason-239555" style="font-weight:bold;" target="_blank" title="Click to know more about REASON">REASON</a>, anyone <a href="https://interviewquestions.tuteehub.com/tag/know-534065" style="font-weight:bold;" target="_blank" title="Click to know more about KNOW">KNOW</a> why?Update: Ok So anyone know why list.bat ./ causes it to work properly and how I can implement that into the script so I don't have to type it with the batch file every time? Also still <a href="https://interviewquestions.tuteehub.com/tag/trying-3234509" style="font-weight:bold;" target="_blank" title="Click to know more about TRYING">TRYING</a> to figure out how to prevent temp.txt from going into the text file.list.bat<br/><br/>Code: <a>[Select]</a>@ECHO OFF<br/>DIR /B /A:-D &gt; temp.txt<br/>FOR /F "tokens=1" %%i IN (temp.txt) DO (<br/>IF "%%i"=="temp.txt" ( echo. ) ELSE (echo %~d1,%~p1,%%i &gt;&gt; l.txt)<br/>)<br/>del temp.txt <br/>It works.</p></body></html>
8703.

Solve : batch script dies after first call to another different batch script?

Answer» <html><body><p>I have a script that basically calls another bunch of scripts in sequence. I don't care if any of them fail -- I want the script to continue.<br/>Unfortunately, it is not. Can anything be done? Here is the basic gist:<br/><br/>CD C:\really\long\path\<br/>clam<br/><br/>CD C:\another\really\long\path<br/>clam<br/><br/>CD C:\yetanother\really\long\path<br/>clam<br/><br/>After the first "clam", it just stops. "clam.bat" is a simple script that's stored in each directory with specific stuff to do.<br/><br/>Thanks,<br/>use CALL clamthat was the first thing i tried to no avail.<br/><br/>do the clam.bat's call any other batch files?It would be helpful if you showed us the contents of 'clam', but in any case you need to use the 'call' statement if you expect a <a href="https://interviewquestions.tuteehub.com/tag/return-238023" style="font-weight:bold;" target="_blank" title="Click to know more about RETURN">RETURN</a> to the caller (the batch file you posted).<br/><br/>Code: <a>[Select]</a>CD /d "C:\really\long\path\"<br/>call clam<br/><br/>CD /d "C:\another\really\long\path"<br/>call clam<br/><br/>CD /d "C:\yetanother\really\long\path"<br/>call clam<br/><br/>It might also be wise to turn <strong>echo on</strong> in 'clam' and any other batch files referenced. This will let you see how the file executes at all levels.<br/><br/>ok. i'll try the "CALL" thing and "ECHO ON" and <a href="https://interviewquestions.tuteehub.com/tag/post-2638" style="font-weight:bold;" target="_blank" title="Click to know more about POST">POST</a> the contents of clam.bat <a href="https://interviewquestions.tuteehub.com/tag/later-1069071" style="font-weight:bold;" target="_blank" title="Click to know more about LATER">LATER</a> today.<br/>Right now -- i'm at my other job for the next 8 hours.<br/><br/>thanks for all the help everyone.ok -- turns out it was a nestled script call without the "CALL". Modified. Reran. Worked.<br/><br/>Thanks, all.Quote from: whale on <a href="https://interviewquestions.tuteehub.com/tag/march-243170" style="font-weight:bold;" target="_blank" title="Click to know more about MARCH">MARCH</a> 20, 2011, 11:49:23 AM</p><blockquote>What is a "nestled script call?" Show the code and output.<br/></blockquote><br/>"show the code and output"? When did he become responsible to answer questions after his problem has been solved? Especially when you are questioning the very piece of information that explains his problem.<br/><br/>nestled clearly means nested. I originally suspected one of the "nested" (batch files being called from the main batch) may have an <a href="https://interviewquestions.tuteehub.com/tag/additional-367648" style="font-weight:bold;" target="_blank" title="Click to know more about ADDITIONAL">ADDITIONAL</a> batch call that wasn't using call, which is why I asked whether any of the said batches called additional batch files.<br/><br/>Then he discovered the issue so there was no reason to further pursue it.</body></html>
8704.

Solve : Passing Parameters to a batch file?

Answer» <html><body><p>Hi all, <br/>I have a master file which calls another batch file like below:<br/><br/>Call "C:\CmdDest\CopyFiles.cmd"<br/><br/>pause<br/><br/>The CopyFiles.cmd calls this:<br/>xcopy "C:\Users\images\*.*" "C:\Program Files\images" /y<br/>pause<br/><br/><br/>xcopy "C:\Pics\*.*" "C:\Program Files\Pics" /y<br/><br/>pause<br/><br/>What I would like to do is <a href="https://interviewquestions.tuteehub.com/tag/instead-248606" style="font-weight:bold;" target="_blank" title="Click to know more about INSTEAD">INSTEAD</a> of hard coding the C:\Users\SunGard Branding\images\*.*, C:\Program Files\images etc I would like to <a href="https://interviewquestions.tuteehub.com/tag/pass-244661" style="font-weight:bold;" target="_blank" title="Click to know more about PASS">PASS</a> these as Parameters from the Master file to the Child batch file...<br/><br/>Please help me...Have you tried:<br/><br/>Call "C:\CmdDest\Copyfiles.Cmd 'C:\Program Files\Images' 'C:\Program Files\Pics' "<br/><br/>Batch parameters are saved to the variable %<a href="https://interviewquestions.tuteehub.com/tag/1-236780" style="font-weight:bold;" target="_blank" title="Click to know more about 1">1</a>,2,3,4,5,6,7,8,9 and for more than 9 you need to use SHIFT depending on <a href="https://interviewquestions.tuteehub.com/tag/os-25550" style="font-weight:bold;" target="_blank" title="Click to know more about OS">OS</a>. (i.e. OS+Command Prompt or MS-DOS)<br/>and<br/><br/>xcopy "C:\Users\images\*.*" %1 /y<br/>pause<br/><br/>xcopy "C:\Pics\*.*" %2 /y<br/>pauseWhen I do this:<br/><br/><br/>Call "C:\CmdDest\Copyfiles.Cmd 'C:\Program Files\Images' 'C:\Program Files\Pics' "<br/><br/><br/>It <a href="https://interviewquestions.tuteehub.com/tag/says-1195457" style="font-weight:bold;" target="_blank" title="Click to know more about SAYS">SAYS</a> the filename, directory name or volume lable syntax is incorrect<br/><br/>please helpCall "CopyFiles.CMD" Param1 Param2<br/><br/>CopyFiles.CMD<br/>echo %1, %2<br/><br/>Output:<br/>Param1<br/><br/>Looks like on my version it only passes the first variable Param1 to %1, don't know why it doesn't pass more than a single parameter.<br/><br/>Update: You Could pass a single string and have CopyFiles.CMD parse that into two variables after the fact with string manipulation but thats more of an advanced topic and I still haven't gotten all the kinks out short of trimming a known part of the string out using set str=%str:~4% to assuming the first four characters need to be trimmed out.Try:<br/>Call "C:\CmdDest\Copyfiles.Cmd" "C:\Program Files\Images" "C:\Program Files\Pics"</p></body></html>
8705.

Solve : Differences between %var and %~var?

Answer» <html><body><p>Anyone know what the differences are between those for batch files. I've <a href="https://interviewquestions.tuteehub.com/tag/seen-1199302" style="font-weight:bold;" target="_blank" title="Click to know more about SEEN">SEEN</a> some examples where they are used but haven't been able to figure out <a href="https://interviewquestions.tuteehub.com/tag/exactly-977868" style="font-weight:bold;" target="_blank" title="Click to know more about EXACTLY">EXACTLY</a> what's going on as it seems different commands handle it differently (i.e. FOR). I'm trying to figure out a way for trimming out a portion of a string read in from a file using the for command. I'm just having trouble finding any documentation on the differences between %~var and %var, obviously there is a difference as running<br/>Code: <a>[Select]</a> set str="cmd politic"<br/><a href="https://interviewquestions.tuteehub.com/tag/echo-11626" style="font-weight:bold;" target="_blank" title="Click to know more about ECHO">ECHO</a>.%str%<br/>for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a<br/>echo.%str% Works correctly in trimming " " out. <a href="https://interviewquestions.tuteehub.com/tag/thanksi-3107426" style="font-weight:bold;" target="_blank" title="Click to know more about THANKSI">THANKSI</a> told you what the tilde ~ character did <a href="https://interviewquestions.tuteehub.com/tag/4-238406" style="font-weight:bold;" target="_blank" title="Click to know more about 4">4</a> days ago. It seems you don't read posts very carefully.<br/><br/>Quote from: Me, on 18 March</p><blockquote>One of the variable modifiers you can use with FOR metavariables of the %%x type is the tilde ~ which removes enclosing quotes (if present).</blockquote></body></html>
8706.

Solve : Using Conditionals in FOR Loop?

Answer» <html><body><p>How do I <a href="https://interviewquestions.tuteehub.com/tag/go-468886" style="font-weight:bold;" target="_blank" title="Click to know more about GO">GO</a> about <a href="https://interviewquestions.tuteehub.com/tag/using-1441597" style="font-weight:bold;" target="_blank" title="Click to know more about USING">USING</a> conditionals within a for loop. I've read that the problem I'm running into is because the IF statement is <a href="https://interviewquestions.tuteehub.com/tag/interpreted-2745191" style="font-weight:bold;" target="_blank" title="Click to know more about INTERPRETED">INTERPRETED</a> before the FOR Loop but haven't found a workaround yet.<br/><br/>Here is what I want a <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> file to do. Check File set flag variables based on %%i %%j<br/><br/>Code: <a>[Select]</a>@echo off<br/>IF EXIST <a href="https://interviewquestions.tuteehub.com/tag/c-3540" style="font-weight:bold;" target="_blank" title="Click to know more about C">C</a>:\temp.txt (<br/>for /F "tokens=1,2 delims=," %%i IN (C:\temp.txt) DO (<br/>if %%i==1 (<br/> if %%j==x86 (<br/> set x86=1<br/> set reboot=1<br/> )<br/>)<br/>)<br/>)<br/>echo %x86% <br/>Unfortunately the flags never get set.Verify the content of c:\temp.txt<br/>C:\temp.txt:<br/><br/>Code: <a>[Select]</a>1,x86<br/>Batch (as above) output:<br/><br/>Code: <a>[Select]</a>1</p></body></html>
8707.

Solve : how to block internet by using command prompt lines?"?

Answer» <html><body><p>if anyone knows the answer for this post it here.You can use the <strong>devcon</strong> utility which came with the <a href="https://interviewquestions.tuteehub.com/tag/xp-747558" style="font-weight:bold;" target="_blank" title="Click to know more about XP">XP</a> <a href="https://interviewquestions.tuteehub.com/tag/toolkit-1422030" style="font-weight:bold;" target="_blank" title="Click to know more about TOOLKIT">TOOLKIT</a>. If you don't have it, you can download it <a href="https://support.microsoft.com/kb/311272">here</a>. Devcon requires that you know the hardware ID or a partial name with wildcards of the NIC.<br/><br/>I also found some VBScript code in the snippet closet.<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>Const ssfCP = &amp;H3&amp;<br/><br/>strEnable = "En&amp;able"<br/>strDisable = "Disa&amp;ble"<br/><br/>strNetworkFolder = "Network Connections"<br/>arrConnections = Array("Wireless Network Connection") 'Verify Name of Connection<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/set-11758" style="font-weight:bold;" target="_blank" title="Click to know more about SET">SET</a> objShell = CreateObject("Shell.Application")<br/>Set objCP = objShell.NameSpace(ssfCP) 'Control Panel<br/><br/>For Each f In objCP.Items<br/> If f.Name = strNetworkFolder Then<br/> Set colNetwork = f.GetFolder<br/> Exit For<br/> End If<br/>Next<br/><br/>If colNetwork.Items.Count = 0 Then WScript.Quit<br/><br/>For Each strConnection In arrConnections<br/> For Each cn In colNetwork.Items<br/> If cn.Name = strConnection Then<br/> Set conn = cn<br/> Exit For<br/> End If<br/> Next<br/><br/> bEnabled = True<br/> For Each verb In conn.Verbs<br/> If verb.Name = strEnable Then<br/> Set objEnable = verb<br/> bEnabled = False<br/> Exit For <br/> End If<br/> If verb.Name = strDisable Then<br/> Set objDisable = verb<br/> Exit For<br/> End If<br/> Next<br/> <br/> If bEnabled = True Then<br/> objDisable.DoIt<br/> Else<br/> objEnable.DoIt<br/> End If<br/> WScript.Sleep 3000<br/>Next<br/><br/>Save the code with a <strong><a href="https://interviewquestions.tuteehub.com/tag/vbs-3852369" style="font-weight:bold;" target="_blank" title="Click to know more about VBS">VBS</a></strong> extension and run from the command prompt as <strong>cscript <em>scriptname.vbs</em></strong> Be sure to verify the name of the connection which you can get by opening "Network Connections" in the control panel. The script will toggle the status of the NIC from enabled to disabled <strong>or</strong> disabled to enabled.<br/><br/>The script was tested on XP but may need some tweaks for other flavors of Windows.<br/><br/>Good luck.</p></body></html>
8708.

Solve : Ooops... I closed it. How do I prevent accidental closure of DOS programs??

Answer» <html><body><p>Hi! I have a <a href="https://interviewquestions.tuteehub.com/tag/relatively-621723" style="font-weight:bold;" target="_blank" title="Click to know more about RELATIVELY">RELATIVELY</a> simple .<a href="https://interviewquestions.tuteehub.com/tag/bat-394554" style="font-weight:bold;" target="_blank" title="Click to know more about BAT">BAT</a> file which calls up a simple command-shell '.exe' program. Is there any code that I can add to my .BAT file that would display "ARE YOU SURE YOU WANT TO <a href="https://interviewquestions.tuteehub.com/tag/exit-251227" style="font-weight:bold;" target="_blank" title="Click to know more about EXIT">EXIT</a> THIS PROGRAM?" in case I accidentally hit the "X" in the top right window (that is, accidentally <a href="https://interviewquestions.tuteehub.com/tag/closing-919708" style="font-weight:bold;" target="_blank" title="Click to know more about CLOSING">CLOSING</a> the command-shell window).<br/>Help is greeeeatly appreciated,<br/>--BHThe short answer is "no". If you really need the <a href="https://interviewquestions.tuteehub.com/tag/ability-25661" style="font-weight:bold;" target="_blank" title="Click to know more about ABILITY">ABILITY</a> to do this, you shouldn't be using batch.<br/></p></body></html>
8709.

Solve : renaming files using a batch file?

Answer» <html><body><p>i have a folder with a lot of photos and i would like 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> a dos batch file to rename all the files in the folder but dont know how to do it.<br/>The <a href="https://interviewquestions.tuteehub.com/tag/renamed-7312003" style="font-weight:bold;" target="_blank" title="Click to know more about RENAMED">RENAMED</a> <a href="https://interviewquestions.tuteehub.com/tag/images-238776" style="font-weight:bold;" target="_blank" title="Click to know more about IMAGES">IMAGES</a> should be numbered to avoid errors. Eg.: graduation_1.jpg,<br/>graduation_2.jpg, etc.Even though this is not by batch as requested...there is a tool out there called Better File Rename that works perfect for this type of purpose.In Windows Explorer, you can highlight all the files (any files, not just images) you want to rename, having <a href="https://interviewquestions.tuteehub.com/tag/first-461760" style="font-weight:bold;" target="_blank" title="Click to know more about FIRST">FIRST</a> got them in the order you want, then right click the (still) highlighted group of files, choose "Rename". Explorer will prompt you to rename the first file in the highlighted set, and when you complete that, all the others will be renamed in numerically ascending sequence in the format "New <a href="https://interviewquestions.tuteehub.com/tag/filename-987949" style="font-weight:bold;" target="_blank" title="Click to know more about FILENAME">FILENAME</a> (1).xyz", "New Filename (2).xyz", etc. If you change your mind you can click Edit, Undo Rename.<br/><br/>(1)<br/><br/>Before<br/><br/><br/><br/>(2) <br/><br/>After<br/><br/></p></body></html>
8710.

Solve : Name a txt file with output of command?

Answer» <html><body><p>I don't see a "marked solved" button. this is what I see:<br/><br/>[recovering disk <a href="https://interviewquestions.tuteehub.com/tag/space-239477" style="font-weight:bold;" target="_blank" title="Click to know more about SPACE">SPACE</a> - old attachment <a href="https://interviewquestions.tuteehub.com/tag/deleted-947557" style="font-weight:bold;" target="_blank" title="Click to know more about DELETED">DELETED</a> by admin]I think there is a bug, or possibly you need a certain number of posts before you see the mark solved button. No <a href="https://interviewquestions.tuteehub.com/tag/matter-22749" style="font-weight:bold;" target="_blank" title="Click to know more about MATTER">MATTER</a>, we have <a href="https://interviewquestions.tuteehub.com/tag/another-876628" style="font-weight:bold;" target="_blank" title="Click to know more about ANOTHER">ANOTHER</a> satisfied customer. <a href="https://interviewquestions.tuteehub.com/tag/hope-25911" style="font-weight:bold;" target="_blank" title="Click to know more about HOPE">HOPE</a> you stick around. <br/></p></body></html>
8711.

Solve : Running ping from a batch file?

Answer» <html><body><p>First, to all who contributed to the batch file and command pages, a big THANK YOU! No programming knowledge at all here, but have made a number of batch scripts to automate things like <a href="https://interviewquestions.tuteehub.com/tag/data-25577" style="font-weight:bold;" target="_blank" title="Click to know more about DATA">DATA</a> backups and disk cleanups. Everyone *says* back up your stuff frequently (the puter might not boot next time), but few do. Two clicks on a batch, and all the good stuff is copied to a flash drive in seconds. ECHO: THANK YOU! <br/><br/>OK, time to move past xcopy, del, and rd. XP SP2 preloaded by OEM (who strongly advised *not* to install SP3; not here to discuss that, thanks), both Home and Pro, on laptops with wireless router to high-speed cable modem. Using <a href="https://interviewquestions.tuteehub.com/tag/cmd-920083" style="font-weight:bold;" target="_blank" title="Click to know more about CMD">CMD</a>.exe. <br/><br/>Situation: Sometimes, a Web page will stop responding, as we all know. Lots of reasons. But every once in a while, the reason is that the connection has been dropped, whether by the ISP, the modem, or the router. The *connection between machine and router* never goes down, so it's <a href="https://interviewquestions.tuteehub.com/tag/somewhere-3049437" style="font-weight:bold;" target="_blank" title="Click to know more about SOMEWHERE">SOMEWHERE</a> between the router and the Web. Quickest diagnostic is to ping example.com. If it works, it's probably the web server, etc. If not, then either the modem or router has dropped the connection. Reboot them, and all is well. <br/><br/>Here's the problem: You guys and gals have me so spoiled , I don't want to open a command prompt and type all that, although the typing can be automated by auto-text tools. And I'm too lazy to put down the laptop and go into another room to look at the modem and router. Hey, that's part of the goodies of laptops! I'd like a batch file that when 2-clicked, runs the command ping <a href="http://www.example.com">www.example.com</a>. Default parameters are fine. It's only four packets. <br/><br/>Tried with just ping etc., and also with 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> for a new window. Allowed TCP/IP Ping command in firewall. What happens: cmd window opens, but it just keeps repeating the command infinitely, and very fast, so I have to close the window. No actual pinging. <br/><br/>Ball in your court. And thanks in advance! (Have I said "thank you" yet?)Your questioning style is so very annoying. Could you try cutting out all this Hey! Yee-har! stuff? Also, as you admit, you are being lazy. Why should we do all your thinking for you? Have you tried writing the batch script yourself? Did you even think of telling us what you have tried already?<br/><br/>Code: <a>[Select]</a>@echo off<br/>ping www.example.com<br/>pause<br/>Wow, you guys are harsh. First post, the user thanks everyone. I've been a volunteer mod at other forums, and it's always nice when someone takes the time to show some appreciation. I don't think I've ever been offended by someone thanking us *too* much. Strange. <br/><br/>Annoying style? People who curse or are snotty are more offensive than those who maybe are a little to friendly or chatty to suit your tastes. I checked the Registration agreement, and there was nothing about being too friendly. Maybe you should amend that. <br/><br/>Quote from: Salmon Trout</p><blockquote>Why should we do all your thinking for you? Have you tried writing the batch script yourself? Did you even think of telling us what you have tried already?</blockquote><br/>Did you not *read* the user's post? <br/><br/>Quote from: Bat Mastersome<blockquote>Tried with just ping etc., and also with cmd /k for a new window.</blockquote><br/>He is saying that he already tried the batch file with exactly that: ping <a href="http://www.example.com">www.example.com</a>, which BC_Programmer later suggested. And that he also tried with cmd /k ping <a href="http://www.example.com">www.example.com</a>. And he gave you the result: <br/><br/>Quote from: Bat Mastersome<blockquote>What happens: cmd window opens, but it just keeps repeating the command infinitely, and very fast, so I have to close the window. No actual pinging.</blockquote> Did you not *read* that? <br/><br/>Quote from: Salmon Trout<blockquote>Could you try cutting out all this Hey! Yee-har! stuff? </blockquote><br/>I searched the OP, and didn't find any use of "Yee-har". So now it's Salmon Trout who's being sarcastic and snotty. Maybe he should be banned.<br/><br/>Speaking of which: *Banned* on the first post, because you don't like his style of writing? Not even a warning or a request to phrase differently? Guess you should have an exact format posted, fill in the blanks, the way you like it, since anything else is apparently unacceptable. We banned people for <strong>spam</strong>, usually after one warning unless really bad; <strong>scamware or malware links</strong> immediately; <strong>profanity</strong>, usually after a warning unless really bad. *Never* because their style of questioning was "personally annoying". 7 billion people in the world, they're not all going to talk and write exactly alike, you know. Saw others here banned on first post because of some little nit. Someone asks you to do their homework or whatever? Point them to the rule about it, matter-of-factly, and keep them as a member for life, instead of banned for life for one mistake. Sheesh. <br/><br/>Wikipedia has among its basic tenets: "Don't bite the newcomer". You guys sure took a <a href="https://interviewquestions.tuteehub.com/tag/great-2556" style="font-weight:bold;" target="_blank" title="Click to know more about GREAT">GREAT</a> chomp out of this one. Nice job of reinforcing the stereotype of computer people as being rigid, humorless geeks. Oh, and don't bother banning me - I won't come back here *ever*, I promise. And neither will my evil twin, the OP. Have a nice day. <br/><br/>P. S. Since you guys didn't care to answer the question of why the ping command was being repeated endlessly, it was solved another way: auto-text tool (won't spam the name of it, even though it's total freeware). One click on Start, one on shortcut to cmd, one trigger letter ("p") which auto-types the desired command, (enter). Four keystrokes instead of two, and no having to deal with mini-dictators who do on the Web what they can't do in real life. Sad. Good luck. What's all this about people being "banned"? The OP has not been banned that I know of, but then I am not a moderator, just an ordinary member who gave his own personal, non-official opinion. If the OP was indeed banned, it must have been for something else that i don't know about, something more serious than a posting style that I didn't like!<br/><br/><br/>The OP never was and is not banned...<br/>The person who was and had his Posts removed was...maybe that's who former mod is referring to...we all know who that was...<br/>Thanks former mod on all the good advice on running a Forum.<br/>Say hi to Bill for us.Here is a great Network Connection Tester I came across. hope it helps<br/>Code: <a>[Select]</a>@echo off<br/>ECHO Checking connection, please wait...<br/>PING -n 1 www.google.com|find "Reply from " &gt;NUL<br/>IF NOT ERRORLEVEL 1 goto :SUCCESS<br/>IF ERRORLEVEL 1 goto :TRYAGAIN<br/><br/>:TRYAGAIN<br/>ECHO FAILURE!<br/>ECHO Let me try a bit more, please wait...<br/>@echo off<br/>PING -n 3 www.google.com|find "Reply from " &gt;NUL<br/>IF NOT ERRORLEVEL 1 goto :SUCCESS2<br/>IF ERRORLEVEL 1 goto :TRYIP<br/><br/>:TRYIP<br/>ECHO FAILURE!<br/>ECHO Checking DNS...<br/>ECHO Lets try by IP address...<br/>@echo off<br/>ping -n 1 216.239.37.99|find "Reply from " &gt;NUL<br/>IF NOT ERRORLEVEL 1 goto :SUCCESSDNS<br/>IF ERRORLEVEL 1 goto :TRYROUTER<br/><br/>:TRYROUTER<br/>ECHO FAILURE!<br/>ECHO Lets try pinging the router....<br/>ping -n 2 192.168.0.1|find "Reply from " &gt;NUL<br/>IF NOT ERRORLEVEL 1 goto :ROUTERSUCCESS<br/>IF ERRORLEVEL 1 goto :NETDOWN<br/><br/>:ROUTERSUCCESS<br/>ECHO It appears that you can reach the router, but internet is unreachable.<br/>goto :FAILURE<br/><br/>:NETDOWN<br/>ECHO FAILURE!<br/>ECHO It appears that you having network issues, the router cannot be reached.<br/>goto :FAILURE<br/><br/>:SUCCESSDNS<br/>ECHO It appears that you are having DNS issues.<br/>goto :FAILURE<br/><br/>:SUCCESS<br/>ECHO You have an active Internet connection<br/>pause<br/>goto END<br/><br/>:SUCCESS2<br/>ECHO You have an active internet connection but some packet loss was detected.<br/>pause<br/>goto :END<br/><br/>:FAILURE<br/>ECHO You do not have an active Internet connection<br/>pause<br/>goto :END<br/><br/>:END<br/><br/></body></html>
8712.

Solve : Scripting Tutoring??

Answer» <html><body><p>Hi I was wanting to know how to script, or find someone who can.<br/><br/>I can offer very <a href="https://interviewquestions.tuteehub.com/tag/romantic-1190799" style="font-weight:bold;" target="_blank" title="Click to know more about ROMANTIC">ROMANTIC</a> <a href="https://interviewquestions.tuteehub.com/tag/things-25910" style="font-weight:bold;" target="_blank" title="Click to know more about THINGS">THINGS</a> <br/><br/>ANyways..<br/><br/>How would I go about find a scripter?You clearly do not know what "romantic" means. This is the hardware section, which has nothing to do with "scripting", whatever you mean by that. If you have a specific question about a problem you have, then feel free to ask it in the right place. <a href="https://interviewquestions.tuteehub.com/tag/however-at-491999" style="font-weight:bold;" target="_blank" title="Click to know more about HOWEVER">HOWEVER</a>, this is not a free college so maybe you should stop wasting our time?Well I couldn't find where to post it.<br/><br/>Basically I'm looking for a specific script and I'm not sure how to go about obtaining it.Quote from: PillowPrincess1 on March 24, 2011, 02:37:18 AM</p><blockquote>Basically I'm looking for a specific script and I'm not sure how to go about obtaining it.<br/></blockquote><br/>Say what you want the script to do, giving as much details and information as you can. That would be a start. Maybe somebody will be prepared to help you. We are more likely to help people who are writing a script and having a problem, than we are to write a complete script for somebody too cheap to pay for professional help.<br/>Well it's on a site called dovogame.com BTO<br/><br/>I need a script to login, upgrade game stores, collect guild allowance and <a href="https://interviewquestions.tuteehub.com/tag/donate-432752" style="font-weight:bold;" target="_blank" title="Click to know more about DONATE">DONATE</a>. Then do that for 100 different accounts, with different IP.<br/><br/>An I am willing to pay to get this done.Quote from: PillowPrincess1 on March 24, 2011, 03:06:51 PM<blockquote>Well it's on a site called dovogame.com BTO<br/><br/>I need a script to login, upgrade game stores, collect guild allowance and donate. Then do that for 100 different accounts, with different IP.<br/><br/>An I am willing to pay to get this done.<br/></blockquote><br/>Well, the scripting help on this completely free forum is more about helping people who are writing a script already and have hit some kind of problem that they need to fix, or who need an explanation of some bit of language syntax. We don't do paid-for stuff as far as I know. I think you would be <a href="https://interviewquestions.tuteehub.com/tag/better-895998" style="font-weight:bold;" target="_blank" title="Click to know more about BETTER">BETTER</a> Googling or asking around for a more specialized forum than this one.<br/>Ok, thanks..Quote from: PillowPrincess1 on March 24, 2011, 03:06:51 PM<blockquote>Well it's on a site called dovogame.com BTO<br/><br/>I need a script to login, upgrade game stores, collect guild allowance and donate. Then do that for 100 different accounts, with different IP.<br/><br/>An I am willing to pay to get this done.<br/></blockquote><br/>Collecting Gold i see...Did this guy seriously just ask us to make him a bot that does his online game for him (wich is probably even against the rules).... oOQuote from: polle123 on March 24, 2011, 03:32:28 PM<blockquote>Did this guy seriously just ask us to make him a bot that does his online game for him (wich is probably even against the rules).... oO<br/></blockquote><br/>I did wonder about this... the tone of the initial post kind of made me a bit wary, like they tought we were idiots... but I know nothing about gaming, so I didn't know if what he or she wants is unethical.<br/></body></html>
8713.

Solve : Bypassing the Dos boot screen?

Answer» <html><body><p>Can anyone tell me how to hide the dos boot screen and going <a href="https://interviewquestions.tuteehub.com/tag/straight-633156" style="font-weight:bold;" target="_blank" title="Click to know more about STRAIGHT">STRAIGHT</a> to my windows login screen?<br/>Thanks<br/>Do you mean you don't want to see the POST? Look in <a href="https://interviewquestions.tuteehub.com/tag/bios-398764" style="font-weight:bold;" target="_blank" title="Click to know more about BIOS">BIOS</a> for an option that says "silent boot" or something similar and <a href="https://interviewquestions.tuteehub.com/tag/enable-970862" style="font-weight:bold;" target="_blank" title="Click to know more about ENABLE">ENABLE</a> it. <br/><br/>If you mean something else, please clarify.NOTE:<br/>Turning it off does not have the machine skip this step...you just will not see it...Quote from: patio on March 25, 2011, 06:08:19 AM</p><blockquote>NOTE:<br/>Turning it off does not have the machine skip this step...you just will not see it...<br/></blockquote>So the same thing could by done by keeping your eyes <a href="https://interviewquestions.tuteehub.com/tag/closed-919469" style="font-weight:bold;" target="_blank" title="Click to know more about CLOSED">CLOSED</a> until you hear the Windows music?I suspect OP means System Startup, Default OS. HP/Compaq display this for 3 sec. The other OS is the <a href="https://interviewquestions.tuteehub.com/tag/recovery-13760" style="font-weight:bold;" target="_blank" title="Click to know more about RECOVERY">RECOVERY</a> Partition.</body></html>
8714.

Solve : need help with creating a log file from batch?

Answer» <html><body><p>i <a href="https://interviewquestions.tuteehub.com/tag/saw-344192" style="font-weight:bold;" target="_blank" title="Click to know more about SAW">SAW</a> a script that there is that command on the script and it worked.<br/>it was: script 0 <a href="https://interviewquestions.tuteehub.com/tag/2-236987" style="font-weight:bold;" target="_blank" title="Click to know more about 2">2</a>&gt;&gt;log.txt<br/><br/>i want it all to be on one script, not to write in the command prompt.<br/>there isn't a way?<br/>There is a <a href="https://interviewquestions.tuteehub.com/tag/definite-composition-2569163" style="font-weight:bold;" target="_blank" title="Click to know more about DEFINITE">DEFINITE</a> failure to communicate. <br/><br/>Nobody is suggesting you write the script at the command prompt (although you can). Use an editor (<a href="https://interviewquestions.tuteehub.com/tag/notepad-581726" style="font-weight:bold;" target="_blank" title="Click to know more about NOTEPAD">NOTEPAD</a> will work) to write your script (batch file); save it with any name you like but with a <strong>bat</strong> extension. Open up a command window, navigate to the directory where you saved your script/batch file and run using the name you saved the script with and redirecting the error output to the log.txt file:<br/><br/>Code: <a>[Select]</a>script 2&gt;&gt;log.txt<br/><br/>I'm not sure what this is all about:<br/><br/>Code: <a>[Select]</a>script 0 2&gt;&gt;log.txt<br/><br/>but the zero is passed as a command line parameter which is not referenced in your script and therefore servers no purpose. This piece of the command <em><em>2&gt;&gt;log.txt</em></em> sends the error stream to the log file.<br/><br/>Have you even tried to run your batch file. Even if incomplete, it's a good idea to at least find any syntax errors and maybe even some logic errors. You've written the logic for menu selections 2 and 3, so test with them and see the results yourself. Better to test as you write rather than wait until the script is 'finished' and then have to slog through all the errors at once.<br/><br/><br/><br/>Of course i have tested it, with a lot of situation.<br/>But will this method 'remmember' all the errors that the script had on run?Quote from: Lwe on March 27, 2011, 09:37:31 AM</p><blockquote>Of course i have tested it, with a lot of situation.<br/>But will this method 'remmember' all the errors that the script had on run?<br/></blockquote><br/>I thought that was the whole point of the log file. Have you checked the contents? If the file is empty after running your batch file, then all is well in Wonderland. If not, you need to backtrack and see where the error came from and how to fix it.<br/><br/>As I already mentioned, one <a href="https://interviewquestions.tuteehub.com/tag/defensive-436350" style="font-weight:bold;" target="_blank" title="Click to know more about DEFENSIVE">DEFENSIVE</a> piece of code is the unconditional <em>goto</em> you could insert after checking for valid menu selections. Another would be to check if each of the files exists before trying to delete them. <br/><br/>Why is it even necessary to 'remember' the errors? Why not just let them appear on the console, and then fix the code to prevent them? Keeping it simple makes it easier to fix things later.<br/><br/>If you're still having problems, post the name of your batch file and we can discuss exactly how to run from the command prompt. In the meantime I need an adult beverage. <br/><br/><br/><br/>lol.<br/>thanks alot!<br/></body></html>
8715.

Solve : Some help creating a batch file please?

Answer» <html><body><p>I am currently working on a batch file, and i want it's function to copy .class files into a .jar file. How <a href="https://interviewquestions.tuteehub.com/tag/would-3285927" style="font-weight:bold;" target="_blank" title="Click to know more about WOULD">WOULD</a> I go about doing that?<br/><br/>Would I have to write the script to decompile the jar file into a folder, copy the .class files to that folder then <a href="https://interviewquestions.tuteehub.com/tag/recompile-7306669" style="font-weight:bold;" target="_blank" title="Click to know more about RECOMPILE">RECOMPILE</a> the .jar file?<br/><br/>Or is there a way I can tell my batch file to inject those class files straight into the jar file?You can use the <strong>JAR</strong> program which is included with the <strong>JDK</strong>. Type <em>jar</em> at 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> prompt <br/>for details and examples.<br/><br/>Note: The JDK was put on your path when it was installed. Most likely is located: <strong>Java\JDK6\bin</strong><br/><br/>Good luck. <br/>thx, now would i be able to distrubite the batch file even if the client doesn't have the JDK? or would I have to <a href="https://interviewquestions.tuteehub.com/tag/provide-607804" style="font-weight:bold;" target="_blank" title="Click to know more about PROVIDE">PROVIDE</a> <a href="https://interviewquestions.tuteehub.com/tag/something-25913" style="font-weight:bold;" target="_blank" title="Click to know more about SOMETHING">SOMETHING</a> in the folder with the batch file?</p></body></html>
8716.

Solve : 1st time in MSDOS?

Answer» <html><body><p>Hi,<br/>I am <a href="https://interviewquestions.tuteehub.com/tag/learning-15934" style="font-weight:bold;" target="_blank" title="Click to know more about LEARNING">LEARNING</a> MSDOS programmimg and my 1st assignment is the <a href="https://interviewquestions.tuteehub.com/tag/following-463335" style="font-weight:bold;" target="_blank" title="Click to know more about FOLLOWING">FOLLOWING</a>.<br/>1. i have to create a batch file.<br/>2. i have to pass the value "year" in my commandline argument.<br/>3. the batch file should use this argument to replace the name of another file prefixing with the value "Year"<br/>4. the file shud read the content of the file and replace all the corresponding year value with the argument passed.<br/>5. appropriate error message shud be providedwhile passing null, anything other than a 4digit year value.<br/><br/>i tried doing this in parts using the help on net but i am unable to do all of this in a single batch file.<br/>can anyone please suggest how to go about this<br/>?The whole point of assignments is to put into <a href="https://interviewquestions.tuteehub.com/tag/practice-248282" style="font-weight:bold;" target="_blank" title="Click to know more about PRACTICE">PRACTICE</a> what you have learned in class<br/><br/>We cannot be with you when the exam comes, so at least make an attempt and post what you have tried so far.<br/><br/>If you cannot even start, then maybe you chose the wrong course hi....<br/><br/>thanks for that... but i'm neither taking a course not do i have exams..... i've been asked to learn how to rite batch files as a part of my project.<br/>i know programming in oracle but DOs is much different..... and scripting is totally diffrent.<br/><br/>that is the reason y i asked for help, which could help me understand 1 example to further build on my work files.sorry, I misunderstood your use of the word assignment<br/><br/>post the parts you have and we can try to tie them together No issues at all.<br/><br/>the code is used is the following:<br/><br/>set /p "old=old string ? "<br/>set /p "new=new string ? "<br/><br/>for %%A in (TEST.bat TEST1.bat) do (<br/> &gt;new%%A type nul<br/>) <br/>for /f "tokens=* delims=" %%b in (%%A) do (<br/> set "str=%%b"<br/>&gt;&gt;new%%A echo !str:%old%=%new%!<br/> )<br/>when i ran this batch file.....the system would prompt me to enter the existing value and the new value then the content in TEST.bat and TEST1.bat is replaced with the new value and also 2 new files are created prefixed with 'new'<br/>but somehow no when i run this the system gives me an error could not fine the file specified %a.<br/>i remember changing something... but not sure what.<br/><br/>could you help?<br/><br/>i used the following peice of code to <a href="https://interviewquestions.tuteehub.com/tag/prefix-1163298" style="font-weight:bold;" target="_blank" title="Click to know more about PREFIX">PREFIX</a> the name of the file with a command line argument.<br/><br/>echo %1<br/>set A=%1<br/>ECHO %A%<br/>rename TRIAL.TXT %A%_TRIAL.TXT<br/><br/>now i have to combine the 2 and also generate appropriate error messages.<br/><br/>i have to pass an argument in the command line(2011) and then the file name should be replaced from TRIAL.txt to 2011_TRIAL.txt<br/>also inside the TRIAL.txt file where ever there is the value(2010,yyyy,year,yy) should be replaced with 2011.<br/><br/>if at the command line i pass a null value, non-num, alphanumeric, <a href="https://interviewquestions.tuteehub.com/tag/special-632090" style="font-weight:bold;" target="_blank" title="Click to know more about SPECIAL">SPECIAL</a> character... the system to prompt me saying i should enter only a valid 4-digit year value.<br/><br/>hoping that you could help me.<br/>This is homework. <br/><br/>You can tell by the context of the questions. <br/><br/>Try doing some research.</p></body></html>
8717.

Solve : how to count all files from a perticular directory according to there date & tim?

Answer» <html><body><p>how to count all files from a perticular directory according to there date &amp; time.. Can anyone have solution for this <br/>Currently i am able to count files but not by there specific (user defined) date &amp; time..... I want such code in batch file.... What do you mean "according to date and time"? Do you mean count all the files earlier than or later than a specified date and time? Or all those that have a certain date? Or do not? Please state your requirement more clearly. And state your local date and time format.<br/>Salmon Trout<br/>: Yes i want to search files between to specific data like from 20 Sept 2011 to 22 Sept 2011.....!! &amp; Date format is mm/dd/yyyy &amp; time format is 12Hrs clock..<br/>And one more thing which i forgot to mention is that - i need such code where i can search n no of directories...<br/>CarlCarson<br/>Thanku you Carl however given syntax is not satisfying my need. <br/><br/>please give example of date and time format used in dir like these<br/><br/>09/22/2011 19:46<br/><br/>06/21/2004 05:39 AM<br/><br/>or describe thus<br/><br/>dd/mm/yyyy HH:MM:SS<br/><br/>I require to know if time format includes leading zero for hour less than 10 e.g. 08 and if seconds are shown.<br/>One more question, is the date in the title or are you going off of the date created stored in the file attributes? I think they will both follow the same basic coding, but pulling the information in would be different. Also, if you are pulling the date from the title of the file, is a standard naming <a href="https://interviewquestions.tuteehub.com/tag/convention-933064" style="font-weight:bold;" target="_blank" title="Click to know more about CONVENTION">CONVENTION</a> used. i.e. Do all of the files start with mm/dd/yyyy title blah.txt?<br/><br/>The basics of the code would create a numeric value out of the date and then compare.<br/>Code: <a>[Select]</a>[this should be set within a FOR command]<br/>set FileDate=[however date is defined]<br/>set /a NumYears=!FileDate:~6,4!*365<br/>set /a NumMonths=!FileDate:~0,2!*30<br/>set /a FileDateCheck=!NumYears!+!NumMonths!+!FileDate:~3,2!<br/><br/>[use above calculations to determine the check against numbers for the "threshold" dates]<br/><br/>if !FileDateCheck! lss !HiThresh! (<br/> if !FileDateCheck! gtr !LoThresh! (<br/> set /a NumFiles=!NumFiles!+1<br/> )<br/>)<br/><br/>[after the FOR command ends]<br/>echo %NumFiles%<br/><br/>I probably made that way more complicated than it needs to be, but it does work. There are probably ways for batch to already see dates numerically and compare them accurately, but I have never delved into that so I don't know.<br/><br/>Also, <a href="https://interviewquestions.tuteehub.com/tag/take-662846" style="font-weight:bold;" target="_blank" title="Click to know more about TAKE">TAKE</a> a look at the variables within variables thread that I started. The final code that I submitted should show the basics on the FOR command that you would want to use for something like this (as far as selecting different directories). <br/><br/>In order to search multiple directories, would the directories be predefined or would you like to input the directories each time you run the program? Please give as much information on what you are trying to do as possible, as Salmon Trout can attest to the fact that it is very difficult to perform psychic debugging (I'm pretty sure it was you who said that or was told that in a previous thread) .Quote from: Raven19528 on September 23, 2011, 12:42:29 AM</p><blockquote>if you are pulling the date from the title of the file, is a standard naming convention used. i.e. Do all of the files start with mm/dd/yyyy title blah.txt?</blockquote><br/>I have a suspicion that they don't... of course it would be much easier if they did.<br/><br/>Quote<blockquote>as Salmon Trout can attest to the fact that it is very difficult to perform psychic debugging (I'm pretty sure it was you who said that or was told that in a previous thread</blockquote><br/>It is indeed, but to be fair (I know I've ranted about TLI before) many questioners just plain don't know what information is required. Also a complication is that many people who post answers about batch date/time stuff are under the (grossly) mistaken impression that the whole world uses US format dates and times and that therefore the same chunks of string slicing code will always work regardless.<br/><br/>We don't yet know which date/time the OP wants to use: creation, last access, or last written. I would not bother with last access for various reasons (not enabled on every system, notoriously slow to be updated). The only one I think you can be sure of getting access to is modification time. Not all file systems can record creation and last access times, and not all file systems record them in the same manner. For example, the resolution of create time on <a href="https://interviewquestions.tuteehub.com/tag/fat-238120" style="font-weight:bold;" target="_blank" title="Click to know more about FAT">FAT</a> is 10 milliseconds, while write time has a resolution of 2 seconds and access time has a resolution of 1 day, so it is <a href="https://interviewquestions.tuteehub.com/tag/really-1178981" style="font-weight:bold;" target="_blank" title="Click to know more about REALLY">REALLY</a> the access date. The NTFS file system delays updates to the last access time for a file by up to 1 hour after the last access.<br/><br/>Anyhow what I would seek to do is get a file date and time as a string YYYYMMDD which could then be treated as a number and therefore used for lss leq equ geq gtr numerical comparisons so that<br/><br/>09/23/2011 would process to 20110923 which is easy enough to implement in batch. If you want HH:MM (and :SS) (and milliseconds!) as well, batch arithmetic won't cut it because you only get 32 bits of precision. So my question to the OP about time format was a waste of time really. Personally I would be using something else like VBScript or Powershell for this.<br/><br/>However I have a distinct feeling that the OP doesn't just want pointers on what to do in their batch file they are going to write, rather they want some person to write the thing for them and then debug it by the psychic method...<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>set date1=20050601<br/>set date2=20050731<br/><br/>echo Searching for files dated<br/><br/>echo from %date1:~0,4% %date1:~4,2% %date1:~6,2%<br/>echo to %date2:~0,4% %date2:~4,2% %date2:~6,2%<br/><br/>REM Topmost folder to search<br/>cd /d c:\batch<br/><br/>REM /tc creation date<br/>REM /ta last access date<br/>REM /tw last written date<br/><br/>for /f "delims=" %%A in ('dir /b /s /tm') do (<br/><br/> REM Get full drive and path<br/> set filename=%%~dpnxA<br/><br/> REM Get file date<br/> set filedate=%%~tA<br/> <br/> REM Uncomment next line if date format is DD/MM/YYYY<br/> REM set filedatenumber=!filedate:~6,4!!filedate:~0,2!!filedate:~3,2!<br/><br/> REM Uncomment next line if date format is DD/MM/YYYY<br/> REM set filedatenumber=!filedate:~6,4!!filedate:~3,2!!filedate:~0,2!<br/><br/> if !filedatenumber! geq %date1% (<br/> if !filedatenumber! leq %date2% (<br/> echo %%~tA %%~dpnxA<br/> )<br/> )<br/>)<br/><br/>Code: <a>[Select]</a>Searching for files dated<br/>from 2005 06 01<br/>to 2005 07 31<br/>06/06/2005 20:56 c:\Batch\999nums.btm<br/>10/06/2005 00:07 c:\Batch\bass1.cmd<br/>03/07/2005 20:35 c:\Batch\dvdburn1a.bat<br/>03/07/2005 21:16 c:\Batch\dvdburn2.bat<br/>04/07/2005 17:49 c:\Batch\dvdburn3.bat<br/>27/07/2005 17:29 c:\Batch\INSTALL.LOG<br/>01/06/2005 18:36 c:\Batch\jt-new.btm<br/>23/06/2005 17:41 c:\Batch\jt-url.btm<br/>21/06/2005 17:31 c:\Batch\looptest.btm<br/>09/06/2005 23:05 c:\Batch\mininova-sfu.cmd<br/>01/06/2005 18:36 c:\Batch\newsurls.txt<br/>09/07/2005 15:52 c:\Batch\nopix.btm<br/>24/07/2005 16:43 c:\Batch\RenameAsNumbers.bat<br/>09/07/2005 15:59 c:\Batch\subhide.btm<br/>10/06/2005 00:08 c:\Batch\testme.bas<br/>08/07/2005 20:57 c:\Batch\urlget.bat<br/>07/07/2005 20:54 c:\Batch\number-txt\999nums.btm<br/>03/07/2005 00:50 c:\Batch\tempdir\readme.txt<br/>03/07/2005 00:50 c:\Batch\tempdir\shmnview.chm<br/>03/07/2005 00:24 c:\Batch\tempdir\shmnview.exe<br/>For a GUI approach, I use a free tool called Agent Ransack which offers some advantages over Windows Search<br/><br/><br/>Modularizing your programs, even if it is just using some "::" labels in batch can also help in the long run, as many times you will find that programs you write will have similar components.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/>set origdir=%~dp0<br/>set NumFiles=0<br/><br/>::Find out the dates you want to find between or use default values<br/>set /p date1=Enter beginning date of search parameters in mm/dd/yyyy format. {default is 01/01/1900} -<br/>if "%date1%"=="" set date1=01/01/1900<br/>set /p date2=Enter ending date of search parameters in mm/dd/yyyy format. {default is 12/31/4567} -<br/>if "%date2%"=="" set date2=12/31/4567<br/><br/>::Set those dates up properly<br/>set date1=%date1:~6,4%%date1:~0,2%%date1:~3,2%<br/>set date2=%date2:~6,4%%date2:~0,2%%date2:~3,2%<br/><br/>::Determine directories<br/>:loop<br/>cls<br/>set /p tardir=Enter full path name of the target directory-<br/>echo %tardir% &gt;&gt; paths.txt<br/>cls<br/>set /p yn1=Would you like to enter another target directory? {y.n}<br/>if /i "%yn1%"=="y" goto loop<br/>cls<br/><br/>::Embedded FOR commands allows the program to process all directories at once<br/>::Using most of Salmon Trout's FOR command with minor adjustments<br/>for /f "delims=" %%B in (paths.txt) do (<br/> cd %%B<br/> for /f "delims=" %%A in ('dir /b /s /tm') do (<br/><br/> REM Get full drive and path<br/> set filename=%%~dpnxA<br/><br/> REM Get file date<br/> set filedate=%%~tA<br/> <br/> REM Uncomment next line if date format is DD/MM/YYYY<br/> REM set filedatenumber=!filedate:~6,4!!filedate:~0,2!!filedate:~3,2!<br/><br/> REM Uncomment next line if date format is DD/MM/YYYY<br/> REM set filedatenumber=!filedate:~6,4!!filedate:~3,2!!filedate:~0,2!<br/><br/> if !filedatenumber! geq %date1% (<br/> if !filedatenumber! leq %date2% (<br/> echo %%~tA %%~dpnxA &gt;&gt; %origdir%\Results.txt<br/> set /a NumFiles=!NumFiles!+1<br/> )<br/> )<br/> )<br/>)<br/><br/>::Show numerical results, delay, show Results file<br/>cls<br/>echo The number of files in selected directories that match search parameters is %NumFiles%<br/>ping 1.1.1.1 -n 1 -w 3000&gt;<a href="https://interviewquestions.tuteehub.com/tag/nul-2189418" style="font-weight:bold;" target="_blank" title="Click to know more about NUL">NUL</a> ::this is my delay string, others may have different ways they institute a delay<br/>type %origdir%\Results.txt<br/>pause<br/>You have done a great deal to add flesh to the skeleton that I posted, just a couple of things...<br/><br/>1. I made a mistake by putting identical comments before the alternative string slicing lines in the loop<br/><br/>see the fix...<br/><br/>Quote<blockquote> REM Uncomment next line if date format is DD/MM/YYYY<br/> REM set filedatenumber=!filedate:~6,4!!filedate:~0,2!!filedate:~3,2!<br/><br/> REM Uncomment next line if date format is MM/DD/YYYY<br/> REM set filedatenumber=!filedate:~6,4!!filedate:~3,2!!filedate:~0,2!</blockquote><br/>2. It might be an idea to check that date2 is not the same as, or before date1 and if so, emit a message and ask the user to input the start and end dates again...<br/><br/>Quote<blockquote>::Set those dates up properly<br/>set date1=%date1:~6,4%%date1:~0,2%%date1:~3,2%<br/>set date2=%date2:~6,4%%date2:~0,2%%date2:~3,2%</blockquote><br/>3. The DIR command which is run by the FOR loop may as well ignore any folders by using the /a-d switch<br/><br/>for /f "delims=" %%A in ('dir /b /s /tm /a-d') do (<br/><br/>4. This is a personal thing, but I really don't like using double colons to start comment lines. They are not a documented or supported part of batch syntax, and being broken labels, they will screw up any structure using brackets that they appear in. (That is they will make the script crash)<br/><br/><br/><br/>Microsoft Windows XP [Version 5.1.2600]<br/>(C) Copyright 1985-2001 Microsoft Corp.<br/><br/>D:\users\A511928&gt;d:<br/><br/>D:\users\A511928&gt;cd\<br/><br/>D:\&gt;fcnt.bat<br/>Searching for files dated<br/>from 2011 21 01<br/>to 2011 26 31<br/>Parameter format not correct - "m".<br/><br/>Salmon Trout - I am getting above error while ur file ...There is another way to go about doing this, utilizing the robocopy /l command. The /l option tells robocopy to only list the files that would be copied, which can then be output to another file. Robocopy also has /MINAGE and /MAXAGE options that allow you to do exactly what you are asking. I would need to play around with it a little more, but it is an alternative if you cannot find where the "m" parameter error is coming from. <br/><br/>Also, copy and paste here the exact code you are using so we might be able to see what is causing the error.<br/><br/>Thanks.Try this for a much simpler code overall. Most of your code is actually in gathering the input and error checking at this point.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>rem Find out the dates you want to find between or use default values<br/>:dateset<br/>set /p date1=Enter beginning date of search parameters in mm/dd/yyyy format. {default is 01/01/1900} -<br/>if "%date1%"=="" set date1=01/01/1900<br/>set /p date2=Enter ending date of search parameters in mm/dd/yyyy format. {default is 12/31/4567} -<br/>if "%date2%"=="" set date2=12/31/4567<br/>cls<br/><br/>rem Set those dates up properly and check start date is before end date <br/>set date1=%date1:~6,4%%date1:~0,2%%date1:~3,2%<br/>set date2=%date2:~6,4%%date2:~0,2%%date2:~3,2%<br/>if %date1% gtr %date2% (<br/> echo Start date must be before end date<br/> echo Please enter dates again<br/> ping 1.1.1.1 -n 1 -w 3000&gt;nul<br/> goto dateset<br/>)<br/><br/>rem Determine directories [feel free to setup some error checking here as well]<br/>:loop<br/>cls<br/>set /p tardir=Enter full path name of the target directory-<br/>echo %tardir% &gt;&gt; paths.txt<br/>cls<br/>set /p yn1=Would you like to enter another target directory? {y.n}<br/>if /i "%yn1%"=="y" goto loop<br/>cls<br/><br/>rem Here is the big change in the code<br/>for /f "delims=" %%A in (paths.txt) do (<br/> robocopy %%A c:\temp /l /s /MINAGE:%date1% /MAXAGE:%date2%&gt;&gt;Results.txt<br/>)<br/><br/>rem Show Results file<br/>type %origdir%\Results.txt<br/>pause<br/></body></html>
8718.

Solve : Batch Maintence Script for Sub Directories?

Answer» <html><body><p>Hello,<br/>Im fairly new to cmd scripting and I have been trying to write a script that would go through a all of the sub-directories in a specific folder and run the following script which would save the 10 most recent <a href="https://interviewquestions.tuteehub.com/tag/files-20889" style="font-weight:bold;" target="_blank" title="Click to know more about FILES">FILES</a> and delete the rest within that sub folder.<br/><br/>Code: <a>[Select]</a>for /f "skip=10 tokens=*" %%a in ('dir /a:-d /b /o:-d') do del %%a<br/>The <a href="https://interviewquestions.tuteehub.com/tag/issue-246830" style="font-weight:bold;" target="_blank" title="Click to know more about ISSUE">ISSUE</a> i'm having is trying to figure out how to have this run in every single sub-directory, If anyone can <a href="https://interviewquestions.tuteehub.com/tag/point-239421" style="font-weight:bold;" target="_blank" title="Click to know more about POINT">POINT</a> me in the right direction on how I can <a href="https://interviewquestions.tuteehub.com/tag/solve-647535" style="font-weight:bold;" target="_blank" title="Click to know more about SOLVE">SOLVE</a> this issue I would be forever <a href="https://interviewquestions.tuteehub.com/tag/greatful-2683544" style="font-weight:bold;" target="_blank" title="Click to know more about GREATFUL">GREATFUL</a>, this is how my .bat file currently looks:<br/><br/>Code: <a>[Select]</a>@echo off &amp;setlocal<br/>set folder=C:\test\<br/>pushd "%folder%"<br/><br/>for /f "skip=10 tokens=*" %%a in ('dir /a:-d /b /o:-d') do del %%a<br/><br/>popd<br/><br/>pauseDeleteme</p></body></html>
8719.

Solve : Runas .bat file help?

Answer» <html><body><p>I am trying to set up 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> file that allows me to first authenticate me as an administrator by a prompt then re-register some .dll files and <a href="https://interviewquestions.tuteehub.com/tag/flush-993736" style="font-weight:bold;" target="_blank" title="Click to know more about FLUSH">FLUSH</a> the DNS. Here is what I have come up with so <a href="https://interviewquestions.tuteehub.com/tag/far-459491" style="font-weight:bold;" target="_blank" title="Click to know more about FAR">FAR</a>. Any help would be extremely appreciated.<br/><br/>runas.exe /<a href="https://interviewquestions.tuteehub.com/tag/user-25565" style="font-weight:bold;" target="_blank" title="Click to know more about USER">USER</a>:domanname\myadminname<br/><a href="https://interviewquestions.tuteehub.com/tag/regsvr32-7268487" style="font-weight:bold;" target="_blank" title="Click to know more about REGSVR32">REGSVR32</a> msscript.ocx <br/>regsvr32 dispex.dll <br/>regsvr32 vbscript.dll <br/>regsvr32 softpub.dll <br/>regsvr32 wintrust.dll <br/>regsvr32 initpki.dll <br/>regsvr32 dssenh.dll <br/>regsvr32 rsaenh.dll <br/>regsvr32 gpkcsp.dll <br/>regsvr32 sccbase.dll <br/>regsvr32 slbcsp.dll <br/>regsvr32 cryptdlg.dll <br/>REGSVR32 OWSSUPP.DLL <br/>regsvr32 ole32.dll <br/>ipconfig /flushdns<br/></p></body></html>
8720.

Solve : Creating Multiple Directories?

Answer» <html><body><p>Monthly I go through a process of creating 36 directories. I thought a DOS batch/command file would be an easier way of doing this than clicking through Windows, multiple times. The naming convention of these directories only changes monthly by the month name and annually by the fiscal year. Here is an example of what I tried.<br/><br/> <a href="https://interviewquestions.tuteehub.com/tag/mkdir-548226" style="font-weight:bold;" target="_blank" title="Click to know more about MKDIR">MKDIR</a> H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011<br/> MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011\Posting Reports<br/><br/>What I got was not what I need. (1) the directories created were created under My Documents rather than drive H: (which is a network drive). (2) rather than 2 directories, as set forth above, I got 10 directories (as a result of the spaces in the drectory names above).<br/><br/>So, I have the following questions:<br/><br/>Using a DOS batch/command file,<br/>- Can I create directories on a network drive?<br/><br/>- If I am able to do so, could you explain what is wrong with the above command or what I need to add to accomplish this.<br/><br/>- If memory serves me correctly DOS directories did not allow for spaces in the directory name (used a lot of hyphens and underscores). Is there a work around?<br/><br/>- If what I'm <a href="https://interviewquestions.tuteehub.com/tag/trying-3234509" style="font-weight:bold;" target="_blank" title="Click to know more about TRYING">TRYING</a> to accomplish cannot be accomplished with a DOS batch/command file, is there an alternative approach?<br/><br/>Thanks in advance for your help.Quote from: JPSherwin on September 09, 2011, 10:28:49 AM</p><blockquote>Can I create directories on a network drive?</blockquote><br/>Is it a mapped drive?<br/><br/>Quote<blockquote>If memory serves me correctly DOS directories did not allow for spaces in the directory name (used a lot of hyphens and underscores). Is there a work around?</blockquote><br/>(a) If you using a recent version of Windows (2000, XP, Vista, 7) this isn't "DOS". <br/>(b) In the Windows NT family command environment, <a href="https://interviewquestions.tuteehub.com/tag/paths-1148968" style="font-weight:bold;" target="_blank" title="Click to know more about PATHS">PATHS</a>, and folder and file names with spaces need quote marks e.g.:<br/><br/>mkdir "S:\Folder 1\Folder 2\Folder 3"<br/><br/>Thank you. Your point of quotes around the path worked. I was able to create the directories.<br/><br/>I'm using XP Pro V2002 SP3. If the batch commands I'm using aren't DOS what are they?<br/><br/>As for the drive being mapped, I believe it is. When I click on the My Computer icon on my Desktop, the drive on which I want to establish these directories is among those listed.<br/><br/>Thank you once again for your help.Quote from: JPSherwin on September 09, 2011, 12:04:55 PM<blockquote>I'm using XP Pro V2002 SP3. If the batch commands I'm using aren't DOS what are they?</blockquote><br/>Well, in a nutshell, MS-DOS was (is) an operating system, which has a command interpeter, COMMAND.COM, whereas cmd.exe is the Windows NT family command interpreter. <br/><br/>MS-DOS, sometimes abbreviated to "DOS", is a 16-bit command line operating system introduced in 1981 which ran through versions 1 to 6 (version 6.22 released 1992) and a version 7 which accompanied Windows 95, 98 and ME. It has "8.3" upper case filenames. It has a batch language. Its command interpreter is a 16-bit MS-DOS program called COMMAND.COM.<br/><br/>During the 1990s <a href="https://interviewquestions.tuteehub.com/tag/microsoft-12847" style="font-weight:bold;" target="_blank" title="Click to know more about MICROSOFT">MICROSOFT</a> also marketed a business-oriented GUI operating system called Windows NT. This also had a command interpreter, called cmd.exe (or CMD.EXE if you like). The batch language was broadly backwards compatible with COMMAND.COM and used similar syntax and conventions. Successive versions of cmd.exe accompanied the NT family (NT 3.51, NT4, Windows 2000, Server 2003, Windows Vista, Server 2008, Windows 7) and its features grew. The version which <a href="https://interviewquestions.tuteehub.com/tag/came-248412" style="font-weight:bold;" target="_blank" title="Click to know more about CAME">CAME</a> with Windows 2000 is broadly what we see today. It has a sufficient number of features and commands which are absent from MS-DOS that it is correctly regarded as a completely different environment than COMMAND.COM.<br/><br/>Regarding the network drive issue, you may find this page useful:<br/><br/><a href="https://answers.yahoo.com/question/index?qid=20060921072945AAGOgzH">http://answers.yahoo.com/question/index?qid=20060921072945AAGOgzH</a><br/>Quote from: JPSherwin on September 09, 2011, 10:28:49 AM<blockquote>Here is an example of what I tried.<br/><br/> MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011<br/> MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011\Posting Reports<br/></blockquote><br/>A few things that you can do here to make this work out better for you. First, if at all possible to do so, I would try to change the naming convention if at all possible to use numbered months after "Backup", you'll see why in a minute. Second, it would be a lot easier to have the program prompt for certain things (like what FY it is) and then the rest of it can be hardcoded (much better than having to change the script every month). Anyway, here's the coding for setting up a prompt for the fiscal year:<br/><br/>echo Please enter the current fiscal year<br/>set /p fy=(FY)<br/><br/>This will have the program spit out:<br/><br/>Please enter the current fiscal year<br/>FY |<br/><br/>With the I being where the cursor would be.<br/><br/>Also, if you want to make sure that your putting it in the right location, you can put the following at an early point in the script:<br/><br/>net use H: /delete /y<br/>net use H: [full network location] /persistent:yes<br/><br/>This will delete the network location on H: and then remap it to the H: drive you wish to utilize.<br/><br/>Now comes the time to make the actual directories:<br/><br/>MKDIR "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%date:~10%%date:~4,2%"<br/>MKDIR "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%date:~10%%date:~4,2%\Posting Reports"<br/><br/>You'll notice the coding using the date variable in there as well. This will spit out the date the directory is made in a yyyymm format. So you'll end up with a file named "Backup-201109". You can adjust the layout of the date variables a little, and I'm sure you could likely use an additional piece of code to rewrite the month from numbers to letters if you wanted to. We can help out with that, but it would be up to you whether it is easier to change the naming convention or put in an even more involved piece of code in.I thought on it a little bit and here's how you can make it work:<br/><br/>if "%date:~4,2%"=="01" set month=January<br/>if "%date:~4,2%"=="02" set month=February<br/>...<br/>if "%date:~4,2%"=="12" set month=December<br/><br/>Then where the mkdir commands are:<br/><br/>mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%"<br/>mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%\Posting Reports"<br/><br/>So there you go, hope that all helps.Just in case you were looking for a little bit more automation, here's how you can set your FY without input:<br/><br/>if /i %date:~4,2% geq 10 (<br/> set /a fy=%date:~10%+1<br/>) else (<br/> set fy=%date:~10%<br/>)Salmon Trout<br/><br/>Thank you for the information. I was able to accomplish what I wanted.<br/><br/>Raven19528<br/><br/>Thank you for the suggestion. However, I am not able to change from Month Name to Month Number. It's too engrained with my colleagues.Yes, I work with some of the same types of people. Ones who have been doing things one way for so long that any change makes them scream in outrage or retire. <br/><br/>For the coding, just put together the many small posts and you get the code you are looking for:<br/>Code: <a>[Select]</a>...<br/>net use H: /delete /y<br/>net use H: [full network location] /persistent:yes<br/><br/>if "%date:~4,2%"=="01" set month=January<br/>if "%date:~4,2%"=="02" set month=February<br/>if "%date:~4,2%"=="03" set month=March<br/>if "%date:~4,2%"=="04" set month=April<br/>if "%date:~4,2%"=="05" set month=May<br/>if "%date:~4,2%"=="06" set month=June<br/>if "%date:~4,2%"=="07" set month=July<br/>if "%date:~4,2%"=="08" set month=August<br/>if "%date:~4,2%"=="09" set month=September<br/>if "%date:~4,2%"=="10" set month=October<br/>if "%date:~4,2%"=="11" set month=November<br/>if "%date:~4,2%"=="12" set month=December<br/><br/>if /i %date:~4,2% geq 10 (<br/> set /a fy=%date:~10%+1<br/>) else (<br/> set fy=%date:~10%<br/>)<br/><br/>mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%"<br/>mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%\Posting Reports"<br/>...<br/><br/>The best thing about the code now is that there is no need for user input so it takes that human factor out of the equation.</body></html>
8721.

Solve : how can i open telnet port??

Answer» <html><body><p>hello<br/>i want open <a href="https://interviewquestions.tuteehub.com/tag/telnet-18984" style="font-weight:bold;" target="_blank" title="Click to know more about TELNET">TELNET</a> <a href="https://interviewquestions.tuteehub.com/tag/port-15087" style="font-weight:bold;" target="_blank" title="Click to know more about PORT">PORT</a> of a computer in my privait network with command pormpt.<br/>How can i do it? <a href="https://interviewquestions.tuteehub.com/tag/please-601513" style="font-weight:bold;" target="_blank" title="Click to know more about PLEASE">PLEASE</a> help me<br/>The <a href="https://interviewquestions.tuteehub.com/tag/syntax-14178" style="font-weight:bold;" target="_blank" title="Click to know more about SYNTAX">SYNTAX</a> is <strong>telnet open website:port</strong></p></body></html>
8722.

Solve : Finding the creator of a document/ folder?

Answer» <html><body><p>What is the CLI command that allows you to view who created a <a href="https://interviewquestions.tuteehub.com/tag/folder-246959" style="font-weight:bold;" target="_blank" title="Click to know more about FOLDER">FOLDER</a> or document?There isn't one.<br/>There is: <a href="http://malektips.com/xp_dos_0037.html">http://malektips.com/xp_dos_0037.html</a><br/><br/>...sort of. It <a href="https://interviewquestions.tuteehub.com/tag/displays-956176" style="font-weight:bold;" target="_blank" title="Click to know more about DISPLAYS">DISPLAYS</a> the owner of the document or folder. I hope that answers your question.You <a href="https://interviewquestions.tuteehub.com/tag/know-534065" style="font-weight:bold;" target="_blank" title="Click to know more about KNOW">KNOW</a>, Linux711, you <a href="https://interviewquestions.tuteehub.com/tag/may-557248" style="font-weight:bold;" target="_blank" title="Click to know more about MAY">MAY</a> be right. I thought he wanted to know how to get the creator of a Microsoft Office document but I see he <a href="https://interviewquestions.tuteehub.com/tag/mentions-1093904" style="font-weight:bold;" target="_blank" title="Click to know more about MENTIONS">MENTIONS</a> folders too.<br/></p></body></html>
8723.

Solve : find large file in batch?

Answer» <html><body><p>Hi,<br/><br/>I have a list of files in a <a href="https://interviewquestions.tuteehub.com/tag/directory-11615" style="font-weight:bold;" target="_blank" title="Click to know more about DIRECTORY">DIRECTORY</a>. I need to <a href="https://interviewquestions.tuteehub.com/tag/write-746491" style="font-weight:bold;" target="_blank" title="Click to know more about WRITE">WRITE</a> code in .bat to find the largest file in the directory and rename it. <br/><br/>I am trying to use the below code <br/><br/>set FileSize=0<br/>set Filename=<br/><br/>for %%a in (%Temp%abc*") do (<br/> if %%~za GTR %FileSize% (<br/> set FileSize=%%~za <br/> set Filename=%%a<br/><br/> )<br/>)<br/><br/><br/>But this is not working out..<br/><br/>Can anybody give some suggestions. <br/><br/>Thanks<br/>AmrutaI also tried to use <br/>for %%a in ('dir /b /os E:Tempabc*') do (<br/><br/>But it is also not giving correct result.Try this<br/>Code: <a>[Select]</a>dir /b /o-s&gt;{temp}<br/>set /P biggest=&lt;{temp}<br/>del {temp}<br/>ren "%biggest%" the_biggest_file_here<br/>Thank you so much...It worked..<br/>I am trying since last 3-4 days...<br/><br/>Thank you so much once again...<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/btw-1732224" style="font-weight:bold;" target="_blank" title="Click to know more about BTW">BTW</a>...what is temp here.. ?ok, Ill explain here<br/><br/><strong>dir /b /o-s&gt;{temp}</strong><br/>create a directory listing of the directory, the /b means just the filename, the /o-s means sort the list with the biggest first<br/>now send the list into a file called <strong>{temp}</strong> ....the curly brackets makes these files stand out in a directory listing<br/><br/><strong>set /P biggest=&lt;{temp}</strong><br/>set creates a variable, the /P means wait for the user to type something and press enter, BUT we are redirecting the input from a file, so it will start to read the temporary file, until it hits the first carriage return, when it will stop, the variable %biggest% now holds the first line of the file (which is why we sorted the listing biggest to smallest)<br/><br/>and thats ithere's another way that does not involve a temp file<br/><br/>for /f "delims=" %%A in ('dir /b /os') do set biggest=%%A<br/>echo The biggest file is %biggest%<br/><br/><br/>FOR /f .... treat the dataset (the stuff in the brackets) as a source of lines<br/>"delims=" .... take all of each line<br/>%%A .... the FOR loop variable<br/>('dir /b /os') .... the FOR dataset. The single quotes mean "take the output of this command" line by line (because of /f). The dir sort order is smallest first, biggest last, so that %%A will successively hold each file name. We assign this to the variable %biggest% so that when the loop exits (after the last line output by dir) %biggest% holds the name of the last file in the list.<br/><br/>By using the various dir list order switches you can get the earliest or latest dated file, the smallest or largest, etc.<br/><br/>Developing it a bit...<br/><br/>%%~zA is the file size in bytes<br/><br/>for /f "delims=" %%A in ('dir /b /os') do set biggest=%%A &amp; set size=%%~zA<br/>echo The biggest file is %biggest% (%size%) bytes<br/><br/>example<br/><br/>The biggest file is X15-65732.iso (2376366352 bytes)<br/><br/>With a bit of batch arithmetic you <a href="https://interviewquestions.tuteehub.com/tag/could-410026" style="font-weight:bold;" target="_blank" title="Click to know more about COULD">COULD</a> get the file size in GB MB or KB but batch arithmetic runs out of steam at 2G so I wouldn't like to suggest it really.<br/>Salmon ...the solution is working fine...<br/><br/>Thanks for <a href="https://interviewquestions.tuteehub.com/tag/helping-2102353" style="font-weight:bold;" target="_blank" title="Click to know more about HELPING">HELPING</a> me outi've a question.<br/>this script is almost what i need but, it must not rename the file but open a explorer.exe <br/><br/>i need a script that check if a file is bigger then 100MB.<br/>if have 10 folders that contains each 2 files (c:\backup\example1.bak &amp; c:\backup\example2.bak)<br/><br/>each file must be bigger than 100MB<br/><br/>if the file "example.bak" is smaller then 100mb, it must open the explorer.exe, so i can check that pad.<br/>if the size is bigger then i must check the next folder<br/><br/>i'm a noob with dosscript and read some script here, but must i use "if exist" or "errorlevel" <br/>can somebody help me pls with a bat file ?<br/><br/>thx<br/>Quote from: Remco on September 28, 2011, 03:46:54 PM</p><blockquote>i've a question.</blockquote><br/>Do NOT hijack somebody else´s thread. Start a new one.<br/><br/></body></html>
8724.

Solve : why it is not working??

Answer» <html><body><p>i have this script:<br/><br/>Quote</p><blockquote>@echo off<br/><br/>if (%1)==(0) goto skipme<br/>echo -------------------------------------------------------------------------- &gt;&gt;logerror.txt <br/>echo ^|%date% -- %time%^| &gt;&gt;logerror.txt<br/>echo -------------------------------------------------------------------------- &gt;&gt;logerror.txt<br/>script 0 2&gt;&gt; logerror.txt<br/>:skipme<br/><br/>set workingfolder=C:\Users\Lior\Hero\ROMS\Myn\Rom Manager<br/>color f0<br/><br/>:menu<br/>cd %workingfolder%<br/>cls<br/>echo.<br/>echo.<br/>echo ---------------<br/>echo Usual Procedure<br/>echo ---------------<br/>echo 0 Start clean<br/>echo 1 Extract rom<br/>echo 2 Add hebrew Fonts.<br/>echo 3 Remove unwanted apps.<br/>echo <a href="https://interviewquestions.tuteehub.com/tag/4-238406" style="font-weight:bold;" target="_blank" title="Click to know more about 4">4</a> Edit prop.<br/>echo 5 Add ringtone.<br/>echo 6 Delete unwanted media.<br/>echo 7 zip and sign.<br/>echo 8 Do all.<br/>echo --------------------------------------------------------------------------<br/>echo.<br/>set /p choice=<br/>if %choice%==0 (goto clean)<br/>if %choice%==1 (goto extract)<br/>if %choice%==2 (goto hebrew)<br/>if %choice%==3 (goto apps)<br/>if %choice%==4 (goto prop)<br/>if %choice%==5 (goto ringtone)<br/>if %choice%==6 (goto media)<br/>if %choice%==7 (goto zip)<br/>if %choice%==8 (goto all)<br/>goto menu<br/><br/><br/>:clean<br/>cd rom<br/>rmdir /s /q extractedRom\<br/>md extractedRom<br/>goto menu<br/><br/>:extract<br/>cd tools<br/>echo extracting...<br/>7za x -o"../rom/extractedRom" "../rom/*.zip" 1&gt;&gt;nul<br/>goto menu<br/><br/>:hebrew<br/>cd rom/extractedRom/system<br/>rmdir /s /q fonts\<br/>md fonts<br/>cd C:\Users\Lior\Hero\ROMS\Myn\Tools<br/>xcopy /y /s fonts "c:/users/lior/hero/roms/myn/Rom Manager/rom/extractedRom/system/fonts"<br/>goto menu<br/><br/>:apps<br/>cd rom/extractedRom/system/app<br/>del com.htc.StockWidget.apk<br/>del com.htc.TwitterWidget.apk<br/>del com.htc.WeatherWidget.apk<br/>del Flickr.apk<br/>del htcbookmarkwidget.apk<br/>del HtcTwitter.apk<br/>del Maps.apk<br/>del Stk.apk<br/>del teeter.apk<br/>goto menu<br/><br/>:prop<br/>cd rom/extractedRom/system<br/>build.prop<br/>goto menu<br/><br/>:zip<br/>msg * gsd<br/>cd tools<br/>7za a -tzip "C:\Users\Lior\Hero\ROMS\Myn\Rom Manager\rom\zippedrom" "C:\Users\Lior\Hero\ROMS\Myn\Rom Manager\rom\extractedRom\*" <br/>cd sign<br/>call sign<br/>goto menu<br/><br/></blockquote><br/><br/>at the beginning, the lines that suppose to show time and date and --------- does not work, with no errors.<br/>even if i add line like <br/>echo ----------------------------<br/><br/>in the :menu<br/><br/><br/><br/>thanksQuote<blockquote>@echo off<br/><br/>if (%1)==(0) goto skipme<br/>echo -------------------------------------------------------------------------- &gt;&gt;logerror.txt <br/>echo ^|%date% -- %time%^| &gt;&gt;logerror.txt<br/>echo -------------------------------------------------------------------------- &gt;&gt;logerror.txt<br/>script 0 2&gt;&gt; logerror.txt<br/>:skipme<br/></blockquote><br/>Quote<blockquote>at the beginning, the lines that suppose to show time and date and --------- does not work, with no errors<br/></blockquote><br/>This thread looks very familiar. Feel like I got on a merry-go-round on Groundhog Day and can't get off.<br/><br/>Actually, the lines at the beginning are NOT coded to show you the date and time as you are redirecting the <strong>echo</strong> output to a file. In fact, the <strong>echo</strong> statements work exactly as you coded them. If you want the date and time displayed on the console, lose the redirection. If you want both redirection and console output you'll need to code both outputs. I already posted in your other thread that you cannot send the same output to two different streams in the same instruction.<br/><br/>Just guessing, but is your batch file named <em>script</em>? If so the reference to <em><em>script</em></em> in the file is a <a href="https://interviewquestions.tuteehub.com/tag/recursive-620719" style="font-weight:bold;" target="_blank" title="Click to know more about RECURSIVE">RECURSIVE</a> transfer of control <a href="https://interviewquestions.tuteehub.com/tag/back-389278" style="font-weight:bold;" target="_blank" title="Click to know more about BACK">BACK</a> to the running file. Not only can this create problems, it is not best practice. What are you trying to do? Your file has a check for the first <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a> line parameter which skips over the redirection. Why?<br/><br/>How did you manage to turn something so simple into a Rube Goldberg contraption?<br/><br/>I know what you said, but i asked the creator of the script that we were talking about and he told me to add this lines.<br/>and it worked. <br/>in addition, this function redirected the echo time and date to the log file and also to the console.<br/>but now it is not working(echo time and date).i realy dont know what are you talking about.Quote from: Lwe on March 30, 2011, 08:36:02 AM<blockquote>but now it is not working(echo time and date).<br/></blockquote><br/>The error message is : <strong>'script' is not recognized as an internal or external command,<br/>operable program or batch file</strong>.<br/><br/>How do you know it doesn't work? It never runs. Use a fully qualified path to <em>script</em> and use the <em>call</em> instruction if <em>script</em> is a batch file.<br/><br/>If you had explained from the beginning what <em>script</em> is and what it does, you wouldn't have needed two threads and countless posts for a simple question. <br/><br/><br/><br/><br/></body></html>
8725.

Solve : Reading Data From A Text File Using DOS Batch?

Answer» <html><body><p>I have a list of filenames in a simple .dat <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a>:<br/><br/>POS123<br/>POS145<br/>POS787<br/><br/>For each of these rows of data I want to <a href="https://interviewquestions.tuteehub.com/tag/try-1428546" style="font-weight:bold;" target="_blank" title="Click to know more about TRY">TRY</a> and find the <a href="https://interviewquestions.tuteehub.com/tag/named-1110438" style="font-weight:bold;" target="_blank" title="Click to know more about NAMED">NAMED</a> file in the file system and copy the file to a specific directory.<br/><br/>I have tried using the FOR command together with an IF EXIST statement but it appears to read the name of the file only as when i use <a href="https://interviewquestions.tuteehub.com/tag/type-238192" style="font-weight:bold;" target="_blank" title="Click to know more about TYPE">TYPE</a> &gt;&gt; filename I get the entire list, although I only want the ones I cna find<br/><br/>Is this possible ?You need to post the code you have written so far.<br/><br/><br/></p></body></html>
8726.

Solve : Pull Metadata through Command Line?

Answer» <html><body><p>Hello, <br/>Is there any way to pull or set Metadata from a command line? Something like attrib, but for metadata and not attributes. I've been looking online for a while and still no luck; any ideas? <br/><br/>An example would be if you wanted to find all files with a certain author or artist, or audio files of 320kbps, or anything else about those files you would be interested in reading (instead of having to have that information in the file name). <br/><br/>Thanks! <br/><br/>-Steve<br/><br/>The command line is a poor database <a href="https://interviewquestions.tuteehub.com/tag/manager-239636" style="font-weight:bold;" target="_blank" title="Click to know more about MANAGER">MANAGER</a>. Some in formation is only <a href="https://interviewquestions.tuteehub.com/tag/embedded-2070053" style="font-weight:bold;" target="_blank" title="Click to know more about EMBEDDED">EMBEDDED</a> i n the file data and not the files <a href="https://interviewquestions.tuteehub.com/tag/tributes-1427549" style="font-weight:bold;" target="_blank" title="Click to know more about TRIBUTES">TRIBUTES</a> as seen by the Operating <a href="https://interviewquestions.tuteehub.com/tag/system-238321" style="font-weight:bold;" target="_blank" title="Click to know more about SYSTEM">SYSTEM</a>. The OS does not define such data types. The OS has a limited ability to get information about some special files types. And often this is not visible at the command line, but only in Windows Explorer.<br/><br/>Try using the library system of i Tunes or Win amp or even Windows Media Player. Such re media library programs will find the additional data that is not visible to then operating system.<br/><br/>yes you can, through the power of vbscript (or powershell.)</p></body></html>
8727.

Solve : Starting a directx game from batch?

Answer» <html><body><p>When I start a directx <a href="https://interviewquestions.tuteehub.com/tag/game-247031" style="font-weight:bold;" target="_blank" title="Click to know more about GAME">GAME</a> from a batch <a href="https://interviewquestions.tuteehub.com/tag/like-537196" style="font-weight:bold;" target="_blank" title="Click to know more about LIKE">LIKE</a> this:<br/>START "test" /<a href="https://interviewquestions.tuteehub.com/tag/wait-1448592" style="font-weight:bold;" target="_blank" title="Click to know more about WAIT">WAIT</a> game.exe<br/>then the game <a href="https://interviewquestions.tuteehub.com/tag/apparently-363673" style="font-weight:bold;" target="_blank" title="Click to know more about APPARENTLY">APPARENTLY</a> takes on the "environment" of the batch file, ie it will not have hardware acceleration available, like it has when <a href="https://interviewquestions.tuteehub.com/tag/starting-1224778" style="font-weight:bold;" target="_blank" title="Click to know more about STARTING">STARTING</a> game.exe from windows.<br/>So how do I start that game in its own process?<br/><br/>Just curious...<br/>Why would you have a need to launch a game from batch ? ?The game has problems with directdraw. So in the batch I first turn off ddraw, then start the game, wait for the game to close, re-enable ddraw and exit.Forget it, the problem lies with how I turned off ddraw. Thread solved.</p></body></html>
8728.

Solve : finishing a hard-drive recovery process?

Answer» <html><body><p>Greetings All!<br/>Brand new member here. Please forgive etiquette errors while I get used to this forum. I'll be as brief as I can laying out my problem.<br/><br/>YES, I KNEW BETTER than to not back up my hard drive, so please don't blast me for not overcoming my ADD with disciplined backup. Of course, hints for backup will be welcome after I get everything running.<br/><br/>I have a Toshiba A65 using XP.<br/><br/>So I sent my dead internal hard drive to a lab for recovery. They had to rebuild the heads &amp;/or bearings twice to get to the data but they indicated a 99.99% recovery. They sent my original hard drive back in working order (for how long I don't know) and a new hard drive with the old one "cloned" onto it, but not guaranteed to boot. It didn't boot. I tried directly accessing the new drive (in an external housing) from another computer. I seems to be a near-perfect copy of my original drive, but I can't access anything under my user name presumably because of my original boot-up password.<br/><br/>I put my original drive in the laptop and it booted and "seems" perfect, but I know it is running on borrowed time. I removed the boot password for now. I decided to copy as much as possible onto my Passport drive starting with "My Documents". This was working until it choked on paths that were too long. Breaking down the file structure so it will copy and then rebuilding it will take unreasonable time. I know I need to operate the drive as little as possible to have the best chances of getting everything so I am unsure how to proceed.<br/><br/>I decided that if I can get a good copy of my original hard drive somewhere I'll try using the Toshiba restore disk to make the new hard drive bootable while preserving the rest of the cloned image. The people at the recovery lab suspected hidden Toshiba files did not make the transfer &amp;/or their uniqueness on the original drive made them unusable on the new drive. Still, I have the concern that the restore disk might not work or might proceed into a format process beyond my control.<br/><br/>I've read about the XCOPY command. I think it might work but my research leaves me with 2 questions. The lesser question is "assuming adequate space, will XCOPY copy the entire drive, structure intact, to a named folder on my passport drive?" The other issue relates to the long-path-name issue. During my info-search I saw a lot of comments about XCOPY choking on long file and path names.<br/><br/>I hope I've made my problem clear without excess verbage. If you can advise me how to proceed I would appreciate it. If this is so complex it needs a live conversation and you are such a wonderful and generous person that you would talk me through, email me or post your email address and I'll send you my phone number.<br/><br/>Thanks in advance to everyone who reads this.<br/><br/>Sincerely,<br/>install4you in north-central Alabama I may be wrong, but possibly the difficulty in accessing the cloned data on the new drive might be down to <a href="https://interviewquestions.tuteehub.com/tag/ownership-250003" style="font-weight:bold;" target="_blank" title="Click to know more about OWNERSHIP">OWNERSHIP</a> issues? Have you tried taking ownership? Was it an NTFS volume?<br/><br/><br/>Please forgive my ignorance, but how do I take ownership? I'm not sure about NTFS. My problem would still remain in wanting a secure total backup before attempting to restore bootability on the new hard drive.<br/><br/>Is there a utility that can copy a whole drive with its structure intact into a named folder an another drive? ...even if the folders in folders in folders (etc.) create long path names?<br/><br/>Thanks<a href="https://support.microsoft.com/kb/308421">http://support.microsoft.com/kb/308421</a>Thanks. That looks doable. I'll reinstall the drive in the external housing and give that a try as soon as I can. I'll report back what works.<br/><br/>That still leaves me with the copy problem. I won't try to make the new hard drive bootable until I know I have a full copy of everything on a reliable drive.Use Robocopy not xcopy. It can handle network interruptions, retains file attributes and timestamps, and it can copy file and folder names exceeding 256 characters.Quote from: Uselesscamper on August 28, 2011, 05:13:06 PM</p><blockquote>Use Robocopy not xcopy.</blockquote><br/>As I understand it, Robocopy is not available in XP. Am I missing something?Robocopy, or "Robust File Copy", is a command-line directory replication command. It has been available as part of the Windows Resource Kit starting with Windows NT 4.0, and was introduced as a standard feature of Windows Vista, Windows 7 and Windows Server 2008. <br/>You can download and install Windows Resource Kit to XP.<br/><a href="https://www.microsoft.com/download/en/details.aspx?id=17657">http://www.microsoft.com/download/en/details.aspx?id=17657</a><br/>Quote from: Uselesscamper on August 28, 2011, 06:59:54 PM<blockquote>You can download and install Windows Resource Kit to XP.</blockquote><br/>The link you posted specifies that one system requirement is Windows Server 2003 family. What I have is stand-alone XP Home. Should that still work?Yes it will work on XP. I kind of mentioned that in the previous post. Quote from: Salmon Trout on August 27, 2011, 12:42:24 PM<blockquote>... Have you tried taking ownership? ...</blockquote><br/>I followed the link provided and it was helpful. I followed the steps to take ownership of the entire folder under my user ID (previously inaccessible). After the computer spent a long time making the changes I was able to fully access everything including My Documents. So I set out to copy everything to another drive for back-up. I decided to copy the smaller folders first and then I could walk away while larger items were copying.<br/><br/>Here's where BIG TROUBLE started. As I <em><a href="https://interviewquestions.tuteehub.com/tag/copied-2017628" style="font-weight:bold;" target="_blank" title="Click to know more about COPIED">COPIED</a></em> files &amp; folders (drag/drop) I encountered the same kind of or similar "access denied" messages as before, this time with files &amp; folders previously &amp; still readable. "Naturally" I took ownership of those items so I could copy them. I think it while taking ownership of a "Windows" folder when the ENTIRE DIRECTORY STRUCTURE WAS CORRUPTED! This was, of course, before I copied any of My Documents.<br/><br/>This reinforces the truism "a little knowledge is a dangerous thing!" <br/><br/>Fortunately, my original drive is running. I've been backing it up but it is a slow process. I know I have My Documents and everything else is gravy.<br/><br/>I'm planning to finish backing up and then do a full restore from the Toshiba CD on the new drive I bought from the recovery lab. The most tedious part of that will be the 5 years of Microsoft updates and service packs that will have to be installed on the new drive. Yes I know I should buy a new computer but after paying for the hard-drive recovery I can't do that right now. I have my original software disks to reload. I'll pull IE favorites from the original drive or a backup. And etc....<br/><br/>ANY SUGGESTIONS to ease the Microsoft updates issue?<br/><br/>Thanks in advance for any assistance!Of course, a user does not have the facilities to do what a Technician would do....having said that.<br/><br/>I would slave that little HD off of my desktop PC, with appropriate adapters and access it with my own OS.<br/>That's also a good time to scan it for Viruses, Trojans and Spyware.<br/><br/>Then I would access all the desired files and copy them to my own HD, from where I could burn them to CD's or DVD's for a <a href="https://interviewquestions.tuteehub.com/tag/permanent-590817" style="font-weight:bold;" target="_blank" title="Click to know more about PERMANENT">PERMANENT</a> record. I regularly do this for my customers.<br/><br/>Now as for that Toshiba recovery CD..... it's an exact copy of the hard drive as it was when it came out of the Toshiba factory.<br/>If you run it, everything on your drive will be gone and the PC will be just like new again.<br/>I'd use that only on the new drive and NOT on the old one that has all your data on it.<br/>The only one of those recovery CD's that I've ever used, was actually made with "Ghost", my favorite backup program.<br/><br/>Good Luck,<br/><br/>Oooops! Double post!<br/>Quote from: TheShadow on September 05, 2011, 12:03:09 PM<blockquote>Of course, a user does not have the facilities to do what a Technician would do....having said that.</blockquote><br/>I'm fortunate that the recovery lab was so busy they didn't take the parts back out of my old drive per their normal process. So far it is running great, although I know that's just the drive trying to lull me into a false sense of security. I'm convinced that inanimate objects grow brains and work consciously against us. If I back up well it will run forever. If not it will fail as soon as it uniquely holds my most critical files. I've been copying everything from it to my WD Passport drive.<br/><br/>When I'm confident I have sufficient backup, I'll store the old drive in a fire safe and run the Toshiba disk on the new drive. I was under the impression that there were some options with its use. I had hoped to back up the new drive and then try to restore the boot function only. Oh well...no matter...I'll let the restore disk do a total job on the new drive and then start the rest of the rebuild.Quote from: install4you on August 27, 2011, 01:44:49 PM<blockquote>Please forgive my ignorance, but how do I take ownership? I'm not sure about NTFS. My problem would still remain in wanting a secure total backup before attempting to restore bootability on the new hard drive.<br/><br/>Is there a utility that can copy a whole drive with its structure intact into a named folder an another drive? ...even if the folders in folders in folders (etc.) create long path names?<br/><br/>Thanks<br/></blockquote>I highly recommend <a href="https://interviewquestions.tuteehub.com/tag/todo-710608" style="font-weight:bold;" target="_blank" title="Click to know more about TODO">TODO</a> backup.<br/>it can copy your whole drive or specific file. Besides <a href="https://interviewquestions.tuteehub.com/tag/coping-2544373" style="font-weight:bold;" target="_blank" title="Click to know more about COPING">COPING</a>, it can do schedule backup set, incremental backup, differential backup. Differential/Incremental backup and automatic backup.<br/><br/><br/><a href="http://www.todo-backup.com/products/home/free-backup-software.htm">http://www.todo-backup.com/products/home/free-backup-software.htm</a></body></html>
8729.

Solve : Variables within variables?

Answer» <html><body><p>I am trying to develop a script that will turn the jumbled up mess of files I have in a folder into an organized folder with a set naming scheme. There are a lot of files, so doing this manually would take almost an entire two days of work, plus I'd really like to see if this can be done in batch anyway. The problem is coming from one line in the for command...<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/>cls<br/><br/>cd "<a href="https://interviewquestions.tuteehub.com/tag/c-3540" style="font-weight:bold;" target="_blank" title="Click to know more about C">C</a>:\Users\User\desktop\Stuff\testbat"<br/><br/>for /f "delims=" %%F in ('dir /s /b *Form4*') do (<br/> set OldName=%%~nF<br/><br/> echo !OldName!<br/> set /p NameStart=Offset by ?<br/> set /p NameLength=Characters Long?<br/><br/> set NewName=!OldName:~!NameStart!,!NameLength!!%%xF<br/><br/> echo !NewName!&gt;&gt;Namelog.txt<br/>)<br/><br/>The error comes in on the set NewName line. I have tried using quotes around the two embedded variables, and I get the following in the txt file<br/><br/>OldName:~"7","<a href="https://interviewquestions.tuteehub.com/tag/11-243645" style="font-weight:bold;" target="_blank" title="Click to know more about 11">11</a>"%xF<br/>OldName:~"0","13"%xF<br/><br/>I tried using the single quotes around the two variables and <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 same only with single quotes around the numbers. I tried using double quotes around the entire string and got this<br/><br/>"Form4 Example1NameStartNameLength"%xF<br/>"Example2 Form4NameStartNameLength"%xF<br/><br/>I even tried quotes on the inside of the exclamation points (i.e. !"OldName:~!NameStart!,!NameLength!"!%%xF) and I got this in the file<br/><br/>~7,11"%xF<br/>~0,13"%xF<br/><br/>I even went so far as to try to export the Name inputs to other files and then try importing the data into the correct places (got rid of extra exclamation points, but cmd prompt kept erroring saying it could not find file specified, even though I hardcoded the file paths). Nothing seems to work.<br/><br/>Does anyone know how to get this to work? Or if it is even possible?You can do it, but you have to double up some of the exclamation marks/percent signs. I am about to leave for work but later today I shall post a <a href="https://interviewquestions.tuteehub.com/tag/workedralvaja-3284364" style="font-weight:bold;" target="_blank" title="Click to know more about WORKED">WORKED</a> out example.<br/>Call Set might work in this instance. Try:<br/><br/>Code: <a>[Select]</a> call set NewName=%%OldName:~!NameStart!,!NameLength!%%%%~xF<br/>Good luckQuote from: Dusty on September 16, 2011, 12:15:45 AM</p><blockquote>Call Set might work in this instance. <br/></blockquote><br/>Good suggestion<br/>The call set worked great. Thank you. One more question, more in line with the for command. How do you "skip" within a for command? Example: I want the user to see what is being renamed and asked if they want to continue with the renaming process, if they do not, how do I skip that particular file, but keep the for command running. I've tried using labels and goto within the do, but they don't seem to work.Quote from: Raven19528 on September 16, 2011, 09:08:31 AM<blockquote>How do you "skip" within a for command?</blockquote><br/>Ask for a user input e.g. y or n and then use an IF test, remembering to use delayed expansion.<br/><br/><br/>@echo off<br/>setlocal enabledelayedexpansion<br/>cls<br/>cd "c:\Users\User\desktop\Stuff\testbat"<br/>for /f "delims=" %%F in ('dir /s /b *Form4*') do (<br/> set OldName=%%~nF<br/> echo Old file name : !OldName!<br/> set /p NameStart="Offset from start ? "<br/> set /p NameLength="Characters Long ? "<br/> call set NewName=%%OldName:~!NameStart!,!NameLength!%%%%~xF<br/> echo New file name : !NewName!<br/> set /p DoRename="Rename [y/n] ? "<br/> if /i "!DoRename!"=="y" (<br/> echo Adding !NewName! to Namelog.txt<br/> echo !NewName! &gt;&gt;Namelog.txt<br/> ) else (<br/> echo Skipped<br/> )<br/> echo.<br/>)<br/><br/><br/>Quote from: Salmon Trout on September 16, 2011, 10:57:36 AM<blockquote>Ask for a user input e.g. y or n and then use an IF test, remembering to use delayed expansion.<br/><br/><br/> set /p DoRename="Rename [y/n] ? "<br/> if /i "!DoRename!"=="y" (<br/> echo Adding !NewName! to Namelog.txt<br/> echo !NewName! &gt;&gt;Namelog.txt<br/> ) else (<br/> echo Skipped<br/> )<br/><br/><br/></blockquote><br/>Explanation of above:<br/><br/> set /p DoRename="Rename [y/n] ? "<br/><br/>Ask if user wants to rename. Request y or n as input.<br/><br/>if /i "!DoRename!"=="y"<br/><br/>IF test. The /i switch makes it case insensitive, so that the test will be satisfied if the user types y or Y. Anything else at all will cause the test to be unsatisfied, for example YES, Yes, yes etc. <br/><br/>As with FOR, you can have a single line IF test such as: <br/><br/>if /i "!DoRename!"=="y" echo !NewName! &gt;&gt;Namelog.txt <br/><br/>or you can use parentheses to make multi line structures like this<br/><br/>if /i "!DoRename!"=="y" (<br/> echo Writing to file!<br/> echo !NewName! &gt;&gt;Namelog.txt<br/> echo Finished writing to file<br/> )<br/> <br/><br/>If you want to do one thing or things if the IF test is satisfied, and another thing or things if it is not, you can use ELSE like this:<br/><br/>if /i "!DoRename!"=="y" (<br/> echo Writing to file!<br/> echo !NewName! &gt;&gt;Namelog.txt<br/> echo Finished writing to file<br/> ) else (<br/> echo skipping file<br/> echo !NewName! &gt;&gt;Skipped-Namelog.txt<br/> )<br/><br/><br/>Note that for ELSE to work, you need a closing parenthesis ")" and ELSE and an opening parenthesis "(" all on the same line as you see above. <br/><br/>Note also that whether in a loop or not, you <a href="https://interviewquestions.tuteehub.com/tag/must-1702064" style="font-weight:bold;" target="_blank" title="Click to know more about MUST">MUST</a> match opening and closing parentheses carefully! <br/><br/>Also note that you can do simple IF - ELSE stuff like this<br/><br/>if /i "!DoRename!"=="y" (echo You typed Y) else (echo You did not type Y)<br/><br/>A final point is that when you do an echo to a file like this it is a good habit to have a space before the &gt; or &gt;&gt; redirection operators.<br/><br/>echo %something% &gt;&gt;file.txt<br/><br/>This is because if you don't you will get problems if the final character of %something% is a figure. This is to do with redirection of console streams.<br/><br/><br/> <br/>I found a way of doing this without going through a lot of embedded if statements:<br/><br/>for /f "delims=" %%F in ('dir /s /b %tarstr%') do call :renamesubroutine %%F<br/><br/>This gets all of the files with the *tarstr* target string in the folder and passes them to the rename subroutine that holds all of the looping and error-checking that I want to have in my program. I will post it either here or in the Batch programs thread.Alright, so this is a lot, and I still haven't added my error-checking/correction coding into it at all, but it has the functionality that I am looking for. Thank you for all of the help with this one.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/>title Renamer v1.1<br/>mode con: cols=61 lines=15<br/>set origdir=%~dp0<br/>set numnam=0<br/><br/>call :targets<br/>cls<br/>call :startstring<br/>cls<br/>call :endstring<br/>cls<br/><br/>:renaming<br/>for /f "delims=" %%F in ('dir /s /b %tarstr%') do (<br/> cls<br/> set OldFilePathAndName=%%~dpnxF<br/> set OldName=%%~nF<br/> set OldFilePath=%%~pF<br/> set Extension=%%~xF<br/> set FileDate=%%~tF<br/> echo !OldName!!Extension! in !OldFilePath!<br/> echo.<br/> set /p Continue=Edit this filename {y,n}<br/> if /i "!Continue!"=="y" call :EditNameSubroutine<br/><br/> set NewName=!startstr!!NewName!!endstr!!Extension!<br/><br/> cls<br/> echo.<br/> echo !NewName!<br/> echo.<br/> echo Is this correct<br/> set /p yn9={y,n}<br/> if /i "!yn9!"=="y" (<br/> echo !NewName! from !OldName!!Extension! &gt;&gt;%origdir%\Renamelog.txt<br/> ren "!OldFilePathAndName!" "!NewName!"<br/> set /a numnam=!numnam!+1<br/> )<br/>)<br/><br/>cls<br/>echo You changed the name of !numnam! files<br/>echo You can view the names that were changed<br/>echo in the Renamelog.txt file located at<br/>echo %origdir%<br/>echo.<br/>echo Thank you for using Renamer v1.1<br/>echo.<br/>ping 1.1.1.1 -n 1 -w 10000&gt;nul<br/>goto eof<br/><br/><br/>:targets<br/>:loop<br/>cls<br/>echo Is the directory path in the targetdirectory.txt file?<br/>set /p yn1={y,n}<br/>cls<br/><br/>if /i "%yn1%"=="y" (<br/> set /p tardir=&lt;targetdirectory.txt<br/>) else (<br/> echo Type full path of target directory<br/> set /p tardir=<br/>)<br/>if exist %tardir% (<br/> cd %tardir%<br/>) else (<br/> echo Target does not exist<br/> echo Please try again<br/> ping 1.1.1.1 -n:1 -w:3000&gt;nul<br/> goto loop<br/>)<br/><br/>echo Is there a target string you want to enter?<br/>set /p yn2={y,n}<br/>if /i "%yn2%"=="y" (<br/> echo.<br/> echo Type target string for renaming<br/> set /p tarstr=[Target]<br/> set tarstr="*!tarstr!*"<br/> goto addtarstrques<br/>) else (<br/> set tarstr=*<br/> goto eof<br/>)<br/><br/>:addstring<br/>cls<br/>set /p addstr=[Target]<br/>set addstr="*%addstr%*"<br/>set tarstr=%addstr% %tarstr%<br/>echo Searching for strings: %tarstr%<br/>:addtarstrques<br/>cls<br/>echo.<br/>echo Is there an additional string you wish to look for?<br/>set /p yn3={y,n}<br/>if /i "%yn3%"=="y" goto addstring<br/>goto eof<br/><br/><br/>:startstring<br/>:startloop<br/>cls<br/>echo Is there a standard starting string <br/>echo to the naming convention?<br/>set /p yn4={y,n}<br/>if /i "%yn4%"=="y" (<br/> cls<br/> echo Enter standard start string <br/> echo [Include an ending space if desired]<br/> echo.<br/> set /p startstr=<br/>) else (<br/> set startstr=<br/> goto eof<br/>)<br/>echo The current start string is "%startstr%"<br/>echo Is this okay?<br/>set /p yn5={y,n}<br/>if /i "%yn5%"=="n" (<br/> set startstr=<br/> goto startloop<br/>)<br/>goto eof<br/><br/><br/>:endstring<br/>cls<br/>echo Is there a standard ending string to the naming convention?<br/>set /p yn5={y,n}<br/>if /i "%yn5%"=="n" (<br/> set endstr=<br/> goto eof <br/>)<br/>cls<br/>echo Would you like the end string to<br/>echo include the date the file was created<br/>set /p DateEnd=[y,n]<br/>cls<br/>if /i "%DateEnd%"=="y" call :DateEndFormatting<br/>cls<br/>echo Would you like the end string to include <br/>echo today's date<br/>set /p yn6={y,n}<br/>cls<br/>echo Enter standard end string<br/>echo [Include spaces if desired]<br/>set /p origendstr=<br/>if /i "%yn6%"=="y" call :DateTodayFormatting<br/>if "%DateEnd%"=="y" set origendstr=%origendstr%[date created]<br/>echo The current end string is "%origendstr%"<br/>echo Is this okay?<br/>set /p yn7={y,n}<br/>if /i "%yn7%"=="n" (<br/> set origendstr=<br/> goto endstring<br/>)<br/>if /i "%DateEnd%"=="y" set origendstr=%origendstr:~0,-14%<br/>goto eof<br/><br/><br/>:DateEndFormatting<br/>echo In what format would you like the<br/>echo date to appear:<br/>echo.<br/>echo 1. dd Mmm yy<br/>echo.<br/>echo 2. yyyymmdd<br/>echo.<br/>echo 3. Mmm dd, yyyy<br/>echo.<br/>echo 4. mm/dd/yy<br/>echo.<br/>echo 5. More...<br/>echo.<br/>set /p DateEndForm=Selection {1-5}-<br/>if "%DateEndForm%"=="5" goto more<br/>goto dateendskip<br/>:more<br/>cls<br/>echo 6. dd Mmm yyyy<br/>echo.<br/>echo 7. yy/mm/dd<br/>echo.<br/>echo 8. mm/dd/yyyy<br/>echo.<br/>echo 9. yymmdd<br/>echo.<br/>set /p DateEndForm=Selection {6-9}-<br/>:dateendskip<br/>goto eof<br/><br/><br/>:DateTodayFormatting<br/>echo In what format would you like the<br/>echo date to appear:<br/>echo.<br/>echo 1. dd Mmm yy<br/>echo.<br/>echo 2. yyyymmdd<br/>echo.<br/>echo 3. Mmm dd, yyyy<br/>echo.<br/>echo 4. mm/dd/yy<br/>echo.<br/>echo 5. More...<br/>echo.<br/>set /p DateTodayForm=Selection {1-5}-<br/>if "%DateTodayForm%"=="5" goto more<br/>goto settodayform<br/>:more<br/>cls<br/>echo 6. dd Mmm yyyy<br/>echo.<br/>echo 7. yy/mm/dd<br/>echo.<br/>echo 8. mm/dd/yyyy<br/>echo.<br/>echo 9. yymmdd<br/>echo.<br/>set /p DateTodayForm=Selection {6-9}-<br/>:settodayform<br/>if "%date:~4,2%"=="01" set todaymonth=Jan<br/>if "%date:~4,2%"=="02" set todaymonth=Feb<br/>if "%date:~4,2%"=="03" set todaymonth=Mar<br/>if "%date:~4,2%"=="04" set todaymonth=Apr<br/>if "%date:~4,2%"=="05" set todaymonth=May<br/>if "%date:~4,2%"=="06" set todaymonth=Jun<br/>if "%date:~4,2%"=="07" set todaymonth=Jul<br/>if "%date:~4,2%"=="08" set todaymonth=Aug<br/>if "%date:~4,2%"=="09" set todaymonth=Sep<br/>if "%date:~4,2%"=="10" set todaymonth=Oct<br/>if "%date:~4,2%"=="11" set todaymonth=Nov<br/>if "%date:~4,2%"=="12" set todaymonth=Dec<br/>if "%DateTodayForm%"=="1" set origendstr=%origendstr%%date:~7,2% %todaymonth% %date:~12%<br/>if "%DateTodayForm%"=="2" set origendstr=%origendstr%%date:~10%%date:~4,2%%date:~7,2%<br/>if "%DateTodayForm%"=="3" set origendstr=%origendstr%%todaymonth% %date:~7,2%, %date:~10%<br/>if "%DateTodayForm%"=="4" set origendstr=%origendstr%%date:~4,6%%date:~12%<br/>if "%DateTodayForm%"=="6" set origendstr=%origendstr%%date:~7,2% %todaymonth% %date:~10%<br/>if "%DateTodayForm%"=="7" set origendstr=%origendstr%%date:~12%/%date:~4,5%<br/>if "%DateTodayForm%"=="8" set origendstr=%origendstr%%date:~4%<br/>if "%DateTodayForm%"=="9" set origendstr=%origendstr%%date:~12,2%%date:~4,2%%date:~7,2%<br/>goto eof<br/><br/><br/>:DateEndSet<br/>if "!FileDate:~0,2!"=="01" set month=Jan<br/>if "!FileDate:~0,2!"=="02" set month=Feb<br/>if "!FileDate:~0,2!"=="03" set month=Mar<br/>if "!FileDate:~0,2!"=="04" set month=Apr<br/>if "!FileDate:~0,2!"=="05" set month=May<br/>if "!FileDate:~0,2!"=="06" set month=Jun<br/>if "!FileDate:~0,2!"=="07" set month=Jul<br/>if "!FileDate:~0,2!"=="08" set month=Aug<br/>if "!FileDate:~0,2!"=="09" set month=Sep<br/>if "!FileDate:~0,2!"=="10" set month=Oct<br/>if "!FileDate:~0,2!"=="11" set month=Nov<br/>if "!FileDate:~0,2!"=="12" set month=Dec<br/>if "%DateEndForm%"=="1" set endstr=%origendstr%!FileDate:~3,2! !month! !FileDate:~8,2!<br/>if "%DateEndForm%"=="2" set endstr=%origendstr%!FileDate:~6,4!!FileDate:~0,2!!FileDate:~3,2!<br/>if "%DateEndForm%"=="3" set endstr=%origendstr%!month! !FileDate:~3,2!, !FileDate:~6,2!<br/>if "%DateEndForm%"=="4" set endstr=%origendstr%!FileDate:~0,6!!FileDate:~8,2!<br/>if "%DateEndForm%"=="6" set endstr=%origendstr%!FileDate:~3,2! !month! !FileDate:~6,2!<br/>if "%DateEndForm%"=="7" set endstr=%origendstr%!FileDate:~8,2!!FileDate:~0,5!<br/>if "%DateEndForm%"=="8" set endstr=%origendstr%!FileDate:~0,10!<br/>if "%DateEndForm%"=="9" set endstr=%origendstr%!FileDate:~8,2!!FileDate:~0,2!!FileDate:~3,2!<br/>goto eof<br/><br/><br/>:setcaps<br/>set NewName=!NewName:A=a!<br/>set NewName=!NewName:B=b!<br/>set NewName=!NewName:C=c!<br/>set NewName=!NewName:D=d!<br/>set NewName=!NewName:E=e!<br/>set NewName=!NewName:F=f!<br/>set NewName=!NewName:G=g!<br/>set NewName=!NewName:H=h!<br/>set NewName=!NewName:I=i!<br/>set NewName=!NewName:J=j!<br/>set NewName=!NewName:K=k!<br/>set NewName=!NewName:L=l!<br/>set NewName=!NewName:M=m!<br/>set NewName=!NewName:N=n!<br/>set NewName=!NewName:O=o!<br/>set NewName=!NewName:P=p!<br/>set NewName=!NewName:Q=q!<br/>set NewName=!NewName:R=r!<br/>set NewName=!NewName:S=s!<br/>set NewName=!NewName:T=t!<br/>set NewName=!NewName:U=u!<br/>set NewName=!NewName:V=v!<br/>set NewName=!NewName:W=w!<br/>set NewName=!NewName:X=x!<br/>set NewName=!NewName:Y=y!<br/>set NewName=!NewName:Z=z!<br/>:caps<br/>cls<br/>echo !NewName!<br/>echo.<br/>set /p caps=How many capital letters?<br/>if "!caps!"=="0" goto eof<br/>for /l %%i in (1,1,!caps!) do (<br/> cls<br/> echo Capital Letter %%i<br/> echo !NewName!<br/> echo 012345678911111111112222222222333333333344444444445555555555<br/> echo 01234567890123456789012345678901234567890123456789<br/> set /p capoff=At Position-<br/> set /a endcap=!capoff!+1<br/> call set before=%%NewName:~0,!capoff!%%<br/> call set capletter=%%NewName:~!capoff!,1%%<br/> call set after=%%NewName:~!endcap!%%<br/><br/> set capletter=!capletter:a=A!<br/> set capletter=!capletter:b=B!<br/> set capletter=!capletter:c=C!<br/> set capletter=!capletter:d=D!<br/> set capletter=!capletter:e=E!<br/> set capletter=!capletter:f=F!<br/> set capletter=!capletter:g=G!<br/> set capletter=!capletter:h=H!<br/> set capletter=!capletter:i=I!<br/> set capletter=!capletter:j=J!<br/> set capletter=!capletter:k=K!<br/> set capletter=!capletter:l=L!<br/> set capletter=!capletter:m=M!<br/> set capletter=!capletter:n=N!<br/> set capletter=!capletter:o=O!<br/> set capletter=!capletter:p=P!<br/> set capletter=!capletter:q=Q!<br/> set capletter=!capletter:r=R!<br/> set capletter=!capletter:s=S!<br/> set capletter=!capletter:t=T!<br/> set capletter=!capletter:u=U!<br/> set capletter=!capletter:v=V!<br/> set capletter=!capletter:w=W!<br/> set capletter=!capletter:x=X!<br/> set capletter=!capletter:y=Y!<br/> set capletter=!capletter:z=Z!<br/><br/> set NewName=!before!!capletter!!after!<br/>)<br/>cls<br/>echo !NewName!<br/>echo.<br/>echo Are there any additional caps needed?<br/>set /p yn14={y,n}<br/>if /i "%yn14%"=="y" goto caps<br/>goto eof<br/><br/><br/>:EditNameSubroutine<br/>:editname<br/>cls<br/>echo !OldName!<br/>echo 012345678911111111112222222222333333333344444444445555555555<br/>echo 01234567890123456789012345678901234567890123456789<br/>echo.<br/>set /p NameStart=Enter Start Position-<br/>set /p NameEnd=Enter End Position-<br/>set /a NameLength=1+!NameEnd!-!NameStart!<br/><br/>if /i "%DateEnd%"=="y" call :DateEndSet else set endstr=%origendstr%<br/><br/>call set NewName=%%OldName:~!NameStart!,!NameLength!%%<br/><br/>cls<br/>echo !NewName!<br/>echo Would you like to make changes to this part<br/>echo {Start and end strings will be added later}<br/>echo.<br/>set /p yn10={y,n}<br/>if /i "!yn10!"=="y" (<br/> call :setcaps<br/><br/> cls<br/> echo !NewName!<br/> echo.<br/> echo Would you like to insert anything into the name<br/> set /p yn8={y,n}<br/> if /i "!yn8!"=="y" call :insertsubroutine<br/><br/> cls<br/> echo !NewName!<br/> echo.<br/> echo Would you like to remove anything from the name<br/> set /p yn12={y,n}<br/> if /i "!yn12!"=="y" call :removesubroutine<br/>)<br/>cls<br/>echo !NewName!<br/>echo.<br/>echo Do you need to make any other changes?<br/>echo.<br/>set /p yn15={y,n}<br/>if "%yn15%"=="y" goto editname<br/>goto eof<br/><br/><br/>:insertsubroutine<br/>:insertsub<br/>cls<br/>echo !NewName!<br/>echo 012345678911111111112222222222333333333344444444445555555555<br/>echo 01234567890123456789012345678901234567890123456789<br/>echo To the **right** of what position would <br/>echo you like to insert the string?<br/>set /p strpos=Right of Position-<br/>echo What would you like to insert<br/>set /p stradd=[String]<br/>call set NewName=%%NewName:~0,!strpos!%%!stradd!%%NewName:~!strpos!%%<br/>cls<br/>echo !NewName!<br/>echo.<br/>echo Is there anything else that needs to be added<br/>set /p yn11={y,n}<br/>if /i "!yn11!"=="y" goto insertsub<br/>goto eof<br/><br/><br/>:removesubroutine<br/>:removesub<br/>cls<br/>echo !NewName!<br/>echo 012345678911111111112222222222333333333344444444445555555555<br/>echo 01234567890123456789012345678901234567890123456789<br/>echo What are the start and end positions<br/>echo of the string to be removed?<br/>echo.<br/>echo Note that the start position should be<br/>echo the last character that you want to stay<br/>echo and the end position the last character<br/>echo you want deleted<br/>echo.<br/>set /p remstpos=Start Position-<br/>set /p remenpos=End Position-<br/>call set NewName=%%NewName:~0,!remstpos!%%%%NewName:~!remenpos!%%<br/>cls<br/>echo !NewName!<br/>echo.<br/>echo Do you need to remove anything else<br/>set /p yn13={y,n}<br/>if /i "!yn13!"=="y" goto removesub<br/></body></html>
8730.

Solve : Replace String Using SET Command?

Answer» <html><body><p>Hello,<br/>I need to replace a <a href="https://interviewquestions.tuteehub.com/tag/string-11290" style="font-weight:bold;" target="_blank" title="Click to know more about STRING">STRING</a> in a variable with another string. The second or replacing string is also in a variable.<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> the SET command to do the string replacement and I can't figure out how to replace a string with a variable.<br/><br/>For example:<br/>set a=Hello kitty<br/>set b=doggy<br/><br/>To change "Hello kitty" to "Hello doggy" with a literal:<br/>set a=%a:kitty=doggy%<br/>Result is: Hello doggy<br/><br/>To replace the string with a variable, I tried the following and failed:<br/>set a=%a:kitty=%b%<br/>The result is: Hello b<br/><br/>The % in front of the variable b is causing the problem. Can anyone give me some suggestions on fixing my problem?<br/><br/>Thank you.set a=%a:Kitty=%%b%%Thank you for your reply.<br/><br/>That seemed to work but when I tried to manipulate the first string like echo or concatenate, the word doggy is repeated again.<br/><br/>set a=%a:kitty=%%b%%<br/><br/>Echo %a%<br/>set a=%a%again<br/>Echo %a%<br/><br/>Result is:<br/>Hello doggy (this <a href="https://interviewquestions.tuteehub.com/tag/came-248412" style="font-weight:bold;" target="_blank" title="Click to know more about CAME">CAME</a> from the first set command)<br/>Hello doggydoggy (this came from the first Echo command)<br/>Hello doggydoggyagain (this came from the second Echo command)<br/><br/>Any suggestions?Oops. Your suggestion works. I had too many set commands in my script so it appeared that the word doggy was repeated. Sorry.<br/><br/>Thank you very much for your help.That's <a href="https://interviewquestions.tuteehub.com/tag/good-1009017" style="font-weight:bold;" target="_blank" title="Click to know more about GOOD">GOOD</a>!<br/></p></body></html>
8731.

Solve : how to know a particular process is running or not using ms dos?

Answer» <html><body><p>hi<br/><br/>i want to create a batch file such that if internet <a href="https://interviewquestions.tuteehub.com/tag/explorer-455219" style="font-weight:bold;" target="_blank" title="Click to know more about EXPLORER">EXPLORER</a> is running then close mozilla firefox...<br/><br/>here how can i handle using IF <br/><br/><br/>pls explain<br/><br/><br/>thank you <br/>sir<br/>You don't use an <em>if</em>. One technique is to get a list of all running processes and then determine if <strong>iexplore.exe</strong> is among them. If it is, then kill <strong>firefox</strong>.<br/><br/>Code: <a>[Select]</a>@echo off<br/>tasklist | find /i "iexplore.exe" &amp;&amp; taskkill /im firefox.exe<br/><br/>Good luck. <br/><br/>thanks for reply<br/><br/>but above command is running in dos but through notepad it is not running..<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/showing-642926" style="font-weight:bold;" target="_blank" title="Click to know more about SHOWING">SHOWING</a> error tasklist is not a <a href="https://interviewquestions.tuteehub.com/tag/internal-517481" style="font-weight:bold;" target="_blank" title="Click to know more about INTERNAL">INTERNAL</a> external or <a href="https://interviewquestions.tuteehub.com/tag/batchfile" style="font-weight:bold;" target="_blank" title="Click to know more about BATCHFILE">BATCHFILE</a> comand.<br/><br/>pls tell<br/>thanksQuote from: amittripathi on September 16, 2011, 12:55:05 AM</p><blockquote>but above command is running in dos but through notepad it is not running..<br/></blockquote><br/>Please explain. It's probably too early for this stuff, but how do you run a <a href="https://interviewquestions.tuteehub.com/tag/program-246414" style="font-weight:bold;" target="_blank" title="Click to know more about PROGRAM">PROGRAM</a> through <strong>notepad</strong>?<br/><br/>Not all machines have<strong> tasklist</strong> installed so try to replace it with <strong>tlist</strong>:<br/><br/>Code: <a>[Select]</a>@echo off<br/>tlist | find /i "iexplore.exe" &amp;&amp; taskkill /im firefox.exe<br/><br/>If an error still occurs, you can download <strong>tasklist</strong> from here and use the original code posted. <br/><br/>Good luck.</body></html>
8732.

Solve : What is WRONG??

Answer» <html><body><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: BC_Programmer on September <a href="https://interviewquestions.tuteehub.com/tag/15-237501" style="font-weight:bold;" target="_blank" title="Click to know more about 15">15</a>, 2011, 05:55:25 PM<blockquote>isn't something that I am apt to consider.<br/></blockquote><br/>Hmmm... I believe they have a <a href="https://interviewquestions.tuteehub.com/tag/word-244271" style="font-weight:bold;" target="_blank" title="Click to know more about WORD">WORD</a> for this 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>...</body></html>
8733.

Solve : Copying, moving and renaming of files?

Answer» <html><body><strong>Scenario:</strong><br/>I have a folder called <em><strong>box</strong></em> that contains a number of folders with names <strong><em>A, B, C…</em></strong> These folders contain varying number of files with a serialized naming scheme <strong>Zxx</strong>, where, <strong>x </strong>represents a number (0, 1, 2…). <br/><br/><strong>Action:</strong><br/>I would like to have a batch file that performs the following:<br/><ul><li><a href="https://interviewquestions.tuteehub.com/tag/create-427332" style="font-weight:bold;" target="_blank" title="Click to know more about CREATE">CREATE</a> a destination folder whose name is given to a placeholder at the same place as box.</li><li>Accesses the folders in box alphabetically </li><li>Copies their files into the destination folder with a serialized naming scheme of type <strong>Zxx</strong> with a possibility of getting to <strong>Zxxx</strong>.</li></ul> <br/><br/>This is a little difficult to start on because I am not quite certain what it is you are trying to do. Can you show an example of what you are looking for?<br/><br/>From what I am reading, I think what you are trying to do is this:<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/transfer-246431" style="font-weight:bold;" target="_blank" title="Click to know more about TRANSFER">TRANSFER</a> File named "Z00" in folder "A" under folder "box"<br/>...<br/>to<br/>...<br/>File named "Z000" in folder "Destination"<br/><br/>Please let us know if this is indeed what you are trying to do or if it is something different.There is another similar topic to this one in which Salmon Trout and CN-DOS replied with some code that does almost what you are trying to do here.<br/><br/>Quote from: Salmon Trout on August 24, 2011, 01:56:50 PM<blockquote>Your convention of having 2 dots was what I did not know about... try this. For guidance there are many sites and one of the best is ss64.com<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>For /f "delims=" %%F in ('dir /s /b *.pdf') do (<br/> set OldPathAndName=%%~dpnxF<br/> Set OldName=%%~nxF<br/><br/> Set NewName=!OldName!<br/><br/> set NewName=!NewName:And=and!<br/> set NewName=!NewName:The=the!<br/> set NewName=!NewName:Is=is!<br/> set NewName=!NewName:Not=not!<br/><br/> echo Ren "!OldPathAndName!" "!Newname!"<br/> )<br/> </blockquote><br/>Quote from: CN-DOS on August 31, 2011, 05:53:17 AM<blockquote>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/>for /f "delims=" %%a in ('dir /s /b *.pdf') do (<br/> set NewName=%%~na<br/> set NewName=!NewName:And=and!<br/> set NewName=!NewName:The=the!<br/> set NewName=!NewName:Is=is!<br/> set NewName=!NewName:Not=not!<br/> ren "%%a" "!Newname!.pdf"<br/>)</blockquote><br/>These pieces of code are meant to rename the files and change the names to have lowercase "and"s, "the"s, "is"s, and "not"s, but uses the same principles (and commands) that you would <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 use for a program like this. The code that I am writing is going to copy the files to the destination folder and rename them with a Zxxx format, but the first x will be the folder they were originally from. So Z00 in folder A will become ZA00 in the new location.<br/><br/>The coding that I am using uses some stuff that is going to require some work on your part. I am going to assume for this code that the "box" folder you are referencing is located on the desktop of "User" and the "destination" folder is in the same location. This is important because you will notice the :~ that is used in the code to parse out the file name. You are going to have to do the research to find out exactly how many characters there are in the fully qualified path name.<br/><br/>Here is a short explanation of what you'll see. To parse out a variable, you use the ':~' to designate that you only want part of the variable. The first number will be the number of characters there are before the start of the parsing, and the second number is the number of characters to use in the parsing. <br/>Example: <br/>%date% will expand to Wed 09/14/2011<br/>%date:~4,2% will expand to 09<br/>Utilizing one number "<a href="https://interviewquestions.tuteehub.com/tag/n-236724" style="font-weight:bold;" target="_blank" title="Click to know more about N">N</a>" will utilize the remainder of the variable after 'n' characters<br/>%date:~10% will expand to 2011<br/><br/>With that, here is a rough go at what you are trying to do with the limited knowledge I have on the FOR command:<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>set NewFilePath=C:\Users\User\desktop\destination {your full path of destination folder}<br/><br/>for /f "delims=" %%F in ('dir /s /b /o:n') do (<br/> set OldFilePath=%%dpF<br/> set OldName=%%~nxF<br/> set OldFilePathAndName=%%dpnxF<br/> set Folder=!OldFilePath:~26,1! {Here's where you need to do your research}<br/><br/> set NewName=!OldName:~0,1!!Folder!!OldName:~1!<br/><br/> copy !OldFilePathAndName! !NewFilePath!<br/><br/> ren !NewFilePath!\!OldName! !NewName!<br/>)<br/>Side note on the :~<br/><br/>You can utilize the - to utilize a from the end type of selection. So a !OldFilePath:~-2,1! Will take the second to last character in the path name (the last character always being a \). Or if you know you want to utilize only a certain part of the path that starts 12 characters in and you don't want the last slash in there, you can set up !OldFilePath:~11,-1! Or use it however you need to. I missed a couple of ~s in the original code.<br/><br/>Corrected.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>set NewFilePath=C:\Users\User\desktop\destination {your full path of destination folder}<br/><br/>for /f "delims=" %%F in ('dir /s /b /o:n') do (<br/> set OldFilePath=%%~dpF<br/> set OldName=%%~nxF<br/> set OldFilePathAndName=%%~dpnxF<br/> set Folder=!OldFilePath:~26,1! {Here's where you need to do your research}<br/><br/> set NewName=!OldName:~0,1!!Folder!!OldName:~1!<br/><br/> copy !OldFilePathAndName! !NewFilePath!<br/><br/> ren !NewFilePath!\!OldName! !NewName!<br/>)<br/>This is what I mean:<br/><br/>Transfer file named "z00" in folder "A" under folder "box"<br/>...<br/>to<br/>...<br/>File named "z00" in folder "Destination"<br/>…<br/>Continue the above procedure till the last file in “A” is transferred and renamed into “Destination”<br/>…<br/>Transfer file named "z00" in folder "B" under folder "box"<br/>...<br/>to<br/>...<br/>File named "zxx" in folder "Destination”, where "xx" is a serial increment of the last file named in folder "Destination". Example, if the last file transferred to "Destination" was named "z56", then, the first file transferred to "Destination" from "B" is named "z57". <br/>This continues until the last file in the last folder of “box” has been transferred to "Destination".<br/>Note: <br/>The folders in “box” are accessed in alphabetical order.<br/>Only the last two characters of the file names change and this may change to three characters. <br/>The folder “Destination” is named by the user via place holder and is located on the same path as “box”.<br/><br/>I am going through the script you posted will post the outcome later. Thanks for ss64.com it helps.<br/>This becomes a two step process then. The first step moves the file into a temporary location so as not to rename the wrong file or copy the wrong file at any point. The second step is to ensure that the proper naming convention is used. A simple if command will <a href="https://interviewquestions.tuteehub.com/tag/allow-362909" style="font-weight:bold;" target="_blank" title="Click to know more about ALLOW">ALLOW</a> for the naming convention to be correct. Please say something if there are parts of the script that you don't understand.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>:setnewpath<br/>set /p NewFilePath=Please enter the full path of the destination folder<br/>cls<br/>if exist %NewFilePath% goto continue<br/>echo That location is not valid. Please type a valid location for the destination.<br/>echo The path needs to exist currently, so please make the folder if it does not already exist.<br/>goto setnewpath<br/><br/>:continue<br/>set TempFilePath="c:\users\user\desktop\Temp"<br/>set number=0<br/><br/>for /f "delims=" %%F in ('dir /s /b /o:n') do (<br/> set OldName=%%~nxF<br/> set Extension=%%~xF<br/> set OldFilePathAndName=%%~dpnxF<br/> if /i !number! leq 9 (<br/> set NewName=z00!number!!Extension!<br/> ) else (<br/> if /i !number! leq 99 (<br/> set NewName=z0!number!!Extension!<br/> ) else (<br/> set NewName=z!number!!Extension!<br/> )<br/> )<br/><br/> copy !OldFilePathAndName! !TempFilePath!<br/><br/> ren !TempFilePath!\!OldName! !NewName!<br/><br/> copy !TempFilePath!\!NewName! !NewFilePath!<br/> del !TempFilePath!\!NewName! /q<br/><br/> set /a number=!number!+1<br/>)<br/>rd c:\users\user\desktop\Temp /q<br/>Over thinking computer tasks always leads to complexities. Try to keep it simple.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/><br/>set seq=0<br/>set source=c:\temp\box<br/>set /p target=Enter Destination Folder: <br/><br/>md %target%<br/><br/>for /f "tokens=* delims=" %%i in ('dir %source% /a:-d /s /b') do (<br/> set leadzero=000!seq!<br/> set leadzero=!leadzero:~-3!<br/> copy %%i %target%\Z!leadzero!%%~xi <br/> set /a seq+=1<br/>) <br/><br/>You will be prompted for a fully qualified destination directory. The source directory (box) is hardcoded but feel free to change it.<br/><br/>Good luck. <br/><br/></body></html>
8734.

Solve : Using batch files for temporary user access to the local admin group?

Answer» <html><body><p>Users on my office network need to run an application/command (eg: regsvr32 -u "c:\<a href="https://interviewquestions.tuteehub.com/tag/program-246414" style="font-weight:bold;" target="_blank" title="Click to know more about PROGRAM">PROGRAM</a> Files\Outlook Add-in\ShinseiOutlookCom.dll") that requires local admin rights. For security purposes, we prefer not to provide users with local admin rights. Would you recommend trying to write a <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> file to add each user to the local admin group when he or she clicks the program's desktop? This privilege level would only last until the user exits the program...Any body can suggest me on this?<br/><br/>Thanks,<br/><br/>BijuQuote from: Biju007 on September 13, 2011, 09:46:59 PM</p><blockquote>Would you recommend trying to write a batch file to add each user to the local admin group when he or she clicks the program's desktop? This privilege level would only last until the user exits the program...Any body can suggest me on this?<br/></blockquote><br/>The problem you run into if you use batch is that in order to write it, it would have to have a hardcoded <a href="https://interviewquestions.tuteehub.com/tag/username-238054" style="font-weight:bold;" target="_blank" title="Click to know more about USERNAME">USERNAME</a> and password. There are some ways to use backdoor options to make it very difficult for the user to obtain the password, but in most cases, when using batch, it is very difficult to make it impossible. The work around that we have used to a great deal of success in my working environment is a batch file that merely starts another batch file located on a network drive as a <a href="https://interviewquestions.tuteehub.com/tag/specified-1221578" style="font-weight:bold;" target="_blank" title="Click to know more about SPECIFIED">SPECIFIED</a> user. That user is the only user with access to the .txt file that contains the administrative name and password, and then the file imports those items into the program to run. It's a big end-around process and it would be a lot easier if the network allowed us to run other software other than batch files, but we have what we have and that's how we have worked it. If you would like, I can give you a sample of the two batch files. My <a href="https://interviewquestions.tuteehub.com/tag/suggestion-250110" style="font-weight:bold;" target="_blank" title="Click to know more about SUGGESTION">SUGGESTION</a> though would be to go with some other programming medium that would alow you to hardcode the username and password but not allow it to be readily available to the user.It is great idea which you offered to me, Thanks for that. I came to know in a batch file we can call VB script in-order to secure the administrative name and password. But right now; if you can share the sample batch files as you told I can try to implement as my requirement.<br/><br/>Looking forward from you.<br/><br/>Biju B.Batch 1<br/><br/>Code: <a>[Select]</a>net use z: /delete /y<br/>net use z: \\networklocation /USER:<a href="/cdn-cgi/l/email-protection">[emailprotected]</a> -password /persistent:no<br/><br/>start z:\batch2.bat /username=joe.schmo /password=password<br/><br/>Batch 2<br/><br/>Code: <a>[Select]</a>@echo off<br/>net use b: /delete /y<br/>net use b: \\anothernetworklocation /persistent:no<br/>set /p adminuser=&lt;b:\adminuser.txt<br/>set /p adminpass=&lt;b:\adminpass.txt<br/>net use b: /delete /y<br/><br/>start c:\localprogram.exe /username=%adminuser% /password=%adminpass%<br/><br/>Let me know if you run into any issues.</body></html>
8735.

Solve : Need help writing a batch file that copies and overwrites files repeatedly?

Answer» <html><body><p>I'm working on writing a batch <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a> for where I work that will help automate some things that have to be done manually.<br/><br/>I work for a retail company that does its credit sales over a network, but when there is a network outage there is a dial-up backup system that can take over and run their credit over dial up.<br/>But this requires the store manager to go on the server and run a few commands through the command <a href="https://interviewquestions.tuteehub.com/tag/line-239358" style="font-weight:bold;" target="_blank" title="Click to know more about LINE">LINE</a> - and the obstacles in <a href="https://interviewquestions.tuteehub.com/tag/getting-2670847" style="font-weight:bold;" target="_blank" title="Click to know more about GETTING">GETTING</a> them to do this are a real support issue.<br/><br/>I've got the monitoring working, it's copying these files around that is giving me problems.<br/><br/><br/><br/>So here's what I have<br/>credit_working - the currently active file that gives instruction to the credit server<br/>credit_IP - a file stored somewhere else that has instructions for credit running normally over the network<br/>credit_DIAL - a file stored somewhere else that has instructions for credit running over the dial-up modem<br/><br/>- the batch file monitors for a network outage<br/>- when the network goes down<br/>* credit_dial needs to be copied over credit_working<br/><br/>- when the network comes back up<br/>* credit_ip needs to be copied over credit_working<br/>- it goes back to monitoring<br/><br/><br/><br/>The problem I'm having is - <br/>When it goes to copy credit_ip over credit_working, it gives the error message "the system cannot find the file specified"<br/><br/><br/><br/>What can cause this? All the files are do exist and are never being deleted, only overwritten.<br/>I've tried taking the long way around and deleting credit_working, copying credit_ip over, and then renaming it - but it gave the same response.<br/>Any suggestions?<br/>I'll put the affected part of the script in my next post.Here is the part I'm having trouble with.<br/>There's a lot more to it than this, and I'm changing the names and directories for clarity.<br/>I'll put <a href="https://interviewquestions.tuteehub.com/tag/general-238723" style="font-weight:bold;" target="_blank" title="Click to know more about GENERAL">GENERAL</a> <a href="https://interviewquestions.tuteehub.com/tag/statements-17642" style="font-weight:bold;" target="_blank" title="Click to know more about STATEMENTS">STATEMENTS</a> in parenthesis, so assume that all works ok.<br/>Remember, the file credit_working is the one that's actually being used by the credit server.<br/><br/><br/><br/>(The batch file runs all the time and checks for a network connection)<br/>(It has lost connection and goes to :DOWN)<br/><br/><strong>:DOWN<br/>copy "C:\credit_dial.xml" "C:\credit_working"</strong><br/><br/>(goes to monitoring for a connection again)<br/><br/><br/><br/><br/>(After the connection comes back up, it comes to :RESTORED)<br/><br/><strong>:RESTORED<br/>copy "C:\credit_IP.xml" "C:\credit_working"</strong><br/><br/>(goes back to monitoring for a network outage)<br/><br/><br/><br/><br/><br/><br/>It is during :RESTORED that it gives the error message "the system cannot find the file specified"<br/>Any suggestions?Maybe you changed directories. Is the script running with sufficient permissions? I suspect you may need to post a bit more of your code. <br/></p></body></html>
8736.

Solve : change dos font size in native dos, not windows shelled dos?

Answer» <html><body><p>I remember way back being able to make dos font size larger, on an old 8088 running DOS 5.0, Thought it was part of the SET command, but cant seem to locate it. Digging online I found a statement that to me just sounds way incorrect... Quote</p><blockquote>"MS-DOS uses characters built into the video card. Thus, you cannot "change" the font." </blockquote> Doesn't the OS parameters/drivers control size and font type of text that is displayed and the video card is just displaying what it is told to display on its x,y grid? <br/><br/><a href="https://wiki.answers.com/Q/How_do_you_change_font_size_in_DOS_command">http://wiki.answers.com/Q/How_do_you_change_font_size_in_DOS_command</a><br/><br/>Changing font/text size is simple in windows shell <a href="https://interviewquestions.tuteehub.com/tag/properties-11511" style="font-weight:bold;" target="_blank" title="Click to know more about PROPERTIES">PROPERTIES</a>, but ran across this the other day with DOS displaying on my 27" CRT TV in which the text is too small to barely make out, and I am using HTPC with DOS 6.22 boot floppy to play old games. Wolfenstein 3D really likes the XMS and EMS memory which is obsolete in modern windows. If it were just WOLF3D that I was playing, I'd just add that exe to autoexec.bat on the floppy, but I also play other games so it would be nice to avoid the eye strain by increasing the font size, which I <a href="https://interviewquestions.tuteehub.com/tag/pretty-2228622" style="font-weight:bold;" target="_blank" title="Click to know more about PRETTY">PRETTY</a> much just sit back and type as correct as possible to start the game, and if I fumble a key try again with the text blur of a 27" CRT TV..lol<br/><br/>I suppose at some point I should modernize from 1995 TV technology and go with a nice flat screen which would be crisp text even if small... but until I have a couple hundred bucks with nothing better to do, I'd liek to make the dos text larger in DOS 6.22..lolOK. Yes, you can change the font size. You are talking about DOS 6.22 running native, not inside of anything or under anythig. <br/><br/>It depemds on the vbideo card. DOS does not have a font sests like nWindows has. The fonts are crated by a generator in the video card. Most of the nolder video cards had no wayn to alter the font used. But it was posible to change the number of chars on a line. And the number of lines on the display.<br/><br/>It is hard to get this information now. Just about every reference is about using DOS under windfows, whichn is nnot really DOS.<br/>This is nabout the MODE command. It can change the ndisplay.<br/><a href="https://www.csulb.edu/~murdock/mode.html">http://www.csulb.edu/~murdock/mode.html</a><br/><br/><em>(I am running Vista and FF 6 and no <a href="https://interviewquestions.tuteehub.com/tag/spell-1222030" style="font-weight:bold;" target="_blank" title="Click to know more about SPELL">SPELL</a> checker.)</em>mode co40Thanks guys... "I forgot all about MODE.com" and that would be why i was not finding my answer through google when looking to do it using SET . Looked into the Mode co40 and <a href="https://interviewquestions.tuteehub.com/tag/color-237956" style="font-weight:bold;" target="_blank" title="Click to know more about COLOR">COLOR</a> with 40 characters per line should definitely do the trick on bootable DOS 6.22 floppy disk adding that to config.sys line.<br/><br/>I just need to make sure that I add MODE.com to it for that to work, since the floppy was created using format a:/s a long time ago ( 1995-ish ), and I bet its not on that disk.!!! These days people say who still uses floppies... well I do for native old school gaming and bios flashes!<br/><br/>I've been hanging around Windows too long and these bits of info are disappearing from what I probably knew 20 years ago before Windows spoiled me... lol <br/><br/>Today with Windows you can alter your font just by command shell window properties. And for quite a few years I have used that feature when needing to make text bigger in command shell... so the sector for making text bigger in my brain got overwritten with that tidbit vs the old way pre-windows. Will tag that piece of info with ATTRIB +R this time to protect it from getting lost again..lol <br/>Quote from: DaveLembke on September 13, 2011, 01:40:53 AM<blockquote>adding that to config.sys line.<br/></blockquote>won't work there. it's a command. add it to autoexec.bat.<br/>Quote<blockquote>These days people say who still uses floppies... </blockquote><br/>I do. Well, actually, that's not true, because nearly all my floppies are bad. I do have a floppy drive installed though.<br/>Quote from: DaveLembke on September 13, 2011, 01:40:53 AM<blockquote>These days people say who still uses floppies</blockquote><br/>I do too. They have all of my StarCraft custom maps on them, from when I used to stay up until ridiculous hours drinking Wal-Mart brand soda and eating Cheetos while creating works of art in StarCraft map editor. Ow! Flashbacks of "triggers" <a href="https://interviewquestions.tuteehub.com/tag/programming-1806" style="font-weight:bold;" target="_blank" title="Click to know more about PROGRAMMING">PROGRAMMING</a>... painful...<br/><br/>I thought MODE.com was a standard load after DOS 6. Maybe it was another one. I can't remember back that far very well.Quote from: Raven19528 on September 13, 2011, 09:36:14 AM<blockquote>I do too. They have all of my StarCraft custom maps on them, from when I used to stay up until ridiculous hours drinking Wal-Mart brand soda and eating Cheetos while creating works of art in StarCraft map editor. Ow! Flashbacks of "triggers" programming... painful...<br/><br/>I thought MODE.com was a standard load after DOS 6. Maybe it was another one. I can't remember back that far very well.<br/></blockquote><br/>MODE was in all version of DOS, at least since 3.11, most likely earlier. It's never been on the boot disks created with sys or format /s, though.Thanks BC for the correction ... I too was thinking autoexec.bat, but the site I was on was talking about it in config.sys, so thats why I was like well maybe because its a configuration parameter where services and memory allocation parameters are set. Tonight hopefully I'll get to test out MODE co40.</body></html>
8737.

Solve : Timer program?

Answer» <html><body><p>I recall way back that it was possible to write a program that could control lights etc. from an old computer.The output was via the parallel port to enable solid state <a href="https://interviewquestions.tuteehub.com/tag/relays-1183761" style="font-weight:bold;" target="_blank" title="Click to know more about RELAYS">RELAYS</a>. Does anyone know of a commercially available version? <br/><br/>Art They wrote <a href="https://interviewquestions.tuteehub.com/tag/books-238323" style="font-weight:bold;" target="_blank" title="Click to know more about BOOKS">BOOKS</a> on that. You cn do a Google search:<br/>parallel port projects<br/>will get near 3 million hits.<br/>Top <a href="https://interviewquestions.tuteehub.com/tag/items-770212" style="font-weight:bold;" target="_blank" title="Click to know more about ITEMS">ITEMS</a>:<br/><a href="&lt;klux&gt;HTTP&lt;/klux&gt;://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html">http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html</a><br/><a href="http://www.edaboard.com/thread155813.html">http://www.edaboard.com/thread155813.html</a><br/><a href="http://www.lvr.com/parport.htm">http://www.lvr.com/parport.htm</a><br/><br/>This one is a <a href="https://interviewquestions.tuteehub.com/tag/good-1009017" style="font-weight:bold;" target="_blank" title="Click to know more about GOOD">GOOD</a> reference with external links<br/><a href="http://ee.cleversoul.com/parallel-port.html">http://ee.cleversoul.com/parallel-port.html</a></p></body></html>
8738.

Solve : lil help?

Answer» <html><body><p>Hi im new at <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> files and im stuck i read up and everything but it still wont work heres my script so far...<br/><br/><br/>echo off<br/>echo v1.2<br/>color 1e<br/>echo . .<br/>echo . RaNdOm <a href="https://interviewquestions.tuteehub.com/tag/facts-16997" style="font-weight:bold;" target="_blank" title="Click to know more about FACTS">FACTS</a> .<br/>echo . . <br/>echo Hello welcome to Random Facts <br/>echo press A-<a href="https://interviewquestions.tuteehub.com/tag/z-236619" style="font-weight:bold;" target="_blank" title="Click to know more about Z">Z</a> to continue to facts or X to exit<br/>echo have fun<br/>if %option%==a goto a<br/>if %option%==b goto b<br/>:a hello<br/>:b hi<br/>pause<br/><br/><br/>any ideas?? please<br/><br/>p.s its saying right fast then close that "goto is unsuspected at this time".:loop<br/>set /p option=Your choice A -Z (X to exit)<br/>if "%option%"=="a" goto a<br/>if "%option%"=="b" goto b<br/>if "%option%"=="x" exit<br/>echo Wrong input!<br/>goto loop<br/>:a <br/>echo hello<br/>:b <br/>echo hi<br/><br/><br/><br/>Better...<br/><br/>:loop<br/>set /p option=Your choice A -Z (X to exit)<br/>if "%option%"=="a" goto a<br/>if "%option%"=="b" goto b<br/>if "%option%"=="x" goto end<br/>echo Wrong input!<br/>goto loop<br/><br/>:a<br/>echo hello<br/>goto end<br/>:b<br/>echo hi<br/>goto end<br/><br/>:z<br/>echo last label<br/>:end<br/><br/><br/><br/><br/>Like Salmon Trout is showing, what seems to be missing from your code is the ability to input the 'option' variable. Without "set"ting the variable, it will not register that the variable even <a href="https://interviewquestions.tuteehub.com/tag/exists-979838" style="font-weight:bold;" target="_blank" title="Click to know more about EXISTS">EXISTS</a> and you run into the error you are seeing. The /p flag tells the script that it is waiting for user input for the variable, which is why you can put text after the = and it will show in the program rather than setting the variable to equal that.<br/><br/>Example:<br/><br/>set /p option=Your choice A -Z (X to exit)<br/><br/>willl generate this in the program:<br/><br/>Your choice A -Z (X to exit) |<br/><br/>where the | would be the cursor for the user to type at and the 'option' variable would equal their input.<br/>If however you typed the following into the code:<br/><br/>set option=Your choice A-Z (X to exit)<br/><br/>the option variable would equal "Your" and the rest of the line would be dismissed and there would be no option for the user to input anything. Batch is very finnicky so a lot of things are learned through trial and error, and of course picking other people's brains.</p></body></html>
8739.

Solve : Replace String with Wildcards using DOS Batch file!?

Answer» <html><body><p>Quote from: graymj on August 24, 2010, 05:47:50 AM</p><blockquote>Show some effort!!!! You have no idea what your are talking about! I have spent over 6 weeks reading books and researching several sites! I work on it around the clock! attempting to use the example below! I just don't post all my efforts here! I would have over 20 pages of crap!<br/></blockquote>sidewinder has shown you how to do it with batch, although not to your requirement. But i am expecting you follow his guidance on that piece of snippet and work on it. That's the effort i am talking about. I am not expecting you to post all your already done scripts here. So i am saying, are you really waiting for him to solve your own (project/homework) problem? <br/><br/>Quote<blockquote>If you decide not to help! Then do so Keep your replies silents! I don't need any negitive responces! Thank you! <br/></blockquote>we are not here to do your work/project for you. As you already saw, I have helped you a lot. I have shown you ways you could do it with ease, and others have shown you native ways to do it with batch and vbscript. BUT the problem is caused by you yourself. Only DOS is allowed ? Typical project/school homework restriction , isn't it ? <br/><br/>If the DOS you mentioned is really the MSDOS 6.22 , it most probably can't be done in a pure DOS, except you have to use some extra tools. If it can be done, it would probably be obscure and arcane. Either way, you are on my blacklist of people not to help from now on.<br/>I must have misinterpreted your original post about the numerics after the <strong>PT</strong> to be deleted too. In any case, that created a real problem when trying to create a batch file to do just that. Seems those special characters in the data file cause the NT interpreter to choke.<br/><br/>By the way, the VBScript I posted only removed the <strong>PT</strong> not the following numerics. This little ditty fixes that problem:<br/><br/>Code: <a>[Select]</a>Const ForReading = 1<br/>Const ForWriting = 2<br/><br/>Set fso = CreateObject("Scripting.FileSystemObject")<br/>Set objRE = CreateObject("VBScript.RegExp")<br/>objRE.Global = True<br/>objRE.IgnoreCase = False<br/><br/>Set inFile = fso.OpenTextFile("d:\wfc\sniplib\WSH-RegEx-putSearchReplace.txt", ForReading)<br/>Set outFile = fso.OpenTextFile("c:\temp\Regex.chg", ForWriting, True)<br/><br/>Do Until inFile.AtEndOfStream<br/> strLine = inFile.ReadLine<br/> objRE.Pattern = "^GOTO\s(.*?)\bPT\s{2}[0-9]{1,}\b"<br/> Set colMatches = objRE.Execute(strLine)<br/> If colMatches.Count &gt; 0 Then <br/>' objRE.Pattern = "PT\s{2}" 'remove PT leave remaining digit(s)<br/> objRE.Pattern = "PT\s{2}[0-9]{1,}\b" 'remove PT and remaining digit(s) <br/> strLine = objRE.Replace(strLine, "")<br/> End If<br/> outFile.WriteLine strLine<br/>Loop<br/><br/>Considering you have Win7 and all those tools available, I would have thought a batch solution would be your last choice.<br/><br/>Good luck. Thank You Sidewinder! I got your vb to work as well! Yes there was issues<br/>understanding my orginal request! I read everything I could find on the subject! But there seem to be no way to do this in DOS! Learn alot from U<br/>and your example! Thank many time more! <br/>Sorry ghostdog74 you feel that way! And as Sidewinder has come to undrstand that my orginal requirements were missunderstoud! Which I attempted to point out with several examples! I want no one to do my work! I had a programming issue and tried to throw it out here to help myself and others <a href="https://interviewquestions.tuteehub.com/tag/learning-15934" style="font-weight:bold;" target="_blank" title="Click to know more about LEARNING">LEARNING</a> batch programming on DOS, which I'm more<br/>than sure this solution will! I'm well versed in Pearl &amp; writing UNIX Scripts,<br/>both would only require one liners to solve this issue! But there was a company standard for whatever reason to only use DOS! which I'm attempting to do! Best Wishes and Thanks for your help in the pass as well!<br/>Quote from: graymj on August 24, 2010, 08:56:41 AM<blockquote> I'm well versed in Pearl <br/></blockquote><br/><a href="https://en.wikipedia.org/wiki/PEARL_%28programming_language%29">Pearl?</a><br/><br/>For some reason I suspect you meant:<br/><br/><a href="https://en.wikipedia.org/wiki/Perl">Perl</a><br/><br/>That would be correct! Thanks for the correction! I hate unfinished business, so I came up with this monstrosity. I apologize if it looks something like Curly the Neanderthal would mark on the cave wall. I gotta learn to stop over thinking things.<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/>if exist c:\temp\regex.chg del c:\temp\regex.chg<br/><br/>for /f "tokens=* delims=" %%f in (c:\temp\regex.txt) do (<br/> set strLine=%%f<br/> set subLine=!strLine:~0,4!<br/> if /i .!subLine! EQU .GOTO call :getLoc<br/> echo !strLine! &gt;&gt; c:\temp\regex.chg<br/>)<br/>goto :eof<br/><br/>:getLoc<br/> for /l %%i in (0, 1, 67) do (<br/> call set strChunk=%%strLine:~%%i,2%%<br/> if .!strChunk! EQU .PT call set strLine=%%strLine:~0,%%i%% &amp; goto :eof<br/><br/> )<br/> goto :eof<br/><br/>Change the file paths as appropriate. If the position of PT changes you <a href="https://interviewquestions.tuteehub.com/tag/may-557248" style="font-weight:bold;" target="_blank" title="Click to know more about MAY">MAY</a> need to change the 67 value in the <strong>for /l</strong> statement to increase the search range.<br/><br/>Good luck. WOW! HA HA! How did you come of with this? I can't <a href="https://interviewquestions.tuteehub.com/tag/wait-1448592" style="font-weight:bold;" target="_blank" title="Click to know more about WAIT">WAIT</a> to try it!<br/><br/>the logic seem wild! I'm trying to break it down now! THANKSSSSSSSSSSS!HI Sidewinder It Works Great! Just having a few problems intergrateing into my code! but thats a small problem! also developeing a method to<br/>Identify which column the PT start and pass that value to your routine!<br/>You're the BEST! THANKS AGAIN &amp; AGAIN!There is no need to send the starting position of <em>PT</em> to the routine. The whole point was to make the code generic. The code found <em>PT</em> in the data file you posted at offset 64 in all the records that contained it.<br/><br/>The <strong>:getLoc</strong> routine processes records that have <em>GOTO</em> in the first four bytes. By starting at offset 0 (record position 1), it increases the record position by 1, reading 2 byte chunks of the record until <em>PT</em> is found or offset 67 is reached, <a href="https://interviewquestions.tuteehub.com/tag/whichever-2326632" style="font-weight:bold;" target="_blank" title="Click to know more about WHICHEVER">WHICHEVER</a> comes first. The 67 was arbitrary. Once the offset of <em>PT</em> is found (stored in the %%i token), the code uses truncation to eliminate the high order bytes. The logic is fairly simple, it was the batch notation that was challenging.<br/><br/>The <strong>FOR /L %variable IN (start,step,end) DO</strong> statement uses the "end" parameter as the indicator when to stop the loop. In this case it represents the highest offset to check before quitting the loop. You can <a href="https://interviewquestions.tuteehub.com/tag/exceed-978351" style="font-weight:bold;" target="_blank" title="Click to know more about EXCEED">EXCEED</a> the record length without the code throwing an error. Ensure the "end" parameter is large enough to include the entire record without being so large as to needlessly waste CPU cycles.<br/><br/>The code can probably be tweaked for more efficiency. For instance, the search for <em>PT </em>could start at offset 4; we already know offsets 0-3 contains <em>GOTO</em><br/><br/>Hope this helps. Thanks! I was busy changeing the 67 thinking it was a start position! but after checking out other sites realized it was like an range! Your explanation was great! This is avery useful piece of code! Thx Again for the info!Is there a way to modify the VBS code example (posted by Sidewinder - thanks by the way) to replace the expression found, ie, find /.*$ (evrything from the slash to enf of line) and replace it with a blank? I am new to vbs, and am not sure what the syntax is to substitute something for the found expression - <br/><br/>In advance, thanks!Scratch my previous post, I did not see the ealier post from Sidewinder with an example of exactly what I needed (once again, thanks very much!). I modified it slightly for what I needed (below), and it works beautufully.<br/>Thanks Sidewinder!!<br/><br/>Const ForReading = 1<br/>Const ForWriting = 2<br/><br/>Set fso = CreateObject("Scripting.FileSystemObject")<br/>Set objRE = CreateObject("VBScript.RegExp")<br/>objRE.Global = True<br/>objRE.IgnoreCase = True<br/><br/>Set inFile = fso.OpenTextFile("c:\temp\test3.txt", ForReading)<br/>Set outFile = fso.OpenTextFile("c:\temp\test33.txt", ForWriting, True)<br/><br/>Do Until inFile.AtEndOfStream<br/>strLine = inFile.ReadLine<br/>objRE.Pattern = "=/.[^/]*"<br/>Set colMatches = objRE.Execute(strLine)<br/>If colMatches.Count &gt; 0 Then <br/>objRE.Pattern = "=/.[^/]*" 'remove everyting from = up to but not including next /, replace with =<br/>strLine = objRE.Replace(strLine, "=")<br/>End If<br/>outFile.WriteLine strLine<br/>LoopTo replace all occurrences of one string in a file by another string, there is even a simpler solution:<br/><br/>@echo off<br/>setlocal enabledelayedexpansion<br/>for /f "tokens=* delims=" %%f in (%1) do (<br/> set strLine=%%f<br/> set strLine=!strLine:= !<br/>:: tab^ ^space<br/> echo !strLine! &gt;&gt; %1<br/>)Update: <br/><br/>1) The output file, of course should be #2 :-(<br/>2) Only exclamation marks, the text between two exclamation marks, and empty lines that are lost. All the other known problem characters (both outside and inside of "..." and "%...%") are retained.</body></html>
8740.

Solve : Copying files from a corrupted drive using "xcopy" from the Command Prompt?

Answer» <html><body><p>Hello... I originally posted this in the Windows 7 forum, but I think it's more of an MS DOS issue, and hopefully someone here can help...<br/><br/>I was running a freeware defrag program when the process halted (prob. due to loss of power/sleep mode) and my laptop no longer boots from the hard drive when powered on. Win7 startup repair does not restore the system. Using the Command Prompt I can still <a href="https://interviewquestions.tuteehub.com/tag/see-630247" style="font-weight:bold;" target="_blank" title="Click to know more about SEE">SEE</a> my files, but there are no 'autoexec.bat', 'config.sys' or 'command.exe' files on the <a href="https://interviewquestions.tuteehub.com/tag/root-237331" style="font-weight:bold;" target="_blank" title="Click to know more about ROOT">ROOT</a> (and I'm not 100% sure that Win 7 even uses them). I think I may have to reformat and reinstall to my factory original disks, which will reformat my hard drive and destroy months of data.<br/><br/>Before I do that, I want to try to save the "my documents" files to an external drive, then reload them after the rebuild. I intend to use the 'xcopy' function from the Command Prompt to copy the entire c:\ drive to the external drive, then when my machine is rebuilt, copy all of my documents back.<br/><br/>I plan on using the "xcopy c:\*.* /a /e /k" command from inside the root directory of the external drive. <br/><br/>Will this work, and does anyone have any other advice for me to try before I reformat my drive?<br/><br/>My laptop is a Toshiba Satellite 505 - s6005, and I'm running Win 7 Home and Office 64bit.<br/><br/>Thank you for any help you can give...<br/>Tom<br/>Seaview1231. The most conservative recovery method is 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> another HDD for that laptop and install Windows. The make the old HDD a USB device using an adapter.<br/><br/>2. Alternative to this is to use a Desktop PC to backup the original drive as a slave drive, using another <a href="https://interviewquestions.tuteehub.com/tag/type-238192" style="font-weight:bold;" target="_blank" title="Click to know more about TYPE">TYPE</a> of adapter, if needed.<br/><br/>3. Another approach is to boot a Linux distro from a USB device and see if you can locate important files and burn them to a DVD. <br/><br/>4. Or, thaxter are some third party Windows tools that do what you would do with the Linux USB device. <a href="https://interviewquestions.tuteehub.com/tag/check-25817" style="font-weight:bold;" target="_blank" title="Click to know more about CHECK">CHECK</a> this:<br/><a href="http://www.ubcd4win.com/howto.htm">http://www.ubcd4win.com/howto.htm</a><br/><br/>Otherwise, trying to recovery files using a corrupt system is often futile. And may even be destructive.<br/>And that is not just IMHO.</p></body></html>
8741.

Solve : Calling a JDK command?

Answer» <html><body><p>I have a question about using a command from the JDK. I <a href="https://interviewquestions.tuteehub.com/tag/plan-25498" style="font-weight:bold;" target="_blank" title="Click to know more about PLAN">PLAN</a> to distrubite the <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a> to clients, will they <a href="https://interviewquestions.tuteehub.com/tag/need-25476" style="font-weight:bold;" target="_blank" title="Click to know more about NEED">NEED</a> to have the specific JDK command file in 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> or will the batch file work without them having the JDK?depends what program ("command") it is you are running from the JDK.</p></body></html>
8742.

Solve : Looping and Zipping of folders?

Answer» <html><body><p>Hi All,<br/><br/>I am new to Dos Batch. My problem now is that I need to loop through a directory with many subfolders. I need to zip those subfolders (using <a href="https://interviewquestions.tuteehub.com/tag/7zip-336341" style="font-weight:bold;" target="_blank" title="Click to know more about 7ZIP">7ZIP</a>) and place the zipped subfolders into another directory. <br/><br/>Before zipping<br/>My main root is C:\Users\ayaka\Desktop\ZipTask\TestingDirectory<br/>Sample <a href="https://interviewquestions.tuteehub.com/tag/folders-994110" style="font-weight:bold;" target="_blank" title="Click to know more about FOLDERS">FOLDERS</a>:<br/>C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\April2001\temp123\temp123.html<br/>C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\April2001\temp234\temp234.html<br/>C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\May2001\temp345\temp345.html<br/>C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\May2001\temp456\temp456.html<br/><br/>After zipping<br/>C:\Users\ayaka\Desktop\ZipTask\TestDir<br/><br/>The folders should be zip according to the month and year. So, there should be 2 zipped folders, mainly April2001 and May2001 in C:\Users\ayaka\Desktop\ZipTask\TestDir<br/><br/>I had done <a href="https://interviewquestions.tuteehub.com/tag/abit-3528390" style="font-weight:bold;" target="_blank" title="Click to know more about ABIT">ABIT</a> of coding, but it doesn't really work. <br/><br/>Here's the code:<br/><br/>Code: <a>[Select]</a>@ECHO off <br/><br/><br/>FOR /R C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\ %%G IN (*) DO (<br/><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-7 delims=\ " %%i in ("%%G") do (<br/>Set folder=%%o<br/>Set path=%%i\%%j\%%k\%%l\%%m\%%n\%%o <br/><br/>cd C:\Users\ayaka\Desktop\ZipTask\7za920<br/><br/>7za.exe a -t7z %path%\%folder%.7z C:\Users\ayaka\Desktop\ZipTask\TestDir<br/><br/><br/>)<br/><br/>)<br/>@ECHO on<br/><br/>Can anyone help me? Thanks.I managed to create the batch file to do it. But I have no idea why the program stopped after the first zipped folder is made.<br/><br/>Here's the new code:<br/><br/>Code: <a>[Select]</a>@ECHO off<br/>FOR /R C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\ %%G IN (*) DO (<br/>FOR /f "tokens=1-7 delims=\ " %%i in ('dir /b /s "%%G"') do (<br/><br/>IF NOT EXIST C:\Users\ayaka\Desktop\ZipTask\TestDir\%%o.7z (<br/><br/>echo %%i\%%j\%%k\%%l\%%m\%%n\%%o<br/><br/>cd C:\Users\ayaka\Desktop\ZipTask\7za920<br/><br/>7za.exe a -t7z C:\Users\ayaka\Desktop\ZipTask\TestDir\%%o.7z C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\%%o<br/>)<br/>)<br/>)<br/>@ECHO on<br/><br/>Output:<br/>C:\Users\ayaka\Desktop\ZipTask\TestDir\April2004.7z<br/><br/>The output should also include this file, but the program did not continue:<br/>C:\Users\ayaka\Desktop\ZipTask\TestDir\May2004.7zFinally, I made it. But it will take a very long time if there are alot of folders in each folder and many files in each folder.<br/><br/>Here's the code:<br/><br/>Code: <a>[Select]</a>@echo off<br/><br/>echo.going to execute loop<br/>call:loop<br/>echo.returned from loop<br/>echo.&amp;pause&amp;goto:eof<br/><br/>:loop<br/>FOR /R C:\Users\ayaka\Desktop\ZipTask\TestDir\ %%G IN (*) DO (<br/>echo.going to execute cont<br/>call:cont %%G<br/>echo.returned from cont<br/>)<br/>echo.going back to loop<br/>echo.&amp;pause&amp;goto:eof<br/><br/>:cont<br/>FOR /f "tokens=1-7 delims=\ " %%i in ('dir /b /s "%~1"') do (<br/>echo %%i\%%j\%%k\%%l\%%m\%%n\%%o &amp;<a href="https://interviewquestions.tuteehub.com/tag/gt-249387" style="font-weight:bold;" target="_blank" title="Click to know more about GT">GT</a>;&gt; path.txt<br/>IF NOT EXIST C:\Users\ayaka\Desktop\ZipTask\testingFolder\%%o.7z (<br/>cd C:\Users\ayaka\Desktop\ZipTask\7za920<br/>7za.exe a -t7z C:\Users\ayaka\Desktop\ZipTask\testingFolder\%%o.7z C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\%%o<br/>)<br/>)<br/>goto:eof<br/><br/>Anybody has any idea on how to improve this? So that it can be done efficiently?</p></body></html>
8743.

Solve : Find Replace filename batch?

Answer» <html><body><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: Salmon Trout on September 08, 2011, 12:55:03 PM<blockquote>Are the people who own the network your employers?<br/></blockquote><br/>Yes.Quote<blockquote>It really blows my mind, how far afield batch programming has gotten in the past few years.<br/>It seems like many jobs would be better done in a <a href="https://interviewquestions.tuteehub.com/tag/much-249971" style="font-weight:bold;" target="_blank" title="Click to know more about MUCH">MUCH</a> higher programming language.<br/><br/>When I started writing batch files back in the DOS 2.0 days, <a href="https://interviewquestions.tuteehub.com/tag/things-25910" style="font-weight:bold;" target="_blank" title="Click to know more about THINGS">THINGS</a> were certainly a lot simpler.<br/>And if I couldn't write a batch file to do <a href="https://interviewquestions.tuteehub.com/tag/something-25913" style="font-weight:bold;" target="_blank" title="Click to know more about SOMETHING">SOMETHING</a>, I just did it manually.</blockquote><br/>I agree. It seems like batch used to be a very simple and concise language, but then they started adding on more and more s*** and now it seems like it has pretty much no regular structure and an awkward <a href="https://interviewquestions.tuteehub.com/tag/syntax-14178" style="font-weight:bold;" target="_blank" title="Click to know more about SYNTAX">SYNTAX</a>.</body></html>
8744.

Solve : Search file and edit it?

Answer» <html><body><p>1. Test.vdf (before)<br/><br/>Code: <a>[Select]</a>{ <br/> { <br/> Section 1 <br/> } <br/> { <br/> Section <a href="https://interviewquestions.tuteehub.com/tag/2-236987" style="font-weight:bold;" target="_blank" title="Click to know more about 2">2</a> <br/> } <br/> { <br/> Section 3 <br/> } <br/> { <br/> Section 4 <br/> } <br/>} <br/><br/>2. Script<br/><br/>Code: <a>[Select]</a>@echo off<br/>setlocal enabledelayedexpansion<br/>for /f "delims==" %%A in ('dir /b /s S:\*.vdf') do (<br/> set filepath=%%~dpA<br/> set filename=%%~nA<br/> set fileExtn=%%~<a href="https://interviewquestions.tuteehub.com/tag/xa-1463393" style="font-weight:bold;" target="_blank" title="Click to know more about XA">XA</a><br/> )<br/>Echo Found file<br/>Echo Path %filepath%<br/>Echo Name %filename%%fileExtn%<br/>cd /d "%filepath%"<br/>set linecount=0<br/>for /f "delims=" %%A in ('type "%filename%%fileExtn%"') do set /a linecount+=1<br/>if exist "%filename%-new%fileExtn%" del "%filename%-new%fileExtn%"<br/>set linenumber=0<br/>for /f "delims=" %%A in ('type "%filename%%fileExtn%"') do (<br/> set /a linenumber+=1<br/> if !linenumber! equ %linecount% (<br/><br/> echo { &gt;&gt; "%filename%-new%fileExtn%"<br/> echo Section <a href="https://interviewquestions.tuteehub.com/tag/5-237653" style="font-weight:bold;" target="_blank" title="Click to know more about 5">5</a> &gt;&gt; "%filename%-new%fileExtn%"<br/> echo } &gt;&gt; "%filename%-new%fileExtn%"<br/> echo } &gt;&gt; "%filename%-new%fileExtn%"<br/><br/> ) else (<br/> echo %%A &gt;&gt; "%filename%-new%fileExtn%"<br/> )<br/> )<br/>echo Rename<br/>echo ren "%filename%%fileExtn%" "%filename%-<a href="https://interviewquestions.tuteehub.com/tag/old-585313" style="font-weight:bold;" target="_blank" title="Click to know more about OLD">OLD</a>%fileExtn%"<br/>ren "%filename%%fileExtn%" "%filename%-old%fileExtn%"<br/>echo ren "%filename%-new%fileExtn%" "%filename%%fileExtn%"<br/>ren "%filename%-new%fileExtn%" "%filename%%fileExtn%"<br/>echo done<br/><br/>1. Test.vdf (after)<br/><br/>Code: <a>[Select]</a>{ <br/> { <br/> Section 1 <br/> } <br/> { <br/> Section 2 <br/> } <br/> { <br/> Section 3 <br/> } <br/> { <br/> Section 4 <br/> } <br/> { <br/> Section 5 <br/> } <br/>} <br/></p></body></html>
8745.

Solve : Script runs in CMD window but not from .bat file?

Answer» <html><body><p>I have this string that I use to read a directory of files and then process them according to the second part of the string.<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/works-17618" style="font-weight:bold;" target="_blank" title="Click to know more about WORKS">WORKS</a> fine when i directly enter it into a CMD window, but when writing it into a .bat file, the CMD flashes and goes <a href="https://interviewquestions.tuteehub.com/tag/away-386546" style="font-weight:bold;" target="_blank" title="Click to know more about AWAY">AWAY</a> <a href="https://interviewquestions.tuteehub.com/tag/aeuroewithout-1475023" style="font-weight:bold;" target="_blank" title="Click to know more about WITHOUT">WITHOUT</a> processing the files. The directory may contain up to 4000 files and what I am trying to do is loop through each file in the directory and insert the data into a Database. And as I said, works fine when I manually <a href="https://interviewquestions.tuteehub.com/tag/paste-597094" style="font-weight:bold;" target="_blank" title="Click to know more about PASTE">PASTE</a> it into a CMD window, but when running from .bat file, doesn't work.<br/><br/>Here is the string.. any suggestions?<br/><br/>for /f %A IN ('dir /b C:\scripts\files\work\out\*.txt') do call <a href="https://interviewquestions.tuteehub.com/tag/load-11593" style="font-weight:bold;" target="_blank" title="Click to know more about LOAD">LOAD</a> AR01 -file "C:\scripts\files\work\out\%A" -addAt command prompt FOR variables have one percent sign: %A <br/><br/>In a batch script they have two percent signs: %%A<br/><br/><br/></p></body></html>
8746.

Solve : Copy / Xcopy?

Answer» <html><body><p>Sorry for all the old questions but it has been awhile since I have been in the DOS thing that I have forgotten everything. What is the difference between copy and xcopy? Can I delete a whole directory with one of those?<a href="https://www.google.com/search?hl=en&amp;rlz=1B3MOZA_en-GBUS386US388&amp;q=difference+between+copy+and+xcopy&amp;aq=f&amp;aqi=g3g-m1&amp;aql=&amp;oq=&amp;gs_rfai=">http://www.google.com/search?hl=en&amp;rlz=1B3MOZA_en-GBUS386US388&amp;q=difference+between+copy+and+xcopy&amp;aq=f&amp;aqi=g3g-m1&amp;aql=&amp;oq=&amp;gs_rfai=</a>xcopy is for directories and files. copy will only move files from one location to another. You cannot delete using xcopy or copy. If you want to delete, use del and if you want to remove a directory use rmdir.8)HOW DO I TRANSFER ALL FILES FROM ONE HARD <a href="https://interviewquestions.tuteehub.com/tag/drive-959713" style="font-weight:bold;" target="_blank" title="Click to know more about DRIVE">DRIVE</a> TO ANOTHER SO I CAME BOOT FROM THAT DRIVE <br/>IN XP PROBoomer960 - Welcome to the <a href="https://interviewquestions.tuteehub.com/tag/ch-241780" style="font-weight:bold;" target="_blank" title="Click to know more about CH">CH</a> forums.<br/><br/>Please don't hijack another member's thread, start one of your own.<br/><br/>To achieve what you want you have to clone the drive using dedicated software. I use XXClone (a free restricted version is available) and there are other packages available on the WWW.<br/><br/>Good luckAfter read and re-reading my post I am trying to remember What was I <a href="https://interviewquestions.tuteehub.com/tag/thinking-771898" style="font-weight:bold;" target="_blank" title="Click to know more about THINKING">THINKING</a>? I know that you can not delete in copy or xcopy, I was asking about moving files. Thanks for the help."Move" is nothing more than Copy + Delete, without verification.<br/>It's actually sort of a dangerous command, as I found out, years ago, when I was working just in DOS.<br/><br/>The list of switches for XCOPY is <a href="https://interviewquestions.tuteehub.com/tag/extensive-981051" style="font-weight:bold;" target="_blank" title="Click to know more about EXTENSIVE">EXTENSIVE</a> and allows the command to do a lot of work, with a lot of selectivity.<br/><br/>I use it daily to back up all my data files, that are new or have just been changed, to like folders in my Backup hard drive.<br/>That totally precludes me loosing any of my data in case my main drive goes up in a big ball of fire and smoke.<br/>Don't laugh.....that CAN happen.<br/><br/>Cheers!<br/>I'm not sure if you are working in a post XP environment or not, but there is also the functionality of robocopy. It has the ability to selectively include or selectively exclude files and directories, it allows you to mirror attributes, or only copy certain attributes, to change certain flags on files, and a lot of other tricks. I believe they only introduced it in the Vista command prompt and later, but if you are in that environment, it's definitely worth checking out. Just try a robocopy /? |more in your cmd line and take a look at all the goodies available (including log filing, in case you want to set up a routine backup with logging capability.) I personally have a backup that runs robocopy daily, with a logging function that names the log file the current date so I don't get confused when something was first backed up. Oh, and thats the other cool thing about robocopy, when you are using it in a backup style capacity, is it will automatically skip files that are already in the new location (can be toggled) so you don't have to worry about the time it takes to copy an entire directory, it will only copy new (or newer <a href="https://interviewquestions.tuteehub.com/tag/versions-244825" style="font-weight:bold;" target="_blank" title="Click to know more about VERSIONS">VERSIONS</a> of) files. It also has a /mov switch if you are wanting to delete the source after the copy (as you suggested originally), and /purge or /mir switches to make the destination look just like the source.</p></body></html>
8747.

Solve : Auto unrar?

Answer» <html><body><p>Hi guys.<br/>I found this script on another forum and it works like a charm.<br/><br/>Code: <a>[Select]</a>@REM ------- BEGIN demo.cmd ----------------<br/>@setlocal<br/>@echo off<br/>set <a href="https://interviewquestions.tuteehub.com/tag/path-11833" style="font-weight:bold;" target="_blank" title="Click to know more about PATH">PATH</a>="C:\Program Files\WinRAR\";%path%<br/>for /F %%i in ('dir /s/b *.rar') do call :do_extract "%%i"<br/><a href="https://interviewquestions.tuteehub.com/tag/goto-1009988" style="font-weight:bold;" target="_blank" title="Click to know more about GOTO">GOTO</a> :eof<br/><br/>:do_extract<br/>echo %1<br/>mkdir %~1.extracted<br/>pushd %~1.extracted<br/>unrar e %1<br/>popd<br/><br/>REM ------- END demo.cmd ------------------<br/>There's only one problem. Somethimes the .rar <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a> is named<br/>file_name.part1.rar<br/>file_name.part2.rar<br/>file_name.part3.rar<br/>and so on<br/>. So if it is 24 parts it means that the file/movie or what ever will be unpacked 24 times <br/>I've tried to search the web for an answer but cant find anything.One way would be to process the rar file or files in 2 stages:<br/><br/>1. The rar files which do not have ".part" in the name.<br/><br/>2. The rar files whose name <a href="https://interviewquestions.tuteehub.com/tag/ends-971392" style="font-weight:bold;" target="_blank" title="Click to know more about ENDS">ENDS</a> with ".part1.rar".<br/><br/>By the way, I fixed a few <a href="https://interviewquestions.tuteehub.com/tag/things-25910" style="font-weight:bold;" target="_blank" title="Click to know more about THINGS">THINGS</a> in that script... it handles files with spaces in the names now.<br/><br/>Code: <a>[Select]</a>@setlocal<br/>@echo off<br/>set path="C:\Program Files\WinRAR\";%path%<br/>for /F "delims=" %%i in ('dir /s/b *.rar ^| find /v ".part"') do call :do_extract "%%i"<br/>for /F "delims=" %%i in ('dir /s/b *.part1.rar') do call :do_extract "%%i"<br/>goto end<br/> <br/>:do_extract<br/>echo %1<br/>mkdir "%~1.extracted"<br/>pushd "%~1.extracted"<br/>echo unrar "%1"<br/>unrar e "%~dpnx1"<br/>popd<br/>goto :eof<br/><br/>:end<br/><br/>sorry, accidentally clicked "quote"<br/>Sweet. I'll test it asap.<br/>Thanks for the help</p></body></html>
8748.

Solve : How to give xml file name as input?

Answer» <html><body><a href="https://interviewquestions.tuteehub.com/tag/hello-484176" style="font-weight:bold;" target="_blank" title="Click to know more about HELLO">HELLO</a> Folks,<br/><br/><br/>Need help to pick right dos command.<br/><br/>I have a requirement to create a Batch file 'Y', that runs a batch file 'X'<br/><br/>The batch file 'X' has command that calls a program <a href="https://interviewquestions.tuteehub.com/tag/build-403683" style="font-weight:bold;" target="_blank" title="Click to know more about BUILD">BUILD</a> in java, when batch file 'X' is <a href="https://interviewquestions.tuteehub.com/tag/executed-979171" style="font-weight:bold;" target="_blank" title="Click to know more about EXECUTED">EXECUTED</a> it ask to input name of a an .<a href="https://interviewquestions.tuteehub.com/tag/xml-11549" style="font-weight:bold;" target="_blank" title="Click to know more about XML">XML</a> file. <br/><br/>can you please help with command to give .xml file name as input to dos <br/><br/>Thanks,<br/>Syed<br/><br/><br/><br/><br/>Generally the <strong>set</strong> command is used to prompt for input in a batch file:<br/><br/>Code: <a>[Select]</a>SET /P variable=[promptString]<br/><br/><strong>Example:</strong><br/>Code: <a>[Select]</a>set /p xml=Enter XML file name: <br/><br/>The prompt <em>Enter XML file name: </em>will <a href="https://interviewquestions.tuteehub.com/tag/appear-2437800" style="font-weight:bold;" target="_blank" title="Click to know more about APPEAR">APPEAR</a> on the console and wait for user input. When the user enters a response, the value entered will be available in the <strong>%xml%</strong> variable.<br/><br/>Quote<blockquote>The batch file 'X' has command that calls a program build in java, when batch file 'X' is executed it ask to input name of a an .XML file. <br/></blockquote><br/>This is ambiguous. Does the batch file request the input file name or does the Java program?<br/><br/>Good luck. Thanks For the response. Its actually Java Program needs input file</body></html>
8749.

Solve : Bat to test existence of a file on list of computers and copy new file.?

Answer» <html><body><p>Hi All<br/><br/>I would appreciate some <a href="https://interviewquestions.tuteehub.com/tag/help-239643" style="font-weight:bold;" target="_blank" title="Click to know more about HELP">HELP</a> with this batch file. <br/><br/>I'm trying to write a bat file to ...<br/><br/>1. Interrogate several computers, listed in a .txt file (currently only contains 3 hosts for test purposes)<br/>2. Check for the instance of a specific file (indicating the installation of a specific application)<br/>3. If the file doesn't exist, comment to that effect.<br/>4. If the file does exist, overwrite it with an amended file (without user response).<br/>5. Send the results of the bat file operations to a separate log file.<br/><br/>The code I'm using is ...<br/><br/>Code: <a>[Select]</a>FOR /F %%a IN (C:\FraserDATA\BATs\LispProblems\ComputerList.txt) do (<br/>IF EXIST "c$\Program Files\AutoCAD Architecture 2010\Support\acad2010doc.lsp" GOTO COPY_FILE<br/>echo File doesn't exist<br/>echo.<br/>echo \\%%a ##################<br/>echo.<br/>) &gt;&gt;C:\FraserDATA\BATs\LispProblems\FileCopied.txt<br/>:COPY_FILE<br/>COPY C:\FraserDATA\BATs\LispProblems\acad2010doc.lsp "\\%%a\c$\Program Files\AutoCAD Architecture 2010\Support\" /y<br/><br/>pause<br/><br/>The only result I'm getting is "File doesn't exist" for each computer entry (one definitely has the requiste folder/file entry).<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/anyones-2436475" style="font-weight:bold;" target="_blank" title="Click to know more about ANYONES">ANYONES</a> help or <a href="https://interviewquestions.tuteehub.com/tag/guidance-25562" style="font-weight:bold;" target="_blank" title="Click to know more about GUIDANCE">GUIDANCE</a> would be very much appreciated.<br/>Quote</p><blockquote>Interrogate several computers, listed in a .txt file (currently only contains 3 hosts for test purposes)</blockquote><br/>We don't do that here.Quote<blockquote>We don't do that here.</blockquote><br/>Not sure what is meant by this comment. I am administering a <a href="https://interviewquestions.tuteehub.com/tag/network-236637" style="font-weight:bold;" target="_blank" title="Click to know more about NETWORK">NETWORK</a> of some 400+ computers, some with CAD installed. Several have been infected with a mild worm that has corrupted a .lsp file. I wanted to interrogate each computer, check for the existence of the program and replace the corrupt file.<br/><br/>I thought that this was a forum where I would be able to find some sensible help regarding a few problems I have in in writing a batch file to that effect. <br/><br/>Apologies for my ignorance.<br/>You generate a computer name in the %%a variable but then fail to use it in existence test.<br/><br/>Try it this way:<br/><br/>Code: <a>[Select]</a>IF EXIST "\\%%a\c$\Program Files\AutoCAD Architecture 2010\Support\acad2010doc.lsp" GOTO COPY_FILE<br/><br/>On another level, the logic seems illogical. If the <em>lsp</em> file exists, the logic goes to <em>copy_file</em>, drops into the pause, then exits the code. Try either moving the <em>copy_file</em> logic into the <strong>for</strong> statement and using a if/else construct, or, use a <strong>call</strong> instead of a <strong>goto</strong>, and use <strong>goto :eof</strong> statements after the <strong>for</strong> loop and after the the <strong>copy</strong> statement.<br/><br/>Why the <strong>pause</strong> statement? The output is redirected to a log file, so you shouldn't need it. Batch file are best run from 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> prompt.<br/><br/></body></html>
8750.

Solve : exit batch if copy fails?

Answer» <html><body><p>Hi, can anyone help me modify this batch file to exit if it fails to complete the 'copy' job<br/><br/>the main function of the batch file is to copy a test file from a source to a destination<br/>and count the time it takes to complete the copy<br/><br/>sometimes the destination computer is turned off so the comand <a href="https://interviewquestions.tuteehub.com/tag/window-11540" style="font-weight:bold;" target="_blank" title="Click to know more about WINDOW">WINDOW</a> displays '0 files copied' in stead of '1 file copied' <br/><br/>i need to add an 'if' satement so that the batch will jump to :end if the file fails to copy <br/><br/>@echo off<br/> <br/>FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Second /<a href="https://interviewquestions.tuteehub.com/tag/format-11876" style="font-weight:bold;" target="_blank" title="Click to know more about FORMAT">FORMAT</a>:table ^| findstr /r "."') DO ( <br/>set Milisecond=%time:~9,2% <br/>set Day=%%A<br/>set Hour=%%B<br/>set Minute=%%C<br/>set Second=%%D<br/>) <br/>set /a Start=%Day%*8640000+%Hour%*360000+%Minute%*6000+%Second%*100+%Milisecond%<br/> <br/>copy c:\temp\1meg.test \\COMPUTERX\c$\temp<br/>::::::: i need to jump from this point to the :end if this copy job fails to complete ::::::::<br/><br/>echo COMPUTER: ADL017 &gt;&gt; c:\temp\BENCHMARK\TIMER.log<br/>echo DATE: %DATE% &gt;&gt; c:\temp\BENCHMARK\TIMER.log<br/>echo tIME: %TIME% &gt;&gt; c:\temp\BENCHMARK\TIMER.log<br/> <br/>FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Second /Format:table ^| findstr /r "."') DO ( <br/>set Day=%%A<br/>set Hour=%%B<br/>set Minute=%%C<br/>set Second=%%D<br/>) <br/>set Milisecond=%time:~9,2% <br/>set /a End=%Day%*8640000+%Hour%*360000+%Minute%*6000+%Second%*100+%Milisecond%<br/>set /a Diff=%End%-%Start%<br/>set /a DiffMS=%Diff%%%100 <br/>set /a Diff=(%Diff%-%DiffMS%)/100 <br/>set /a DiffSec=%Diff%%%60 <br/>set /a Diff=(%Diff%-%Diff%%%60)/60 <br/>set /a DiffMin=%Diff%%%60 <br/>set /a Diff=(%Diff%-%Diff%%%60)/60 <br/>set /a DiffHrs=%Diff%<br/> <br/>:: format with leading zeroes <br/>if %DiffMS% LSS 10 set DiffMS=0%DiffMS!% <br/>if %DiffSec% LSS 10 set DiffMS=0%DiffSec%<br/>if %DiffMin% LSS 10 set DiffMS=0%DiffMin%<br/>if %DiffHrs% LSS 10 set DiffMS=0%DiffHrs%<br/> <br/>echo COUNTER: %DiffHrs%:%DiffMin%:%DiffSec%.%DiffMS% &gt;&gt; c:\temp\BENCHMARK\TIMER.log<br/><br/>echo **************************************** &gt;&gt; c:\temp\BENCHMARK\Timer.LOG<br/><br/>:end Code: <a>[Select]</a>copy c:\temp\1meg.test \\COMPUTERX\c$\temp || goto endThe way I understand it is that you what the bat file to copy a file and log how long it takes. And for the bat file to end if it can't <a href="https://interviewquestions.tuteehub.com/tag/find-11616" style="font-weight:bold;" target="_blank" title="Click to know more about FIND">FIND</a> it.<br/>I don't know why you have all the set statements. Here's <a href="https://interviewquestions.tuteehub.com/tag/one-241053" style="font-weight:bold;" target="_blank" title="Click to know more about ONE">ONE</a> that worked for me.<br/>@echo off<br/>echo Starting on %date% at %time%&gt;&gt;c:\users\bonz\bat\TIMER.log<br/>if not exist \\COMPUTERX\c$\temp\*.* goto NOTTHERE<br/><br/>copy c:\temp\1meg.test \\COMPUTERX\c$\temp<br/>echo 1meg.test has been copied to \\COMPUTERX\c$\temp &gt;&gt;c:\users\bonz\bat\TIMER.log<br/>echo Done copying at %time%&gt;&gt;c:\users\bonz\bat\TIMER.log<br/>goto end<br/><br/>:NOTTHERE<br/>echo Couldn't find \\COMPUTERX\c$\temp&gt;&gt;c:\users\bonz\bat\TIMER.log<br/>echo ending at %time%&gt;&gt;c:\users\bonz\bat\TIMER.log<br/><br/>:end<br/>echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&gt;&gt;c:\users\bonz\bat\TIMER.log<br/><br/>This is what printed to the TIMER.log file.<br/><br/>Starting on Sat 04/02/2011 at 23:28:39.74<br/>Couldn't find \\COMPUTERX\c$\temp<br/>ending at 23:29:00.95<br/>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/>As you can see, it also gave me the message that it couldn't find the destination as well as the starting date &amp; time and ending time. I noticed it took some time trying to find \\COMPUTERX\c$\temp. I counted off 21 seconds and that's what it shows in the TIMER.log file. (actually 21.21 seconds)</p></body></html>