This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 6701. |
Solve : Delete lines in txt files that contains an STRING or are BLANK.? |
|
Answer» Hello, Not sure how you have your pings setup, but you might want to build an outer loop to the snippet so you can iterate your multiple IP addresses or names. Thank you for response. I think I should have said from start that I am an beginer in batch files. I tried to use your code with my ping but don't works. I think I didn't used properly your code. Any sugestion of how to set up my pings is welcomed also. My pings setup now looks like this: Code: [Select]del ping.log date/t >>ping.log time/t >>ping.log ping -n 2 server1 >> ping.log ping -n 2 server2 >> ping.log Because I use it to ping nore than 25 servers at the time, the result log is very log and not easy to read. Sow I only want to make it easy to read and for that I want to cut out non needed lines. An DREAM would be, if its possible, to have an result like: Date Time SERVER1 RESPONDING SERVER2 NOT RESPONDING SERVER3 RESPONDING SERVER4 NOT RESPONDING Code: [Select]@echo off REM echo your server urls to a list REM first one uses >, the the rest use >> REM I only show 3 here for the sake REM of brevity echo www.google.com > servers.list echo www.bbc.co.uk >> servers.list echo www.yahoo-ht3.akadns.net >> servers.list REM now ping them & act according to REM the errorlevel returned for /f %%S in (servers.list) do ( ping %%S>nul if %errorlevel% EQU 0 ( echo %%S RESPONDING ) else ( echo %%S NOT RESPONDING ) ) Quote from: Dias de verano on December 13, 2008, 02:08:32 AM Code: [Select]@echo off Hello, Sorry for not respondig, but I didn't had ACCES to an computer for several days. Dias de verano, u'r code is almost perfect. I added only ECHO for having an result.txt but it seems to be an problem at ERRORLEVEL. No MATTER of pinged host the response is always RESPONDING. Here is the code i used, I cut off the messages for space: Code: [Select]@echo off echo 123.123.123.123 > servers.list echo www.bbc.co.uk >> servers.list echo www.yahoo-ht3.akadns.net >> servers.list for /f %%S in (servers.list) do ( ping %%S>nul if %errorlevel% EQU 0 ( echo %%S RESPONDING >> result.txt ) else ( echo %%S NOT RESPONDING >> result.txt ) ) My result.txt 123.123.123.123 RESPONDING www.bbc.co.uk RESPONDING www.yahoo-ht3.akadns.net RESPONDING Sorry, I made an oversight. @echo off setlocal enabledelayedexpansion REM echo your server urls to a list REM first one uses >, the the rest use >> REM I only show 3 here for the sake REM of brevity echo www.google.com > servers.list echo www.bbc.co.uk >> servers.list echo www.yahoo-ht3.akadns.net >> servers.list REM now ping them & act according to REM the errorlevel returned for /f %%S in (servers.list) do ( ping %%S>nul if !errorlevel! EQU 0 ( echo %%S RESPONDING>>result.txt ) else ( echo %%S NOT RESPONDING>>result.txt ) ) EXCELENT. THANK YOU VERY MUCH. |
|
| 6702. |
Solve : Batch File for pulling back info...? |
|
Answer» Hey, |
|
| 6703. |
Solve : Disable a .bat file on a specific date? |
|
Answer» How can I add a code to an existing .BAT file to prevent useage after a certain DATE |
|
| 6704. |
Solve : How do i copy the results of a program run in ms-dos to a txt-file?? |
|
Answer» I have to RUN a program in MS-DOS and I want the results of that program to be automatically written to a txt-file. Is this possible? |
|
| 6705. |
Solve : how to realize the function : set /p input value=: in Pure Dos? |
|
Answer» command line : set /p input value=: can be used in windows dos. but not in Pure dos. And I typed set /?, LOOKS like no /p parameters supported in my dos. So are there any other ways to realize this function in Pure dos? Thanks! command line : set /p input value=: can be used in windows dos NT machines only. Quote So are there any other ways to realize this function in Pure dos? I believe the choice command arrived with MS-DOS 5 and would be the closest alternative to getting input from set. Choice ALLOWS for single character input only, but does have a timer, which it seems many NT OS owners would kill for. Another alternative would be to WRITE your own command using the debug utility. Also try checking the net for programs input.com or answer.com. These were two 80's era programs that allowed for user input at the console. Actually, I want to store the keyboard input value into a variable, so I can use it in my bat file. Looks like input.com cannot realize that. Got it using Input.com!! Thanks Sidewinder for help!!can you please attach a copy of input.com to this post thanksYou can find the source code for a PROGRAM similar to input.com here. For all I know it may even be the original code for input.com. Your OS is not posted, but I'm fairly certain the debug utility was distributed with the earliest RELEASES of DOS. Follow the directions on how to assemble the code. Program only works in a MS-DOS Prompt window and not a Command Prompt window. Input is limited to a single word; a string with embedded spaces seems to break the code. Are we going back to the future? Personally I would have used QBasic. |
|
| 6706. |
Solve : listing used ip using DOS? |
|
Answer» i am WORKING workgroup with 15PC (Modem > Switch > 15PCs) |
|
| 6707. |
Solve : Multiple Set Commands?? |
|
Answer» Hello, |
|
| 6708. |
Solve : Need help with a game!? |
|
Answer» Hello i created this game but there are errors in it so can you help me |
|
| 6709. |
Solve : Copy a file and make numerous duplicate copies of the original...? |
|
Answer» Would a For Loop be needed? I am a beginner at DOS, so any code or pointers would be helpful! Is this EVEN POSSIBLE in DOS? |
|
| 6710. |
Solve : Do you want to Crack .exe to .bat? |
|
Answer» Here's how to crack a batch FILE compressed to exe file using bat2exe |
|
| 6711. |
Solve : visual basic 6 .exe not enabled? |
|
Answer» Hello Friends, i installed it as portable. The Pirate Edition. Oh dear. |
|
| 6712. |
Solve : Space in Output File? |
|
Answer» Hi! I'm using DOS on Windows XP. My database is PostgreSQL 8.2. I've been trying to code a small export process. My .bat runs a .sql that contains some basic select statements. The output is catted to a .txt file. However, every record (header, detail and trailer) in the .txt file contains a space as the first byte. I don't think the space is generated by the SQL as there is no space in the output when I cat the data to a temp table. I cannot figure out why a space is being INSERTED as the first byte of the .txt file. Any thoughts? The .bat code is below. My way was the quickest fix, but never mind. Never mind indeed! His problem was a space at the beginning of each line. Your "solution" is for a space at the END of each line.Quote from: Dias de verano on December 10, 2008, 11:38:32 AM Quote from: Jacob on December 10, 2008, 09:22:10 AMMy way was the quickest fix, but never mind. As I realized at 11 o'clock last night, sorry. |
|
| 6713. |
Solve : Batch - Start application with parameter help please? |
|
Answer» Trying to start an application from within a .bat file with a parameter, and not having any luck. I can start the program fine without the parameter using |
|
| 6714. |
Solve : Half-Life Dedicated Server Batch File? |
|
Answer» I decided to make an all-in-one batch file for server hosting for VALVE. I would like Batch to look in that directory for hldsupdatetool.exe and if its not there to download the installer from the link above. Download wget.exe and put it in the same folder as the batch then put this line in the batch if not exist "c:\srcds\hldsupdatetool.exe" wget.exe "http://www.steampowered.com/download/hldsupdatetool.exe" -o "c:\srcds\hldsupdatetool.exe" Old post alert. The SPAMMER (now DELETED) bumped a post from 2010. |
|
| 6715. |
Solve : need batch script to Keep Certain data from a text file.? |
|
Answer» Thank you all for you help again. I have one more question i was TRYING to use the path where the file is stored. and the script just quits instantly. example below.. |
|
| 6716. |
Solve : fc not recognized as an internal or external command.? |
|
Answer» So fc is actually a command, but it doesn't seem to work when I run the batch FILE. Any ideas? |
|
| 6717. |
Solve : Renaming files and deleting strings? |
|
Answer» I haven't touched batch files in some years so I have become a bit rusty. I have an excel spreadsheet that has two columns, the first column shows the old file name and the second shows the new file name. Copy the columns into a temporary spreadsheet and use a formula to assemble a batch command in a column then copy the column into Notepad and save it as a batch and then run it. |
|
| 6718. |
Solve : Batch file to restart wireless connection & program? |
|
Answer» Hi.. not familiar with scripting, reading many forums have pieced together an incorrect WAY of doing it.. so have GIVEN up and DECIDED to ask the experts |
|
| 6719. |
Solve : How to Echo this? |
|
Answer» Hi everyone, I've been trying to echo the following from a batch file to another batch file: Code: [Select]Echo.SET /p="Hello World"<NUL|clip >> "C:\File.bat"But in the new batch the file is BLANK, is SOMETHING missing? Do I need to add brackets? Note: The idea is to use the clip file to copy any assigned text. Thanks in advance Code: [Select]Echo.Set /p="Hello World"^<NUL^|clip >> "C:\File.bat" Modern Windows will not let you write to c:\ by default. Maybe use something like this "%temp%\file.bat" Hi foxidrive, Thanks for the SUGGESTION, but you know what, it doesn't matter where I set the script to be output, at the END I still get the same thing, an emty or blank batch file. I'am so sorry foxidrive, I inadvertently replied to you... You modified the code THANKS A MILLION, THANK YOU SO MUCH foxidrive, I would like to double thank you for helping me, that was so nice the way you solved my problem. Thank you so much. You're welcome - thanks for your feedback. I was a bit sneaky for not making it clear that I had changed your code. hehe |
|
| 6720. |
Solve : Create batch to archive files using main folder name for archive name? |
|
Answer» I am trying to create BATCH file and couldn't find solution anywhere on the web. |
|
| 6721. |
Solve : Send e-mails by batch? |
|
Answer» So i have looked all over and I cannot find a solution. Basically, I take complaints for a company, I would ILKE to have a batch file on my desktop that I can just click on and it opens a new message in outlook with a reciepient, multiple CC's, and a list in the body. |
|
| 6722. |
Solve : Search word? |
|
Answer» Hi, How write DOS program, which search all word "windows" of the all file text word? Your question is not clear. |
|
| 6723. |
Solve : How to set password in the password box? |
|
Answer» hi, Batch doesn't do this, but vbs might (I don't know enough vbs to tell you though.) you could always just use the windows FTP command, other than that, I don't know what to tell you. thank you for suggestion, now anyone expert in vbs please help me SOLVING my problem just GIVE me some coding please....If it cant be done in VBS, I know that it can be done with a macro recorder such as JitBit which you can create a routine even if your not a programmer pretty easily to populate this field with password. Then you can compile this macro as an exe and call to this exe from a batch file and it will run the process with no issues. I bought a single-user license of this software and its great!!! http://www.jitbit.com/macro-recorder/In FTP you can set autolgins to sites you have access to... Maybe you should CONSIDER that as a solution ? ? Here's Tons of Tips... |
|
| 6724. |
Solve : DOS use? |
|
Answer» I used to use DOS, a LONG time ago. I remember a little, but not a lot. Here is my problem: I have an OLD computer that does have some recent files on it. There are two hard drives in this machine, both with data I MUST retrieve. Recently, WIND98 went totally south in the machine. I do not know what caused it, nor how to fix it, but have not the time to fix it so I want to use DOS to retrieve what I need. I know most of the commands I think I need but do not remember how to properly use them. I need to know the following: Before I get out of everyone's hair, I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true?Yes, it is true, but with an explanation. Most DOS programs were written is the 16 bit mode. Modern programs must use 32 bit to work properly. I don't want to cause confusion with exact details, nut the devil is in the details. Here is an article that explains it in general terms. Does Windows 8 Support 16-bit Programs? The article shows there is a solution, but you may not like it. Read it. Then come back here with any questions. Quote from: DaAncientOne on August 24, 2013, 05:53:33 PM Before I get out of everyone's hair, I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true? No Windows NT System can use DOS. Allow me to explain as best I can, because it's a mite confusing. 1. First, we have DOS. 2. Now, we also are aware, of Windows 3.1 Stemming from Windows 3.1, there was also Windows 95, Windows 98, 98SE, and Windows ME. These ran on top of a DOS-based Subsystem. The DIFFERENCE comes with Windows 2000 and particularly XP. XP moved the entire consumer codebase over to Windows NT. Windows NT was up until that time designed primarily for workstations. It had No DOS sitting underneath everything and was in fact an entire standalone OS all on it's own. Windows NT Can run DOS Applications, but it runs it through the Command Prompt and the "NT Virtual DOS Machine". If you want to see this in action, start "command" from Start->Run, and check task manager. "NTVDM.EXE" will be shown proudly. The Command Prompt (cmd.exe) is not DOS; it is actually a complete Windows Application that provides a command prompt and the syntax and appearance is similar to DOS. Essentially, you could sort-of use DOS in XP, but only if you were lucky and the DOS applications you wanted to use still ran in the NT DOS Virtual Machine. 64-bit Windows has no NTVDM so you cannot run any DOS applications. 32-bit Windows 8 still includes the NTVDM, as far as I'm aware. Note that there is still a 64-bit version of cmd.exe and a 32-bit version of cmd.exe, so you can still use the Command Prompt. The "Command Prompt" is often considered analogous to DOS, but this is not the case.Quote from: DaAncientOne on August 24, 2013, 05:53:33 PM I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true? No. Windows 8 like every version has a command prompt and has many of the same commands that you will find in MSDOS and they work the same in most cases - except you have long filenames now, and more commands that MSDOS didn't have. 64 bit windows of any kind cannot run 16 bit programs.Quote 64 bit windows of any kind cannot run 16 bit programs.Right! The OP may want to know there is tie possibility of booting DOS from as USB stick or a mini CD. (Or a BIG CD if yh0ou don't care.) http://social.technet.microsoft.com/Forums/windows/en-US/e4696428-6999-4946-81c1-ea934eb6fd41/dos-622 Read the article. It is legal if you follow the instructions there. A DOS boot CD can be used for solving a number of issues with older programs and older computer Hard Drives. |
|
| 6725. |
Solve : Batch file executes some time and close.? |
|
Answer» Hi! sorry for my english. |
|
| 6726. |
Solve : Is there a DOS Command that is the same a "Find" command in regedit?? |
|
Answer» I have had unauthorized VISITORS in my computer that got in using Windows XP Remote Access software. I've eliminated their entries in the Win Registry. I have had unauthorized visitors in my computer that got in using Windows XP Remote Access software. I've eliminated their entries in the Win Registry. I also agree that it should be shut off as the fix. However there are other exploits out there other than the Windows XP Remote Access that can also give them remote access. A great free tool to use for home USERS is Secunia PSI. It will make you aware of any software you have that should be updated or is open to attack from hackers etc. http://secunia.com/vulnerability_scanning/personal/ I use this on my systems to keep track of what software I have installed may require security patches etc beyond the regular Windows Updates etc. I provides you with threat levels to know just how open to vulnerability something is as well as allows you to actually patch some of the software requiring patches directly through the user interface. Some software I have is no longer supported by the mfr with patches and so I get my weekly pop up that shows I am at a score of 87% protection because of these old programs that I still have on my system that have known exploits. But these exploits are low risk to me behind firewalls and a good antivirus. If I uninstalled the software that is popping up as potential security threats, I'd have a score of 100%, but I chose to keep the 3 programs installed.Quote from: Gliq on May 14, 2013, 04:47:55 PM I have had unauthorized visitors in my computer that got in using Windows XP Remote Access software. I've eliminated their entries in the Win Registry. The risk is that they installed other trojan and backdoor software while they were in.Thanks for all your help. To summarize my response... I've been attacked several times by a proxy server company (or more likely, its hacker assets). I've gone far beyond just clicking the Windows software boxes to disable Remote Assistance and Remote Desktop. I've written a batch file to check if recimbly.exe and RCP.exe are in the system32 and system32/dllcache FOLDERS. If so, I have a batch file to delete them if they are. Just today, I exported a registry from one of my three computers and found a list of (probably) 15,307 websites that my attacker enters into the zonemap areas of my machines (there are two of those zonemap areas). I'm going to remove these in my "textpad" app (advanced notepad) and will attempt to import them with HOPE that they will be gone. As far as an intruder having set up something else, I have no sign of any activity at the moment, so hopefully I don't. I will be going to Win7 and Linux before April 8th, 2014 (D-Day for XP) so I hope I will make it till then. Thanks again for the replies.If you have the XP installation CD or system recovery set, I'd wipe the system clean and enable all protection just to make sure there is no more back doors. I use to run/host honeypots to bait hackers to systems that looked important, looked like a company server etc with a bunch of data that looked important but was fake, and I use to look at their methods on the honeypots that they didnt know where honeypots. I ended up stopping the honeypot project though when one of the hackers tried to make my honeypot a relay location for downloads. I had a ghost image for my honeypots so that after they played in my honeypot sandbox, I could wipe it clean and set it up as a trap for the next hacker. It was fun until one decided to try to make it a relay for most likely illegal content sharing. I stopped baiting with honeypots when I realized that their actions could get me in hot water with illegal file sharing, even if it was only live for a few hours until I killed it to wipe it clean and set it back up again. Hosting Honeypots is just asking for trouble, which I dont need! |
|
| 6727. |
Solve : IPconfiguration script working on Windows 7 but not XP...? |
|
Answer» Hello, and thankyou for being here, there aren't a lot of live forums which still support batch scripting, so im gonna post it right away, so the main problem that is i needed a script which shows the active network adapters, then lists them gives'em ID so a user can enter the ID and then get's asked for what kind of a setup he wants, DHCP y/n, then if DHCP it configures adapter X for dhcp if not runs a next question and lists all bat files(profiles) in the same directory except the one running now. so the thing is IT works on Windows 7... what i need is a fix for it, or a XP revision so it works under XP sp3 Hello, and thankyou for being here, there aren't a lot of live forums which still support batch scriptingDefine a lot. I belong to at least 6 forums that all support batch scripting.Quote from: tixed on May 16, 2013, 11:56:20 AM taken from http://ricardo.szyfer.com/Nice that he took the time to write that but there are plenty of free programs out there that will run in the task tray and you can setup predefined network profiles and switch to one with two mouse clicks. http://www.snapfiles.com/get/netsetman.htmlXP doesn't support the Netsh command which is the first external file used. Code: [Select]c:\XP Box>netsh int ipv4 show interfaces The following command was not found: int ipv4 show interfaces. okay, im no expert in BATCH scripting, and the author tried to fix it but, as we know many infrastructures still use XP, so im still diging thru, and yes im trying to post everywhere i know, so maybe someone has a global idea how to solve this FOR XP. Quote from: Squashman on May 16, 2013, 07:00:39 PM Define a lot. I belong to at least 6 forums that all support batch scripting. Some time before there were even 3 forums in my native language, now everyone is obsessed with newer win versions... Now im thinking maybe this can be done for both WinXP and Win7 through VBscript call ? |
|
| 6728. |
Solve : Command prompt shortcut not taking variable.? |
|
Answer» Hello, |
|
| 6729. |
Solve : Schedule One Time Task with SchTasks? |
|
Answer» I need to be able to schedule a task from a batch file that I run using SchTasks. BUT . . . heheh . . . I need the task to run on startup - once, and then delete itself. Here's how it would work: This can be done, through a series of batches all calling and removing each other from startup, and here is how I have done it before. Start batch#1 which runs stuff at the get go and then has a SLEEP timer which gives you your 10 minute delay you need before the next event triggers. This batch completed its sleep delay and then copies Batch#2 to startup folder of system, system reboot is passed, and system reboots and now automatically triggers Batch#2 as part of startup. Batch #2 now calls for Batch # 3 which runs the final chunk of whatever needs to be done and then batch # 3 performs a final cleanup that deletes Batch # 2 from startup. Startup is now empty of any batches and process is complete. Dave - thanks for the fast reply. I may have misunderstood what you wrote but the startup I was referring to was system start. The scheduled task should execute on system start and then delete itself. I don't intend to log into the servers. So since scheduling a task to run at system start precludes me from being able to have the task delete itself I think I need to schedule a task to run once (because these types of tasks can delete themselves) but at a time that is 10 minutes from when the task is created. Is it possible to do this? Is it possible to query the time add 10 minutes and set the new time equal to a variable that can be passed to the schtasks command? Thanks, MJAfter a bit of searching I found this: Code: [Select]@echo on for /F "tokens=1-3 delims=:." %%a in ("%time%") do ( set Hour=%%a set Minute=%%b set Seconds=%%c ) ::Convert HH:MM to minutes + 10 set /A newTime=Hour*60 + Minute + 10 rem Convert new time back to HH:MM set /A Hour=newTime/60, Minute=newTime%%60 ::rem Adjust new hour and minute if %Hour% gtr 23 (set Hour=0) ELSE (IF %Hour% lss 10 set Hour=0%Hour%) if %Minute% lss 10 set Minute=0%Minute% Set TaskTime=%Hour%:%Minute%:%Seconds% Echo %TaskTime% I will use the TaskTime variable to schedule the task LIKE this: Code: [Select]Schtasks /create /ru "System" /s localhost /tn "My Task" /tr "<path to my script>" /sc once /st %TaskTime% /F /V1 /Z Note, the /V1 switch in the the Schtasks command is not needed for Server 2003. why not use the runonce registry optionSquashman - RunOnce is executed upon login. I don't want to have to log into the server for the script to execute. Thanks anyway! |
|
| 6730. |
Solve : How can I count the restart cycle in a batch file?? |
|
Answer» I would like to run a batch file which does a sequence of operations and then restarts the PC. This is one restart cycle. I hope to do the restart cycle 100 times. How can I count the restart cycles? Thanks.You have to create a file with a number in it. Start with zero. |
|
| 6731. |
Solve : URL file shortcut? |
|
Answer» "I have files saved from my schools site, they are saved as URL shortcuts, due to the content being REMOVED from the site I can not access the files, is there ANYTHING I can do?"CONTACT the IT people at the school... |
|
| 6732. |
Solve : Script that executes steps (takes action) if IP address is correct? |
|
Answer» I wrote a script that installs program updates based on a number of criteria including which DATA center the server is located in. However the script doesn't SEEM to determine the data center properly. My 2¢ 10¢ worth I'd say that was worth a couple of dollars at least, SW. 10.44.xxx.xxx should go to proxyon though... Salmontrout, THANK YOU! That did the trick. Was able to test this morning and everything worked as it should. Is it possible to do something like this: If Errorlevel 0 in (ipconfig | findstr "10.64" > NUL) GOTO ? I just refreshed my screen and saw more replies. I'm interested in what Sidewinder posted too. What does Code: [Select]&& do? Thanks again, MJQuote What does && do? Do you want to handle that, SW? Quote Do you want to handle that, SW? Haven't got a clue The symbol && is used to execute the code to the right of the symbol if the instruction immediately preceding the symbol is true. Code: [Select]ipconfig | findstr /r " 10\.64\." > nul && goto proxyoff In this case the goto is executed if the findstr instruction is true, meaning the IP pattern (" 10\.64\.") has been found. If you are interested, there is an inverse notation || , which is used to execute the code to the right of the symbol if the instruction immediately preceding the symbol is false. Put another way, the && and || operator are errorlevel tests. command1 && command2 this line runs command1 and if the errorlevel from command1 is equal to 0 (zero), then it runs command2. command1 || command2 this line runs command1 and if the errorlevel from command1 is NOT equal to 0 (zero), then it runs command2. (note: "not equal to zero" - not just greater than zero; less than zero also. Some programs return negative errorlevels.) You can do stuff with brackets as well command1 && ( echo no error some other code to execute if there was no error ...etc ) You can combine && and || if you do this put the && test first. command1 && (echo no error) || (echo an error) command1 && ( echo no error echo That's right, no error ) || ( echo an error echo Yup, an error ) In fact with a little thought you can do away with GOTOs and labels. http://judago.webs.com/batchoperators.htmnice pageI use FOR with the netsh command to find a host's own IP address and then it can be used again to isolate the first two octets @echo off set mycommand=netsh interface ip show addresses "Local Area Connection" for /f "tokens=1-3 delims= " %%A in ('%mycommand% ^| find "IP Address:"') do set hostIP=%%C for /f "tokens=1-4 delims=." %%A in ("%hostIP%") do set first2octets=%%A.%%B if "%first2octets%"=="10.64" goto Proxyoff if "%first2octets%"=="10.14" goto Proxyoff if "%first2octets%"=="10.44" goto Proxyon This is fantastic! Excellent information. Thank you everyone!Quote from: Salmon Trout on May 22, 2013, 12:26:31 PM I use FOR with the netsh command to find a host's own IP address and then it can be used again to isolate the first two octets That relies on the network adapter name and in my case it gives the Virtualbox IP address, and not my internet connection. If the OP wants to get his internet facing IP address then this is one way, relying on an external website to report the information. Code: [Select]@echo off >"%temp%\ip.vbs" echo Set objHTTP = CreateObject("MSXML2.XMLHTTP") >>"%temp%\ip.vbs" echo Call objHTTP.Open("GET", "http://astronomy.comoj.com/ip.php", False) >>"%temp%\ip.vbs" echo objHTTP.Send() >>"%temp%\ip.vbs" echo wscript.echo objHTTP.ResponseText for /f "delims=" %%a in ('cscript /nologo "%temp%\ip.vbs"') do ( if not defined ip set ip=%%a ) echo %ip% pause |
|
| 6733. |
Solve : XCOPY - Script runs first line repeatedly, does not copy and does not end.? |
|
Answer» XCOPY - Script runs first line repeatedly, does not copy and does not end. |
|
| 6734. |
Solve : Make Move Merge & Rename files into directories based on file-name / Bash to DOS? |
|
Answer» LINUX BASH SCRIPT Makes directories from a predefined part of the file-name and moves/merges them into their corresponding defined folder. IF the folder and file already exists, it will merge the file into the pre-existing folder and create a incremental numbered tag at the end of filename (c#). No files are over written. INPUT: Filename Pattern Field1 - Field2.ext Field1 - Field2 - Field3.ext Field1 - Field2 - Field3 (tag).ext Field1 - [Field2] - Field3.ext Field1 - [Field2] - Field3 (tag) (tag2).ext Deliminators: dash, square BRACKET (optional) and parenthesis. These are designated and NOT used elsewhere in FIELD names. Field: The field can contain any of the following: alpha-numerics, apostrophe, ampersand and decimal point. No other special or foreign characters. Code: [Select]#!/bin/bash for i in $(ls | sed 's/ /~/g'); do FILENAME=$(echo "$i" | sed 's/~/ /g') if ! [ -d "$FILENAME" ]; then AUTHORNAME=$(echo "$FILENAME" | awk -F"-" '{ print $1 }' | sed -r 's/ +$//g') if ! [ -d "$AUTHORNAME" ]; then mkdir "$AUTHORNAME" fi COUNT=1 EXTENSION=$(echo "$FILENAME" | awk -F. '{ print $NF }') NEWNAME=$(echo "$FILENAME" | sed -r "s/\.$EXTENSION$//g") TEMPNAME=$NEWNAME while [ -e "$AUTHORNAME/$NEWNAME.$EXTENSION" ]; do NEWNAME="$TEMPNAME(C$((COUNT++)))" done mv "$FILENAME" "$AUTHORNAME/$NEWNAME.$EXTENSION" fi done OUTPUT: John Doe/ John Doe - bbb.ext John Doe - aaa - bbb.ext John Doe - aaa- bbb(tag).ext John Doe - [aaa] - bbb.ext John Doe - [aaa] - bbb (tag) (tag2).ext Linux users, this bash script WORKS like a dream. ISSUE: My husband was kind of enough to write this script for me in Bash (Linux). It works great in Linux, but I need Cygwin to run it in Windows and it's SLOW and buggy. Salmon Trout posted this DOS Batch on a similar Topic: Create folders based on part of filename dated June 22, 2012. which does close to what I want, but makes no concession for merging duplicate file names and renaming them. DOS BATCH: Code: [Select]for /f "delims=" %%A in ('dir /b /a-d ^| find /v "%~nx0"') do ( for /f "tokens=1* delims=-" %%B in ("%%A") do ( if not exist "%%B" md "%%B" if not exist "%%B\%%A" move "%%A" "%%B" ) ) I would like help in expanding this DOS batch to include merging and renaming files if they exist -- much like my Bash Script. My programming skills are limited to simple regular expression. Basically, I wish to convert my Bash to DOS. _______________________________________ ______ PC: Running Windows 7 Home Edition 64 bit / 16 GB RamThe task is unclear, to me at least. You wish to move files from somewhere to somewhere else and not overwrite any files. Does it include subdirectories? Give some examples of the source files and the target files, which should clarify the task.The bash script does the following... BEFORE: J.R.R. Tolkien - Lord of the Rings 01 - The Hobbit.pdf J.R.R. Tolkien - Lord of the Rings 02 - Lord of the Rings.txt J.R.R. Tolkien - Beowulf, The Monsters and the Critics (html).rarx William Shakespeare - A Midsummer Nights Dream.epub William Shakespeare - Alls Well That Ends Well.epub William Shakespeare - Twelfth Night.epub William Shakespeare - Venus And Adonis.epub AFTER: J.R.R. Tolkien/ J.R.R. Tolkien - Lord of the Rings 01 - The Hobbit.pdf J.R.R. Tolkien - Lord of the Rings 02 - Lord of the Rings.txt J.R.R. Tolkien - Beowulf, The Monsters and the Critics (html).rar William Shakespeare/ William Shakespeare - A Midsummer Nights Dream.txt William Shakespeare - A Midsummer Nights Dream.epub William Shakespeare - Alls Well That Ends Well (2ed).epub William Shakespeare - Twelfth Night.epub William Shakespeare - Venus And Adonis (c1).epub William Shakespeare - Venus And Adonis (c2).epub William Shakespeare - Venus And Adonis.epub William Shakespeare - Venus And Adonis.jpg In cases where the folder already exists the files are move into the existing folder. In cases filename already exists the files are rename with an incremental tag to avoid conflict. i.e. (c1), (c2)This seems to work Code: [Select]@echo off setlocal EnableDelayedExpansion for /f "delims=" %%A in ('dir /b /a-d') do ( for /f "tokens=1 delims=-" %%B in ("%%A") do ( set b=%%B if not "%0"=="!b:~0,-1!" ( echo %%B if not exist %%B md %%B move "%%A" "!b:~0,-1!\%%A" ) ) ) pause This task is complicated by the need to rename and add a suffix - and that suffix has to be removed to compare further similar files. However this seems to work here in my test. Try it on copies of your files first. The source filespec can simply be *.* and the target is where your folders are to be CREATED and could be simply books to move into a books folder in the current directory. Code: [Select]@echo off set "source=d:\abc\*.*" set "target=d:\abc\books" md "%target%" 2>nul FOR %%a in ("%source%") do call :next "%%a" pause goto :eof :next for /f "delims=-" %%b in ("%~n1") do set "folder=%%b" if "%folder%"=="%~n1" goto :EOF if "%folder:~-1%"==" " set "folder=%folder:~0,-1%" md "%target%\%folder%" 2>nul set c=-1 set "name=%~n1" :: remove existing " (cNNN)" echo "%name%|" |findstr /r /c:" (c[0-9]*)|">nul && call :remove :loop set /a c=c+1 set num= (c%c%) if %c% EQU 0 (set num=) if exist "%target%\%folder%\%name%%num%%~x1" goto :loop echo processing %1 MOVE /-Y "%~1" "%target%\%folder%\%name%%num%%~x1" >nul goto :EOF :: Search and Replace - strings :remove call :Search_and_replace "%name%" for /f "delims=" %%c in ('cscript /nologo _.vbs') do set "name=%%c" ) del _.vbs goto :EOF :Search_and_replace set s=regex.replace("%~1","$1") >_.vbs echo set regex=new regexp >>_.vbs echo regex.global=True >>_.vbs echo regEx.IgnoreCase=True >>_.vbs echo regex.pattern="(.*) \(c[0-9]*\)" >>_.vbs echo wscript.stdOut.write %s% First, a 'thank you' both, your help is greatly appreciated. I pressed your buttons. Foxidrive's batch works like a charm. I even tweaked a copy so it can run on the root directory of the batch file. I now have a choice and flexibility; one for my LIBRARY folder with targetand source set and one portable for drag-n-drop. Foxidrive's Tweaked Version: No target or Source: runs on root of batch file. Code: [Select]@echo off FOR %%a in ("*.*") do call :next "%%a" pause goto :eof :next for /f "delims=-" %%b in ("%~n1") do set "folder=%%b" if "%folder%"=="%~n1" goto :EOF if "%folder:~-1%"==" " set "folder=%folder:~0,-1%" md "%folder%" 2>nul set c=-1 set "name=%~n1" :: remove existing " (cNNN)" echo "%name%|" |findstr /r /c:" (c[0-9]*)|">nul && call :remove :loop set /a c=c+1 set num= (c%c%) if %c% EQU 0 (set num=) if exist "%folder%\%name%%num%%~x1" goto :loop echo processing %1 MOVE /-Y "%~1" "%folder%\%name%%num%%~x1" >nul goto :EOF :: Search and Replace - strings :remove call :Search_and_replace "%name%" for /f "delims=" %%c in ('cscript /nologo _.vbs') do set "name=%%c" ) del _.vbs goto :EOF :Search_and_replace set s=regex.replace("%~1","$1") >_.vbs echo set regex=new regexp >>_.vbs echo regex.global=True >>_.vbs echo regEx.IgnoreCase=True >>_.vbs echo regex.pattern="(.*) \(c[0-9]*\)" >>_.vbs echo wscript.stdOut.write %s% |
|
| 6735. |
Solve : Delete files taht are not AVI? |
|
Answer» A paid service downloads video files in AVI format. Along with the videos come other files that are no longer needed after the download is finished.
Add the /i switch or it will delete .AVI files or .aVi files etc. The CASE insensitive switch will fix that. Code: [Select]for %%A in (*.*) do if /i not "%%~xA"==".avi" del "%%A"Quote from: foxidrive on May 25, 2013, 10:47:23 PM Add the /i switch or it will delete .AVI files or .aVi files etc. The case insensitive switch will fix that.Cool ! Didn't know.Quote from: foxidrive on May 25, 2013, 10:47:23 PM Add the /i switch or it will delete .AVI files or .aVi I can't imagine that mattering. Not mattering if it deletes your collection of AVI files? Quote from: foxidrive on May 26, 2013, 02:22:03 AM Not mattering if it deletes your collection of AVI files? Of course... I posted UNTHINKINGLY... a very good point. You can force lower case with a rename of the extension. But then it would not be a one-liner. rename *.AVI *.avi Quote from: Geek-9pm on May 26, 2013, 09:48:47 AM You can force lower case with a rename of the extension. As the REN command ignores case, we can protect the avi files with a temporary dummy extension, and then rename back, forcing every .avi extension to a chosen case. In this example it is lower case. It will all go in one line. in a batch... ren *.avi *.avi$$$ & for /f "delims=" %%A in ('dir /b *.* ^| find /v "%~nx0"') do if not "%%~xA"==".avi$$$" del "%%A" & if exist *.avi$$$ ren *.avi$$$ *.avi before aaaaa.bat test0.AVI test1.Avi test2.aVI test3.aVI test4.aVi test5.aVI test6.avi test7.txt test8.doc test9.zip testA.aaa testB.bbb testC.ccc after aaaaa.bat test0.avi test1.avi test2.avi test3.avi test4.avi test5.avi test6.aviUpdate (ignores directories in the folder) Note: batch does not delete itself Code: [Select]ren *.avi *.avi$$$ & for /f "delims=" %%A in ('dir /b /a-d ^| find /v "%~nx0"') do if not "%%~xA"==".avi$$$" del "%%A" & if exist *.avi$$$ ren *.avi$$$ *.aviYour original suggestion with case insensitive switch will work fine, except it will delete the bat file. This should cater for that. Code: [Select]for %%A in (*.*) do if /i not "%%~nxA"==%~nx0" if /i not "%%~xA"==".avi" del "%%A" |
|
| 6736. |
Solve : How can I find and replace text inside a xml file using bat process? |
|
Answer» Hi guys, what's up? |
|
| 6737. |
Solve : Sort Files into Folders by Artists Name? |
|
Answer» I have a script currently to sort all my music into Alphabetic Folders (A,B,C, ect) Most of my music is already in folders by artists name (//Queen/Bohemian Rhapsody. - Queen.mp3) However I have some unsorted mp3s in the with the same title format (Song - Artist) that I would like to put into directories by the artists' name. I cannot solve this for the life of me. I can put them into directories with the last letters of the file name but the length VARIES so I might get directories named "sody - Queen" instead of just "Queen" I'm pretty novice user of batch files but I'm trying to get better I just got caught up on this problem which I hope there is a solution to. Edit: When I put it in with the rest of my code it only works for the first file and that's it. The other file(s) are unaltered. I assume I could run it as a separate file but it would be much better if I could run it in my main batch file. It calls a subroutine. If you show us your main batch file then it should be able to be added. |
|
| 6738. |
Solve : Commands about file checking?? |
|
Answer» Is there any articles to explain about commands for FILE checking; such as checking if a folder is EMPTY, if a file empty, if two folders the same?'fc' is the closest thing I can think of to what you are LOOKING for. You may need to 'dir >>tmp & fc tmp1 tmp2' kinda thing for your directories.You will find all those things if you google for them. here. "alt.msdos.batch.nt" newsgroup. Dostips forum. Stack Overflow forum. ss64 forum. All have examples and tips. |
|
| 6739. |
Solve : How to return result from sub function to caller?? |
|
Answer» 1. How to return the processing result from a called batch program to the caller? Getting started with PowerShellQuote from: Geek-9pm on May 28, 2013, 09:39:35 PM For some time MS has recommended for t all users learn to use PowerShell instead of DOS for all but the most trivia things. Batch has been able to access the registry since reg.exe was created. 1. How to return the processing result from a called batch program to the caller? set a variable or use a file 2. How to return the processing result from a called function in the same batch file to the caller? set a variable or use a file 3. How to go back to the next line of call statement from the called function in the same batch file? end the called subroutine with Code: [Select]GOTO :EOF |
|
| 6740. |
Solve : How to check if a file is ordinary or a folder?? |
|
Answer» As title. |
|
| 6741. |
Solve : %errorlevel% will have different result in my batch file and in DOS command.? |
|
Answer» Below is my BATCH file for comparing two folders. I would like to compare each files under two folders to make sure they are the same. I used 'fc' to compare files and then CHECK the result. The strange thing is that I usually got non-zero %errorlevel% in this batch file when it compares two identical files. But if I did the same comparison at DOS command PROMPT, I got expected result. How come? |
|
| 6742. |
Solve : How to set result of a command into a variable?? |
|
Answer» I would like to execute a DOS COMMAND and have its output string being SAVED into a VARIABLE in a batch file. How can I do it?for /f "delims=" %%A in ('mycommand') do SET output=%%A |
|
| 6743. |
Solve : Batch File to move a file Help.? |
|
Answer» Good Morning, After a PM exchange with the OP I'm unlocking the thread. Sorry Allen I don't see that I have the option to edit my OP. Please feel free to remove any harmful content at your discretion. My goal is to help my players get their game pointed to my server. That has all been worked out. The problem I am having is that the server name is actually client side in a file servername.dat I have a servername.dat file for my players that will display my server name "Relentless" What I want to do is provide it along with the batch file I am working on and have the batch file overwrite the default servername.dat file with mine. I think I can do it if they were to unpack it and run it EXACTLY on the desk top and their game was installed exactly at the default location. But if something isn't at the precise location I get a LITTLE confused about what to do. I realize I'm on a short leash here so if we want to echo to the user exactly what is taking place I'm cool with that. If you guys were willing to help, you could hold onto the script and I would just provide an executable. That way the warnings to the users could not be removed. Chad It's possible to search the drive for servername.dat or perhaps query the registry for it's location. When it's found - do you want the batch file to create a new servername.dat with the required contents? I'm assuming it is a text file with several lines inside so the batch file can create a new one rather than packaging another file. So more details are needed - registry settings etc.Thanks everyone. I decided to abandon this approach. My Antivirus software lit up like a Christmas tree during a trial run. This would cause more problems than it solves if my players had to deal with that. What approach did you use that triggered your AV program? What tool were you using - because very few batch scripts will cause any issue with an AV program.Quote from: foxidrive on August 22, 2013, 01:42:16 AM What approach did you use that triggered your AV program? What tool were you using - because very few batch scripts will cause any issue with an AV program. I can't answer that without going into detail about it and the moderators don't want that posted here. The AV didnt REALLY become an issue until I COMPILED the script into an executable. |
|
| 6744. |
Solve : turning off attributes in archive files? |
|
Answer» IN MY Windows CLI I am asked to turn off ATTRIBUTES for an archive file, however I have tried EVERYTHING to no avail. any help? turn off archive by attrib -A. This does not work. What filename did you pass it and what error MESSAGE appeared? |
|
| 6745. |
Solve : Syntax error on this batch file?? |
|
Answer» Okay, so I decided to make a temperature converter between Celsius and FAHRENHEIT. |
|
| 6746. |
Solve : Even doing "setlocal enabledelayedexpansion", 'fc' still returned wrong value? |
|
Answer» Below is my program for comparing files and folders under two specified folders. It almost works well except one issue. That is, after 'fc /b' compared two different files, %errorlevel% is 0. I met the same phenomenon and it was DUE to not set "enabledelayedexpansion". This time I am sure I did it. How come? 2. Use exclamation marks, not percent signs, with variable i.e. !errorlevel! not %errorlevel% You should not use :: to start a COMMENT. This is wrong and will break code blocks. Use REM. You should start many threads which are all about the same code. Quote from: Stan Huang on May 31, 2013, 02:23:13 AM @echo offThat's Quote from: Salmon Trout on May 31, 2013, 02:45:54 AM You should not start many threads which are all about the same code.For "You should not start many threads which are all about the same code.", do you mean that I should try to use interaction instead of recursion?Quote from: Stan Huang on June 02, 2013, 06:49:48 PM For "You should not start many threads which are all about the same code.", do you mean that I should try to use interaction instead of recursion? No. He means you shouldn't start multiple forum threads about the same code. |
|
| 6747. |
Solve : Batch file to export a .txt of the Add/Remove Programs list in Windows? |
|
Answer» I searched a lot for a batchfile that could export a list to a text file of all the installed programs on my machine. I want the list as similar as possible to the 'visual' list of the Add/Remove Programs in WINDOWS. Windows Live Communications Platform To: Quote Windows Live Communication Platforms | Essentials | Family Safety | etc Tnx for your help.Why to export to text file. Export it to csv, you can even open that in Excel. You can read this article to know how to export all installed apps http://www.funbutlearn.com/2013/06/easily-export-all-installed-apps-from.html |
|
| 6748. |
Solve : How can i add a space 3 letters from the end of each line in a text file?? |
|
Answer» Hello everyone. |
|
| 6749. |
Solve : use of SET in FOR? |
|
Answer» I am making list of folders I am LOOKING having name 2000 it working fine with CODE Code: [Select]FOR /F "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO echo %%I IN %G\%%H>> L2.txt Some reason I can't get this work with SET to get name without 2000 word Code: [Select]FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO ( set NY=%%I set "NY=%NY:2000=%" ) echo "%NY%" IN %%G\%%H>> L2.txtIn this case you can move the line that changes the variable out of the loop. To change a variable inside a loop you need to use delayed expansion and the !variable! syntax instead of %variable% Code: [Select]FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO ( set NY=%%I set g=%%G set h=%%H ) set "NY=%NY:2000=%" echo "%NY%" IN "%g%\%h%">> L2.txt This example uses delayed expansion (and be aware that ! characters in the TEXT are an issue) Code: [Select]@echo off setlocal enabledelayedexpansion FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO ( set NY=%%I set "NY=!NY:2000=!" echo "!NY!" IN %%G\%%H>> L2.txt ) |
|
| 6750. |
Solve : exit /b turning echo off? |
|
Answer» For some reason exit /b is leaving echo off when the program ends. Is there anyway to fix this? @echo offAdd something to verify this part of the code is working. You code is too much. Batch code does not lend itself to easy testing, so you have to do bits and nibbles and have little FLAGS to tell what is going on. Why use echo off? Use echo on up until u got the code working. An annotate your code so other can help you. Best I can do for you.I didn't SEE an issue with echo being turned off. See below (a.bat) Code: [Select]d:\abc>a 1.2 3.4 6.8 0 - - - - - + 0 - - - - - - 0 - - - - - - 0 - - - - - - 0 - - + - - - 0 - - - - - - 0 + - - - - - 0 - - - - - - 0 0 0 0 0 0 0 d:\abc>123 |
|