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.
| 901. |
Solve : Question about tokens and delimeters? |
|
Answer» I'm just curious about something I couldn't find any more information about.
I'm not clear on your question but that is correct. The spaces and commas are treated as separators up the the start of the third term, which starts with just The * means "put the rest of the line into the next variable" If it's unclear then explain what you expected, or what you need it to look like. Example from help for FOR command. Quote FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do echo %i %j %k From that example, as said, %k variable displays all the remaining tokens. I'm not sure why the delimiters are not applied to the remaining tokens after the variable (%k). As it's stated from that example that the variable %k stands for ALL following tokens, not just the rest of the line. The delimiters are only applied to the given tokens (2,3) while the wildcard that represents all the remaining tokens is ignored. I hope this clarifies my question a BIT more. Quote from: Night on August 10, 2014, 10:26:06 AM it's stated from that example that the variable %k stands for ALL following tokens, not just the rest of the line. As you have FOUND, the variable %k stands for the rest of the line, that is, any remaining tokens and separators all together. The help documentation could be clearer in EXPLAINING that, I suppose, (it can be occasionally opaque or seemingly incomplete) but you have discovered by experiment the way it works. Quote the wildcard that represents all the remaining tokens is ignored. It is not "ignored". It is correctly interpreted. The asterisk ("wildcard") represents the whole remainder of the line. There are no more "tokens" to process. Thanks for the clarification! I guess the documentation isn't all that good after all. That would be all. |
|
| 902. |
Solve : Error?? |
|
Answer» Hi, I wanted to see my hand at scripting and got started, it took me 5 minutes to make a canculator that worked, but I wanted something more... special. But one I finished coding, it didnt work! it errors. ECHO offThe set command to do maths is set /a Type set /? and you can read the portions about the arithmetic. Quote from: TheLastAlly on August 16, 2014, 05:03:34 PM But one I finished coding, it didnt work! it errors. You invented a set of switches for the SET command that do not exist... /Add, /Subtract, /Multiply, and /Divide. The way to produce code that works is not to guess and hope the computer understands what you meant, but rather to study the documentation. You may be interested to know that set /a can evaluate a string e.g. 5+226 or 34-12 or 27*5 or 55/11 or (5*30)/10 or 6+5+4+3+2+1 e.g. Code: [Select]echo off echo Welcome to Batch Calculator! :loop set /p tocalc="Enter an expression, or 0 to quit: " if "%tocalc%"=="0" goto done set /a result=%tocalc% echo Answer=%result% goto loop :done echo Done! sample run: (Do you notice anything about the 4th result?) Code: [Select]Welcome to Batch Calculator! Enter an expression, or 0 to quit: 5-3 Answer=2 Enter an expression, or 0 to quit: 6+5+4+3+2+1 Answer=21 Enter an expression, or 0 to quit: 15*3 Answer=45 Enter an expression, or 0 to quit: 10/3 Answer=3 Enter an expression, or 0 to quit: 0 Done!Isn't 10/3 like 3.33333333333333 Or unless it doesn't go into decimals Quote from: shiverbob on August 17, 2014, 12:34:10 AM Isn't 10/3 like 3.33333333333333 You got it. Now try 10000000000/2 Quote from: Salmon Trout on August 17, 2014, 12:24:48 AM The way to produce code that works is not to guess and hope the computer understands what you meant, but rather to study the documentation. Of course that is not right; making mistakes and learning from them is part of learning too. |
|
| 903. |
Solve : Increment value in xml file? |
|
Answer» Hi Guys, |
|
| 904. |
Solve : Batch File - batch window auto-focus?? |
|
Answer» I've GOT a batch file I'm using to maintain my disk image backups. Make a one-line launcher batch script; add it to your scheduled tasks. It will launch the batch you want to run in a new window, and give it focus, and then exit. Thanks ST, but that script does nothing. My batch doesn't won't run even though Task Scheduler reports a status of "Running". Presumably your code is completely suppressing the window altogether? Quote from: Lemonilla on April 01, 2012, 06:34:16 PM If I understand correctly, you have a batch file running in the background that will pop up errors on your disk images and you want it to bring it to the top. Nope, you've got it wrong. My batch is waiting on my input before it's allowed to continue or quit. The batch file opens up on top of other windows just fine. My issue is that it's not in focus when I let Task Scheduler run it on a schedule. Needless to say, running it manually via task scheduler, or simply double clicking the batch file directly, will give the window focus. FWIW, Here's how things are working. Machine is on at backup time: Acronis images my drives at 8AM every Monday. Task Scheduler kicks in two hours later, plenty of time for Acronis to finish creating the file, and manipulates said images. Machine is off at backup time: BOTH Acronis and Task Scheduler want to run immediately at next system boot. Since the file exists but isn't finished yet, I have the batch sitting at a prompt waiting for a "Y" keystroke. When Acronis is done, I press "Y" and the batch continues. Here's my file it this helps: This "version" has all the network attached storage stuff removed for ease of testing from the Desktop if you're so inclined... Code: [Select]ECHO OFF C: CHDIR %~dp0 CLS ECHO WAITING FOR ACRONIS FILE DUMP PING 1.1.1.1 -n 1 -w 3000 >NUL IF NOT EXIST *.tib CALL :ABORT CLS CHOICE /M "IS ACRONIS DONE DUMPING DRIVE IMAGE" IF %ERRORLEVEL% EQU 2 CALL :EXIT CLS ECHO RENAMING BACKUP. PING 1.1.1.1 -n 1 -w 3000 >NUL IF EXIST *.tib REN *.tib Backup.tib IF NOT EXIST ".\BACKUPS\" CALL :MAKEFOLDER :MOVEFILE CLS ECHO MOVING BACKUP INTO STORAGE DIRECTORY PING 1.1.1.1 -n 1 -w 3000 >NUL MOVE Backup.tib ".\BACKUPS\" CLS ECHO RESTRUCTURING BACKUP STORAGE DIRECTORY PING 1.1.1.1 -n 1 -w 3000 >NUL CHDIR ".\BACKUPS\" IF EXIST Backup2.tib DEL Backup2.tib IF EXIST Backup1.tib REN Backup1.tib Backup2.tib IF EXIST Backup.tib REN Backup.tib Backup1.tib CLS ECHO ALL DONE! PING 1.1.1.1 -n 1 -w 3000 >NUL EXIT REM *************SUBROUTINES************** :ABORT CLS ECHO NO BACKUP FOUND, ABORTING PING 1.1.1.1 -n 1 -w 3000 >NUL EXIT :MAKEFOLDER MKDIR ".\BACKUPS\" CLS ECHO NO STORAGE DIRECTORY FOUND, CREATING IT NOW PING 1.1.1.1 -n 1 -w 3000 >NUL CALL :MOVEFILE :EXIT CLS ECHO OK, EXITING. PING 1.1.1.1 -n 1 -w 3000 >NUL EXIT Hmm, now that I'm thinking about it... I wonder if I can make the batch read the date/time the was last modified? If so, perhaps I could create an argument along the lines this for when the job is missed: If last modified within the last two hours, ask me if Acronis is done. That way, I could do away with the prompt altogether when the job runs as scheduled. Quote from: S3NTYN3L on April 03, 2012, 08:36:45 AM Thanks ST, but that script does nothing. Works fine on my system. I set it to run with highest privileges. I presume the path and file name are correct? What OS are you running this on? Quote from: Salmon Trout on April 03, 2012, 10:49:21 AM Works fine on my system. I set it to run with highest privileges. I presume the path and file name are correct? What OS are you running this on? Running with highest privileges as well on Windows 7, (as stated on the left of my posts).I have got this to run at a set time and also on demand (1) Launcher.bat Code: [Select]start "" "cmd" /c "C:\Batch\Test\After 22-01-2012\Batchfocus\CHBatchfocus.bat" (2) CHBatchfocus.bat Note: I have commented out various ping and CLS commands to make the screen capture tell a story, and added a couple of lines to make things clearer. Code: [Select]ECHO OFF echo The time is %time% set /p dummy="if we have focus, you can type SOMETHING here " C: CHDIR %~dp0 REM CLS ECHO WAITING FOR ACRONIS FILE DUMP REM PING 1.1.1.1 -n 1 -w 3000 >NUL IF NOT EXIST *.tib CALL :ABORT CLS CHOICE /M "IS ACRONIS DONE DUMPING DRIVE IMAGE" IF %ERRORLEVEL% EQU 2 CALL :EXIT CLS ECHO RENAMING BACKUP. PING 1.1.1.1 -n 1 -w 3000 >NUL IF EXIST *.tib REN *.tib Backup.tib IF NOT EXIST ".\BACKUPS\" CALL :MAKEFOLDER :MOVEFILE CLS ECHO MOVING BACKUP INTO STORAGE DIRECTORY PING 1.1.1.1 -n 1 -w 3000 >NUL MOVE Backup.tib ".\BACKUPS\" CLS ECHO RESTRUCTURING BACKUP STORAGE DIRECTORY PING 1.1.1.1 -n 1 -w 3000 >NUL CHDIR ".\BACKUPS\" IF EXIST Backup2.tib DEL Backup2.tib IF EXIST Backup1.tib REN Backup1.tib Backup2.tib IF EXIST Backup.tib REN Backup.tib Backup1.tib CLS ECHO ALL DONE! PING 1.1.1.1 -n 1 -w 3000 >NUL EXIT REM *************SUBROUTINES************** :ABORT REM CLS ECHO NO BACKUP FOUND, ABORTING pause REM PING 1.1.1.1 -n 1 -w 3000 >NUL EXIT :MAKEFOLDER MKDIR ".\BACKUPS\" CLS ECHO NO STORAGE DIRECTORY FOUND, CREATING IT NOW PING 1.1.1.1 -n 1 -w 3000 >NUL CALL :MOVEFILE :EXIT CLS ECHO OK, EXITING. PING 1.1.1.1 -n 1 -w 3000 >NUL EXIT I was trying to put the start command into the add arguments field, my bad. OK, your way works, but it doesn't do anything. It just opens and closes the launcher window, opens and closes my original batch file and blows through the original (known working) script without processing any commands contained within... I also tried your edited batch and get the same results. Everything works fine on my system. Mine is Windows 7 Professional 64-bit; my user account has Administrator privileges. Would this help? Combine the launcher and the batch file code in a single batch file: Code: [Select]echo off setlocal if [%1]==[Recurse] goto %2 start "Focused Window" "%0" Recurse Label %1 %2 %3 %4 %5 %6 %7 %8 %9 exit :Label echo Your Batch Code Here If it seems a bit dinky, well, it is! But it should keep thing simple. Quote from: Sidewinder on April 03, 2012, 04:06:24 PM Would this help? Combine the launcher and the batch file code in a single batch file: This does not address the question of why my solution works for me but not for him. I have devised a method to allow you to launch an elevated command prompt via the command line, with no clicking, and the new prompt gets focus, with no clicking. You can just keep typing. Here's how to do it: 1. Create a task using task scheduler, as detailed elsewhere on this thread. The task's command line is simply: Code: [Select]cmd and the "Run with highest privileges" box must be checked. 2. Create a batch file called "sudocmd.cmd" in your PATH with this: Code: [Select]schtasks /run /tn "myTasks\sudocmd" sudocmd.vbs 3. Create a file called "sudocmd.vbs" also in your path, most conveniently in the same folder, as: Code: [Select]set wshShell = CreateObject("WScript.Shell") WScript.Sleep 500 wshShell.AppActivate("Administrator: taskeng.exe") This last little bit is the trick that will bring the new command window into focus. 4. Then just type sudocmd at a command prompt and voila! Another possibility is this little gem I found: http://sourceforge.net/projects/sudowin/ |
|
| 905. |
Solve : Batch for checking file? |
|
Answer» I need to check a log.txt file if it is changed, so if it is than must copy XL.txt file ... the same problem, but I found another solution without having to modify my batch script. The only thing that I missed out is at the 'Action' settings - "Start in (Optional)" option.For more info, search for: Windows task scheduler Hope that helps thanks, task scheduler is not a solution I need a batch. Perhaps you did not understand. Batch does not have an effective scheduler. Wasting time in batch is a bad idea. Instead you create a batch file that does what you want. It must be a cone time self-contained batch. No LOOPING. It runs once and stops. The n you make a task e to start that batch file every ten minutes. Make a batch file. Name it My_Job.bat and it must be a job that can be done in well under ten minutes. In an abstract way, it will do this: Start Task:: For every ten minutes Do My_Job.bat Next time frame End. No, you don't write that code, that is an abstract of what you tell the task schedule thing GADGET in Windows. It is not a batch command. Maybe a video will help https://www.youtube.com/watch?v=8tMzockuB2g Does that help? ... Yeah, the video has too much stuff. Here is a simple explanation Here is a simple explanation: Schedule a task in Windows 7 You have to give the name of a batch file with the full path. - Unless it is in the path. Quote from: GEEK-9pm on August 04, 2014, 11:16:02 AM Perhaps you did not understand. Batch does not have an effective scheduler. Wasting time in batch is a bad idea. Instead you create a batch file that does what you want. It must be a cone time self-contained batch. No looping. It runs once and stops. Batch can do that very efficiently, Geek. Code: [SELECT]:loop echo ... timeout /t 600 /nobreak goto :loop Quote from: foxidrive on August 04, 2014, 11:23:15 AM Batch can do that very efficiently, Geek. OK. That will work. That is easier that reading up on how to use the Scheduler. Ok that's sounds good. But how can I use that loop, because file is filling up differend time to get 1k and than to get 2k to get noticable for command FCI guess I would check the Archive Attribute. Every time a file changes the archive attribute should be turned on. Code: [Select]H:\>echo hello>mylog.txt H:\>attrib mylog.txt A H:\mylog.txt H:\>xcopy /m mylog.txt H:\test\ H:mylog.txt 1 File(s) copied H:\>attrib mylog.txt H:\mylog.txt H:\>echo hello again>>mylog.txt H:\>attrib mylog.txt A H:\mylog.txtok how can I check with this if file is changed last 5 minutes?bump |
|
| 906. |
Solve : batch for finding batch? |
|
Answer» I have some batch files with the same name and differend folders and I need to be executed. but instead of this batch it runs this one user_sel.bat The code that I suggested will not do that when using a local drive, and you need to say that you are using a network. Quote from: Lemonilla on August 04, 2014, 06:20:05 AM try changing the line`call "%%A" ` to ` if "%%A"=="copylog.bat" call "%%A"`.That doesn't work, nothing happends Quote from: foxidrive on August 04, 2014, 09:21:11 AM The code that I suggested will not do that when using a local drive, and you need to say that you are using a network.sorry, that's why I posted now allCan you map the network share to a local drive letter? Do the batch file use network paths in them too? Quote from: foxidrive on August 04, 2014, 11:25:44 AM Can you map the network share to a local drive letter?no unfotunally can not map it, because I use %computername% for string in each users backup for this what I need is all above, paths and batchs. All use newtorks pathsbump no luck with this one So if I get this right you want two files to be ran. Simple IF it is in the same directory use " start filename.bat " then use " taskkill filename.bat " mabye a sleep command in the middle of then but if there not in the same dir use " for " or " forfiles " and/ or you could help you understand this batch stuff like I did trial and error and this website http://ss64.com/nt/ Hope this helps Shiverbob |
|
| 907. |
Solve : .VBS file that play sound. I don't know how to stop it? |
|
Answer» Hello, sorry for my poor english. |
|
| 908. |
Solve : Batch AI? |
|
Answer» Hello, I am make a game where you have your city that you build and create armys to attack the other ai's city but I have know idea how to get the ai to do stuff. And I don't know if this is posible but anything would help |
|
| 909. |
Solve : Find Hard Drive ID Without Using WMIC? |
|
Answer» Hi, Is Powershell an option? Unfortunately no The OP mentione4d WMIC as not available. http://en.wikipedia.org/wiki/Windows_Management_Instrumentation More info about it: http://technet.microsoft.com/en-us/library/bb742610.aspx Question: Why can it not be run under PE? Because it's not included...and you cannot run outside apps on PE. Quote from: Fugazi on September 03, 2014, 09:15:11 AM Unfortunately no Is WSH/VBS available?But this thread says it can be installed into WIN_PE http://www.msfn.org/board/topic/143622-how-to-install-wmic-in-winpe/Creating a WinPE LiveCD for WMI lookups https://www.404techsupport.com/2012/03/creating-a-winpe-livecd-for-wmi-lookups/ Quote from: Geek-9pm on September 03, 2014, 09:47:30 AM The OP mentione4d WMIC as not available. Because it was not included in the wim when it was created. I am trying to use an already created wim without making changes to it. Quote from: Salmon Trout on September 03, 2014, 12:24:18 PM Creating a WinPE LiveCD for WMI lookups Thank you, was hoping that I wouldn't have to create a NEW winpe livecd Quote from: Fugazi on September 04, 2014, 02:14:29 AM Thank you, was hoping that I wouldn't have to create a new winpe livecdNot that that is going to take you all day. While you are at it, you might as well switch over to WinPE USB stick! |
|
| 910. |
Solve : Need help on approaching a problem..? |
|
Answer» Not sure if DOS can help me here.. but does DOS, or VB, or any programming language have the ability to change the monitor settings on a machine? setdisplay {monitor:index/name} [width] [height] [color bits] {refresh rate} {-updatereg} {-allusers} |
|
| 911. |
Solve : Add -Val- to file names? |
|
Answer» Hello |
|
| 912. |
Solve : Extracting from a Text file using FOR /f? |
|
Answer» Need some advice - |
|
| 913. |
Solve : find some words and add a word after them in batch script? |
|
Answer» I have a txt files in a FOLDER. I want a batch script which I'd look into using the helper program repl.bat. I'm going to see if I can figure it out past that. How did you go Lemonilla? I was going to let this question slide coz it hasn't got enough info but now that you've mentioned repl.bat I also had a CRACK at it. Code: [Select]echo off type "file.txt" | repl "(.*)(AAA|BBB)(.*)({.*)" "$1$2$3timestamp$4" pause file.txt AAA mmmmmmmmmm {aaa BBB mmmmmmmmmm {bbb ZAAA mmmmmmmmmm {ccc ZBBB mmmmmmmmmm {ddd and the output: AAA mmmmmmmmmm timestamp{aaa BBB mmmmmmmmmm timestamp{bbb ZAAA mmmmmmmmmm timestamp{ccc ZBBB mmmmmmmmmm timestamp{ddd This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat Place `repl.bat` in the same folder as the batch file or in a folder that is on the path. Thanks Foxidrive, I tried * for the wildcard, but it didn't seem to do anything. From you're code it looks like (.*) is the wildcard? Quote from: Lemonilla on September 03, 2014, 02:53:23 PM From you're code it looks like (.*) is the wildcard?That is common syntax for most programs that do regular expressions. Many of them are very similar. The parenthesis are a GROUPING. The period matches any character. The asterisk matches zero or more OCCURRENCES of the previous character. |
|
| 914. |
Solve : bat file to move folder(s) containing certain file type? |
|
Answer» I need the bat file to scan a directory (Folder A) and look at all of the SUBFOLDERS. If a subfolder contains any .PDF files (subfolder A1) then I need that folder to be moved into a NEW location (Folder B). Is this even possible via bat? The tree looks like this: |
|
| 915. |
Solve : How can i modify a windows 7 services with a bat? |
|
Answer» What the command to modify by example in WINDOWS 7 the searchindexer.xe service ? |
|
| 916. |
Solve : Batch to move files in a single directory into separate folders in groups of 10? |
|
Answer» I have a directory with almost 500 pdfs in it. They are all named/numbered sequentially with a 3 digit numeral in the 8th, 9th, and 10th place in the file NAME. I would like to create a batch that moves those files into separate folders in groups of 10. So when it was over, I'd have 50 or so folders named "001-010", "011-20", etc. with the corresponding files placed in each. I could obviously do this manually, but I'll have a new batch of files every week that I will need to do this for. The other variable is that there won't necessarily be the same number of files every week. This week I may have 488, next week I may have 506 and so on and so forth. I'd appreciate any help! Thanks.Could you give some typical file names, obfuscating non-essential parts if you like? ******_001_**_****_***_*****_*****.pdfWeird. That looks exactly like the file naming we use for our PDF's where I work..The OP has not indicated if he/she still needs a solution. Anyhow, this is how I would do it these days; I filled a folder with 999 pdf files, of mixed sizes from 29 KB to 14 MB, named them with the number part from 001 to 999. It should be saved as a .vbs file in the folder to be processed. DOUBLE click to run, or create a shortcut somewhere strHost = Right(WScript.FullName, 11) strHost = LCase(strHost) If strHost <> "wscript.exe" Then Set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") strCmdLine = Chr(34) & objFSO.BuildPath(WScript.Path, "wscript.exe") & Chr(34) strCmdLine = strCmdLine & " " strCmdLine = strCmdLine & Chr(34) & WScript.ScriptFullName & Chr(34) objShell.Run strCmdLine Set objShell = Nothing Set objFSO = Nothing WScript.Quit End If Set fso = CreateObject("Scripting.FileSystemObject") ThisFolder = fso.GetParentFolderName(Wscript.ScriptFullName) Set objFolder = fso.GetFolder(ThisFolder) Set AllFiles = objFolder.Files FilesMoved = 0 FoldersCreated = 0 Ssec=DateDiff("s", "01/01/1970 00:00:00", Now) For Each File in AllFiles FileName = File.Name FileExt = fso.GetExtensionName(File) If lcase(FileExt) = "pdf" Then NumPart = Mid(Filename, 8,3) DS = 1+(Int((NumPart-1)/10)*10) DE = DS + 9 If DE = 1000 Then DE = 999 FolderName = Right(DS + 1000, 3) & "-" & Right(DE + 1000, 3) FolderExists = fso.folderExists(FolderName) If Not folderExists Then fso.CreateFolder(FolderName) FoldersCreated = FoldersCreated + 1 End If fso.movefile FileName, FolderName & "\" FilesMoved = FilesMoved + 1 End If Next Esec=DateDiff("s", "01/01/1970 00:00:00", Now) Elapsed = Esec - Ssec MsgText = FilesMoved & " Files moved " & vbcrlf & FoldersCreated & " Folders created" & vbcrlf MsgText = MsgText & "Elapsed: " & Elapsed & " second(s)" & vbcrlf MsgBox MsgText, 0, "Script finished" |
|
| 917. |
Solve : Get selective columns from a dump file using MS DOS and make new dump? |
|
Answer» Hi: I've found a problem in the script. It doesn't recognize blank field. Please help me in this issue as well. Picked column 3, 4 and 6. For Example:Not a problem with the script. It is more of a problem with your data. The FOR /F command always sees consecutive delimiters as one. If you would have provided that information upfront, I could have coded for that instance. That is the main problem with providing obfuscated data. It is better to provide real world examples up front.Thanks for your feedback. As I've said the script works fine if all the fields have value like below: (real time example) SUBCOS|RATE|DATE|ACCSTATE|PREVBALANCE|ACTTIME|USERSTARE|RATEPLAN|EXPIRY| 2|30|20150830|0|0|20160226235959|11|3|20170101000000| 2|44|20140329|0|0|20140923235959|12|4|20140328003330| 2|20|20140722|2|0|20150118235959|11|3|20140518151446| But if few fields are NULL, i.e. in second ROW there is no RATE (3, 4 & 6 columns are picked) SL|RATE|DATE|ACCSTATE|PREVBALANCE|ACTTIME|USERSTARE|RATEPLAN|EXPIRY| 2|30|20150830|55|99|20160226235959|11|3|20170101000000| 2||20140329|33|90|20140923235959|12|4|20140328003330| 2|20|20140722|22|91|20150118235959|11|3|20140518151446| Output comes: ---------------- DATE|ACCSTATE|ACTTIME| 20150830|55|20160226235959| ----Ok 33|90|12| -----As RATE field is blank, insted of picking DATE column, it picks ACCSTATE as column 3 which actually is 4 20140722|22|20150118235959| -----Ok Please let me know if you need any information. Thanks, TanvirThis uses dbenham's ParseCSV.bat to reformat the file and then Squashman's code to output the data. Save both batch files into the same folder as file.csv and run this one. Code: [Select]echo off call ParseCSV.bat "/i:|" "/o:|" <file.csv >file.csv.tmp for /F "tokens=3,4,6 delims=|" %%G in (file.csv.tmp) do >>newfile.csv echo %%~G^|%%~H^|%%~I del file.csv.tmp ParseCSV.bat Code: [Select]if (X)==(Y) end /* harmless hybrid line that begins a JScrpt comment ::************ Documentation *********** ::parseCSV.bat version 1.0 ::: :::parseCSV [/option]... ::: ::: Parse stdin as CSV and write it to stdout in a way that can be safely ::: parsed by FOR /F. All columns will be enclosed by quotes so that empty ::: columns may be preserved. It also supports delimiters, newlines, and ::: quotes within quoted values. Two consecutive quotes within a quoted value ::: are converted into one quote. ::: ::: Available options: ::: ::: /I:string = Input delimiter. Default is a comma. ::: ::: /O:string = Output delimiter. Default is a comma. ::: ::: /E = Encode output delimiter in value as \D ::: Encode newline in value as \N ::: Encode backslash in value as \S ::: ::: /D = Escape exclamation point and caret for delayed EXPANSION ::: ! becomes ^! ::: ^ becomes ^^ ::: :::parseCSV /? ::: ::: Display this help ::: :::parseCSV /V ::: ::: Display the version of parseCSV.bat ::: :::parseCSV.bat was written by Dave Benham. Updates are available at the original :::posting site: http://www.dostips.com/forum/viewtopic.php?f=3&t=5702 ::: ::************ Batch portion *********** echo off if "%~1" equ "/?" ( setlocal disableDelayedExpansion for /f "delims=: tokens=*" %%A in ('findstr "^:::" "%~f0"') do echo(%%A exit /b 0 ) if /i "%~1" equ "/V" ( for /f "delims=:" %%A in ('findstr /bc:"::%~nx0 version " "%~f0"') do echo %%A exit /b 0 ) cscript //E:JScript //nologo "%~f0" %* exit /b 0 ************ JScript portion ***********/ var args = WScript.Arguments.Named, stdin = WScript.Stdin, stdout = WScript.Stdout, escape = args.Exists("E"), delayed = args.Exists("D"), inDelim = args.Exists("I") ? args.Item("I") : ",", outDelim = args.Exists("O") ? args.Item("O") : ",", quote = false, ln, c, n; while (!stdin.AtEndOfStream) { ln=stdin.ReadLine(); if (!quote) stdout.Write('"'); for (n=0; n<ln.length; n++ ) { c=ln.charAt(n); if (c == '"') { if (quote && ln.charAt(n+1) == '"') { n++; } else { quote=!quote; continue; } } if (c == inDelim && !quote) c='"'+outDelim+'"'; if (escape) { if (c == outDelim) c="\\D"; if (c == "\\") c="\\S"; } if (delayed) { if (c == "!") c="^!"; if (c == "^") c="^^"; } stdout.Write(c); } stdout.Write( (quote) ? ((escape) ? "\\N" : "\n") : '"\n' ); } I had found another post online about changing the DOUBLE PIPES to |#null#| and then running that output to another FOR /F command to un-delimit the output. But then you have to run that data through another SET command to remove the #null#. Would probably have issues with poison characters as well.Thanks to both of you. It returns the correct output now but each field comes with " like below: "2"|"147500"|"1906342342"|"2"|"20140830125243" "2"|"0"|"1903312025"|"197"|"20140327111829" "2"|"765952"|"1903312029"|"160"|"20140327174850" I've tried removing " from parser file but the output become wrong again. Just need to eliminate the ". As I'm very beginner with DOS need further help. Another help I need - How can I call multiple files instead of a single one here call ParseCSV.bat "/i:|" "/o:|" <file.csv >file.csv.tmp i.e. call ParseCSV.bat "/i:|" "/o:|" <*.csv >file.csv.tmp ---I tried but it doesn't work Please help. Thanks/ TanvirIs it OK if I ask a question? If this was a CSV file -- Why not just use a SPREADSHEET to parse it. Just asking. Quote from: Geek-9pm on September 08, 2014, 08:42:21 AM Is it OK if I ask a question?I think the OP's last post answers your question. They need to do it on multiple files. Would you want to open up multiple files and manually process all of them on a daily basis? Quote from: tanvir.khan on September 08, 2014, 08:27:03 AM Thanks to both of you. It returns the correct output now but each field comes with " like below:That is not the correct output. It has more than 3 fields. Nor would it be the correct input because you said you wanted columns 3, 4 & 6 and you only have 5 columns. I used your last data example Code: [Select]SL|RATE|DATE|ACCSTATE|PREVBALANCE|ACTTIME|USERSTARE|RATEPLAN|EXPIRY| 2|30|20150830|55|99|20160226235959|11|3|20170101000000| 2||20140329|33|90|20140923235959|12|4|20140328003330| 2|20|20140722|22|91|20150118235959|11|3|20140518151446|And this is the output I got. Code: [Select]DATE|ACCSTATE|ACTTIME 20150830|55|20160226235959 20140329|33|20140923235959 20140722|22|20150118235959Program is working for the 2nd time as you described your data. I used the following input which has surround quotes around each field Code: [Select]"2"|""|"147500"|"1906342342"|"2"|"20140830125243" "2"|""|"0"|"1903312025"|"197"|"20140327111829" "2"|""|"765952"|"1903312029"|"160"|"20140327174850"And the output does not have any surround quotes. I did not change any of the code that Foxidrive posted. Code: [Select]147500|1906342342|20140830125243 0|1903312025|20140327111829 765952|1903312029|20140327174850Dear Geek-9pm: Actually it's not a CSV, those are text files as I mentioned in my first post. Dear Squashman: No, files will come in a folder automatically with extension .txt; I've to parse those make a single dump (an auto job will run every 1 hr) and upload into a Oracle database using SQL Loader. So, I need to parse all a files of .txt extension an make a single dump. My Input files don't have quotes. But when I run the Parse Script the output comes with quote. These quotes appear because of this line in the parse script: if (c == inDelim && !quote) c='"'+outDelim+'"' ---I removed quotes from here, quotes disappear but returns wrong result Did you use the same parse script foxidrive provided and also parsed from text file? Need further help. Thanks/Tanvir Quote from: tanvir.khan on September 08, 2014, 10:01:29 AM My Input files don't have quotes. But when I run the Parse Script the output comes with quote. These quotes appear because of this line in the parse script:No. It is not because of that line. Quote from: tanvir.khan on September 08, 2014, 10:01:29 AM Did you use the same parse script foxidrive provided and also parsed from text file?Quote from: Squashman on September 08, 2014, 09:50:42 AM I did not change any of the code that Foxidrive posted. |
|
| 918. |
Solve : note.bat? |
|
Answer» So I've been working on this project to redirect stdout and stderr into a temporary text file so you can view help MENUS in a separate window easily. It works for the most part at the moment, but for some reason it crashes with no error when executed on a batch file. Does anyone have any idea's what could be going wrong or how to fix it? How did you learn all that batch? Programming?There really isn't a TRUE IDE for writing batch. You basically can write your programs in any text editor and then double click on them to run them or run them from the cmd line by typing the name of the batch file. Most people do chose to use a programming text editor which helps in highlighting key words that are commands or variables. Some of these editors allow you to also run the program from editor. I prefer to use Notepad++ for all my batch files. Quote from: foxidrive on September 17, 2014, 10:36:43 AM See if this solves the issue. Without sample input command lines it's unclear how you are using it. I just tried that, and here is what I found: *I edited it to write to %temp%\note.txt instead of just note.txt, Should not alter outcome. Code: (cmd (no call)) [Select]Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\cmdPlugins>note repl /? C:\cmdPlugins>rem echo off C:\cmdPlugins>setlocal C:\cmdPlugins>set _=repl /? C:\cmdPlugins>if not defined _ goto :help C:\cmdPlugins>if /I "repl" == "/?" goto :help C:\cmdPlugins>repl /? 1>note.txt 2>&1 Code: (cmd (call %_%)) [Select]C:\cmdPlugins>note repl /? C:\cmdPlugins>rem echo off C:\cmdPlugins>setlocal C:\cmdPlugins>set _=repl /? C:\cmdPlugins>if not defined _ goto :help C:\cmdPlugins>if /I "repl" == "/?" goto :help C:\cmdPlugins>call repl /? 1>C:\Users\LEMONI~1\AppData\Local\Temp\note.txt 2>&1 C:\cmdPlugins>ping ::1 -n 2 1>nul C:\cmdPlugins>start notepad C:\Users\LEMONI~1\AppData\Local\Temp\note.txt C:\cmdPlugins>ping ::1 -n 2 1>nul C:\cmdPlugins>del /f C:\Users\LEMONI~1\AppData\Local\Temp\note.txt C:\cmdPlugins>goto :exit C:\cmdPlugins>endlocal So it runs when you use 'call %_%' but it writes the help menu to call and not repl (the batch file I'm testing with). 'start %_%' does not work, because it opens the help menu for repl in another cmd window, and does not redirect it to note.txt Quote from: RedDos7665 on September 17, 2014, 09:35:38 AM How did you learn all that batch? Programming? I learned mostly by reading these threads and downloading and examining other people's scripts. Quote but it writes the help menu to call and not repl That's funny. It's a bug in cmd that shows the help for the call command, but this is all you need: Code: [Select]echo off %* >"%temp%\note.txt" 2>&1 & notepad "%temp%\note.txt" It will only ever have the one temp file and will overwrite it every time. Quote from: foxidrive on September 17, 2014, 09:01:46 PM That's funny. Wow, no idea why that fixed it, but it works now. Thanks! Quote from: Lemonilla on September 18, 2014, 10:38:46 AM no idea why that fixed it, but it works now. If you write a batch file - and that script executes another batch file - then you need to use call to return to the next line in the script, otherwise the executed batch file will take full control and never return. This is the reason why your batch file didn't continue when you used note repl /? because repl ran and then it exited. Owing to the bug you found with call, you can't use call to simply fix your script. The batch file I posted above only has one real line so call isn't needed to return control to the script - and notepad is launched using the & command separator. HTH |
|
| 919. |
Solve : batch counter? |
|
Answer» I MIGHT need some help on a batch thing i'm working on. I need a COUNTER that goes from 1% to 100%, with variables that I can EASILY change the values with. Can someone just post the code here, and tell me where I can play around with the variables such as speed and LENGTH? |
|
| 920. |
Solve : Batch file to ping everyday and save in notepad? |
|
Answer» Hello, Please no code at the moment. ok. Which server are you going to ping? An internet server or a local server on the LAN? or do you have to do this for an assignment?A local server on LAN Code: [Select]echo off ping IPADDRESS >>"C:\path to\logfile.txt"Use Windows Task Scheduler to have it run every day at the time you WANT it to run.Please how can i make it name itself after the current date so that it will not replace each other?Please explain in better detail what you are trying to do. Please list examples of what you want. If you KEEP changing the parameters of what you need eventually people will not help you with your problem.The solution you GAVE saves the notepad file with the name logfile. I will prefer if it saves it with the name of the current date. This will change the name of the TEXT file with the current date. Code: [Select]echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do SET "dt=%%a" set "YYYY=%dt:~0,4%" set "MM=%dt:~4,2%" set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" set "Min=%dt:~10,2%" set "Sec=%dt:~12,2%" set "datestamp=%YYYY%%MM%%DD%" set "timestamp=%HH%%Min%%Sec%" ping IPADDRESS >>"C:\path to log\%datestamp%.txt"Thanks. |
|
| 921. |
Solve : VBscript named pipe? |
|
Answer» Quick ask for a change - I want to USE VBScript to create, and write to, a named pipe in Windows 7 Professional 64 bit. All the stuff I have found on the web says that named pipe SUPPORT in VBscript is limited to treating the pipe as a text file, e.g.: |
|
| 922. |
Solve : cos/sin 90 in vbs? |
|
Answer» Solved, vbs uses radians.So do most programming languages, don't they? 1 CIRCLE = 2pi radians Which is funny, since vbs doesn't have a static pi value or function. You have to calculate it. Dim PI PI=ATN(1)*4 |
|
| 923. |
Solve : Give me 10 example of batch file? |
|
Answer» Please help me.. GIVE me 10 examples of batch file and its function.. send me your ANSWER to my private email [email protected] I really NEED your help in 3 days. thanks |
|
| 924. |
Solve : Help to move files based on filename - Batch Script? |
|
Answer» Hi Experts, |
|
| 925. |
Solve : Need to Transfer Files to External Hard Drive? |
|
Answer» I have a laptop running Windows 8 that won't boot. I am trying to copy all the subdirectories under games to an external hard drive to save them. They are all in d:\program files (x86)\games. I can GET to the command prompt but that is all I can do. Thanks but this command didn't work! What did it say after you entered the command? |
|
| 926. |
Solve : call self without passing variables? |
|
Answer» So I have a program that reorganizes math equations into a different format that some friends showed me. Instead of writing 5+7 it would be written 57+. Or instead of 1+4/2 it would be 42/1+. It started to get a little complicated when (1+4)/(4+6) came around, which should be 14+46+/. To handle the parenthesis I am trying to call a new instance of my batch file with the operation withing the parenthesis to store in that space. The script I have below stores each character in a different slot in a psudoarray, and them moves them around based on what they are and uses a second parallel array to handle order of operations. |
|
| 927. |
Solve : deshabilitate my net adapters or habilitate.? |
|
Answer» deshabilitate my net adapters or habilitate. deshabilitate habilitate. I take note is enable/disable I have a laptop Yes I want to disable with a bat the internet connection disabling the net adapters (wifi, lan,...) Best Regards Quote from: Esgrimidor on September 14, 2014, 09:33:10 AM I have a laptop If your laptop uses standard DHCP to connect to the modem/router then you can use this: To disable the connections (until a reboot or by running the enable batch file) Code: [Select]echo off ipconfig /release To enable the connections Code: [Select]echo off ipconfig /renew It works !!!!!!!! Wonderful Wonderful Best Regards ! Glad to HEAR you were able to "deshabilitate"... |
|
| 928. |
Solve : Browse to a folder in Android from the command line? |
|
Answer» Browse to a folder in Android from the command line Then your path is wrong...find it in Win Explorer...right clik it and select Properties...the path will be shown. I continue INVESTIGATING. Seems necessary to root the device and adb.exe as shown above. But I RECEIVED information about the possibility to use Dropbox in the windows environment and in google environment..... I'll try and comment. |
|
| 929. |
Solve : MS DOS edit function? |
|
Answer» Hello there! |
|
| 930. |
Solve : Batch File Issue? |
|
Answer» How do we include supporting FILES in batch file. Suppose i have created batch file and i need some files like .exe files and pictures to be included in it and if i created exe of batch i should get an option to include all the supporting files to make the batch file a complete set . So if user downloads the batch file then even the supporting files should go with it. How do we include supporting files in batch file. Encoding the binaries into the batch script is one option. Quote i want batch file should automatically take up the path where i have downloaded the file. Can you explain what you mean by that? Quote Secondly suppose i have downloaded the batch file in the system anywhere and i want batch file should automatically take up the path where i have downloaded the file. How do we get that. Batch automatically makes the current directory that of the batch file as it is run. If you want reference that in your code, you can have a 'set home=%cd%' command at the beginning, or you can use '%~pd0' if you don't use the 'shift' command in your script. Quote from: Lemonilla on September 24, 2014, 08:40:34 AM Batch automatically makes the current directory that of the batch file as it is run. It does, except if you elevate PERMISSIONS when the c:\windows\system32 folder becomes the working directory.General Reference for BAT files: Information on batch files (CH) |
|
| 931. |
Solve : Unauthorized icon/smiley in my post? |
|
Answer» Hey, what gives?! |
|
| 932. |
Solve : luanch of executable from within .bat file fails? |
|
Answer» I am trying to get started with Google's Android Studio. I have installed the studio software and the Android SDK on my d:\ drive, as follows... I get the following error message... The message shows a relative path is being used. foxidrive: Yes, a relative path. That particular error message is displayed when SDK Manager.exe runs. That .exe is in the sdk folder, android .bat is in the sdk\tools folder, so the .bat file is in the tools folder relative to the exe. But it makes no difference how I initiate the process, SOMETHING is preventing the android tools from traversing the Windows path. Again, these files do all work on some systems. I'm pretty sure it is not a coding error in the various .exe/.bat files. My current best guess is there is a permission conflict. I just don't know what permissions, where to find them, and how to fix the problem. I've looked at the security settings in various Windows peroperty dialogs for the files and folders, nothing works. Except it does work, on other people's Windows machines. Just not on mine.Do you get a UAC prompt when running the installer? What are the user account control settings for the computers that it works on and your computer?From the Android Developer Website. Quote On some Windows systems, the launcher script does not find where Java is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.squashman: JAVA_HOME has been set on my system for a long time prior to trying to use Android, and it remains pointed at a valid JDK. Jerrysquashman: If I run the installer as administrator, I get the prompt. If not, no prompt. Either way, makes no difference, files still don't run correctly. User account control properties are the same on both computers (mine, Windows 7 Ultimate, where the SDK files don't work, and my wife's, Windows 7 Home Pro, where the SDK files do work)... Default - Notify me only when programs try to make changes to my computer. Something I had not noticed before, but in the SDK installer .exe's properties dialog, there is this message at the bottom... Security - This file came from another comptuer and might be clocked to help protect the computer. When I click the [ Unblock ] button, the text goes grey (and is not shown on subsequent openings of the properties dialog), but it makes no difference, the EXECUTABLES still do not work correctly. Quote from: Jerry Ford on November 24, 2014, 05:59:11 PM The batch files, BTW, appear to be correct, with no broken syntax. Your question is sorta like saying: "I wrote some source code and it doesn't work - can you tell me what's wrong with it?" and you don't show anyone the source code. Code: [Select]for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a On a casual examination, the code above will only work if the find_java.exe is in the same folder as the batch file. Quote from: Squashman on November 21, 2014, 10:10:16 PM Would probably help to see the contents of each batch file. This says it all...Okay, here are the two files where it starts. There are more, but I can't copy the whole SDK. It is a free download though, if you really want to purse all files INVOLVED. Get it here (you'll need to create an account, but,again, free)... https://developer.android.com/sdk/index.html?hl=i The SDK comes in an executable installer. When I run it (with or without administrative privileges, doesn't seem to matter, and it worked fine without on the Win7 Home machine where the SDK works), the last panel in the installer asks if I want to start the SDK Manager, which is to say run the file SDK Manager.exe that is located in the SDK top level folder. When I do, I get the error message Failed to execute tools\android.bat:, error 2 The system cannot find the file specified. When I open a command window and cd to the SDK tools folder, I run android.bat from the command line and get the error message '"D:\dev\android\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal or external command, operable program or batch file. The executable find_java.exe, which the message references, is actually called from within find_java.bat, both of which are in the tools\lib folder. Here's android.bat (in the SDK's tools folder), followed by find_java.bat... echo off rem Copyright (C) 2007 The Android Open Source Project rem rem Licensed under the Apache License, Version 2.0 (the "License"); rem you may not use this file except in compliance with the License. rem You may obtain a copy of the License at rem rem http://www.apache.org/licenses/LICENSE-2.0 rem rem Unless required by applicable law or agreed to in writing, software rem distributed under the License is distributed on an "AS IS" BASIS, rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License. rem Useful links: rem Command-line reference: rem http://technet.microsoft.com/en-us/library/bb490890.aspx rem don't modify the caller's environment setlocal rem Set up prog to be the path of this script, including following symlinks, rem and set up progdir to be the fully-qualified pathname of its directory. set prog=%~f0 rem Grab current directory before we change it set work_dir=%cd% rem Change current directory and drive to where the script is, to avoid rem issues with directories containing whitespaces. cd /d %~dp0 rem Check we have a valid Java.exe in the path. set java_exe= call lib\find_java.bat if not defined java_exe goto :EOF set jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar rem Set SWT.Jar path based on current architecture (x86 or x86_64) for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a :MkTempCopy rem Copy android.bat and its required libs to a temp dir. rem This avoids locking the tool dir in case the user is trying to update it. set tmp_dir=%TEMP%\temp-android-tool xcopy %swt_path% %tmp_dir%\%swt_path% /I /E /C /G /R /Y /Q > nul copy /B /D /Y lib\common.jar %tmp_dir%\lib\ > nul copy /B /D /Y lib\commons-codec* %tmp_dir%\lib\ > nul copy /B /D /Y lib\commons-compress* %tmp_dir%\lib\ > nul copy /B /D /Y lib\commons-logging* %tmp_dir%\lib\ > nul copy /B /D /Y lib\dvlib.jar %tmp_dir%\lib\ > nul copy /B /D /Y lib\guava* %tmp_dir%\lib\ > nul copy /B /D /Y lib\httpclient* %tmp_dir%\lib\ > nul copy /B /D /Y lib\httpcore* %tmp_dir%\lib\ > nul copy /B /D /Y lib\httpmime* %tmp_dir%\lib\ > nul copy /B /D /Y lib\layoutlib-api.jar %tmp_dir%\lib\ > nul copy /B /D /Y lib\org-eclipse-* %tmp_dir%\lib\ > nul copy /B /D /Y lib\sdk* %tmp_dir%\lib\ > nul copy /B /D /Y lib\swtmenubar.jar %tmp_dir%\lib\ > nul rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs. set tools_dir=%cd% cd /d %tmp_dir% :EndTempCopy rem The global ANDROID_SWT always OVERRIDE the SWT.Jar path if defined ANDROID_SWT set swt_path=%ANDROID_SWT% if exist "%swt_path%" goto SetPath echo ERROR: SWT folder '%swt_path%' does not exist. echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform. goto :EOF :SetPath rem Finally exec the java program and end here. REM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 call "%java_exe% %REMOTE_DEBUG%" "-Dcom.android.sdkmanager.toolsdir=%tools_dir%" "-Dcom.android.sdkmanager.workdir=%work_dir%" -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %* rem EOF Here's find_java.bat... echo off rem Copyright (C) 2007 The Android Open Source Project rem rem Licensed under the Apache License, Version 2.0 (the "License"); rem you may not use this file except in compliance with the License. rem You may obtain a copy of the License at rem rem http://www.apache.org/licenses/LICENSE-2.0 rem rem Unless required by applicable law or agreed to in writing, software rem distributed under the License is distributed on an "AS IS" BASIS, rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License. rem This script is called by the other batch files to find a suitable Java.exe rem to use. The script changes the "java_exe" env variable. The variable rem is left unset if Java.exe was not found. rem Useful links: rem Command-line reference: rem http://technet.microsoft.com/en-us/library/bb490890.aspx rem Check we have a valid Java.exe in the path. The return code will rem be 0 if the command worked or 1 if the exec failed (program not found). for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a if not defined java_exe goto :CheckFailed :SearchJavaW rem Check if we can find a javaw.exe at the same location than java.exe. rem If that doesn't work, just fall back on the java.exe we just found. for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s -w') do set javaw_exe=%%a if not exist "%javaw_exe%" set javaw_exe=%java_exe% goto :EOF :CheckFailed echo. echo ERROR: No suitable Java found. In order to properly use the Android Developer echo Tools, you need a suitable version of Java JDK installed on your system. echo We recommend that you install the JDK version of JavaSE, available here: echo http://www.oracle.com/technetwork/java/javase/downloads echo. echo If you already have Java installed, you can define the JAVA_HOME environment echo variable in Control Panel / System / Avanced System Settings to point to the echo JDK folder. echo. echo You can find the complete Android SDK requirements here: echo http://developer.android.com/sdk/requirements.html echo. goto :EOF Try changing this line: for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a to this: for /f "delims=" %%a in ('"%~dps0find_java.exe" -s') do set java_exe=%%a Also check that path to make sure that find_java.exe actually exists.Lemonilla: The change you suggest replaces the double backslash with a single backslash in the path to find_java.exe, so D:\dev\android\sdk\tools\lib\\find_java.exe becomes D:\dev\android\sdk\tools\lib\find_java.exe but either one works as a valid Windows path. And yes, find_java.exe does exist at that location, and when I run it from the command line it returns a valid path... D:\dev\android\sdk\tools>lib\find_java.exe C:\ProgramData\Oracle\Java\javapath\java.exe D:\dev\android\sdk\tools> ...which does point to the java executable in my JDK... D:\dev\android\sdk\tools>C:\ProgramData\Oracle\Java\javapath\java.exe -version java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b18) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode) But attempts to run the Android SDK Manager or andriod.bat still fail. |
|
| 933. |
Solve : Problem w/ Escape "^": cmd-line vs. batch? |
|
Answer» The SET command works at the interactive command line as I would like, but does not work the same when executed from TEST.BAT (see attached). |
|
| 934. |
Solve : How do you display the Syntax in DOS?? |
|
Answer» 1.) Display the syntax of the FIND command. |
|
| 935. |
Solve : batch for copy and rename? |
|
Answer» Ok one mroe last thing I need is to find all LogFile.txt from all subfolders and copy it in one folder and add a folder name to file name. Sorry this won't work, because I have added users and will add some more users. It solves the question as you asked it, with the details you provided. The code above the second echo off simply CREATES some files where you said they were so that it can show you that the code works. More users isn't a problem, and it doesn't use fixed folders in the way you obviously think it does. So I don't need to change batch file everytime I add a user folder? |
|
| 936. |
Solve : How to format windows 7 without installing a new version on my pc? |
|
Answer» Hello to EVERYONE. I INSTALLED windows 7 on my PC. I want to know how can I delete windows 7 WITHOUT installing a new version. I would like to delete everything so when you turn on the computer you can't do anything other than be at the beggining. As if you buy a computer without windows on it. I hope I was clear of what I would like. Thanks for the help. So basically you just want to format the hard drive so nothing is on it?Yes.why?Boot up a cdrom or USB with LIVE Ubuntu or other version of Live Linux and use the GUI file manager to delete all files on the HDD. why? It could be a malicious TASK but it's pretty easy to find a way to do it in google. |
|
| 937. |
Solve : Check if a process exists. If don't exist execute? |
|
Answer» Check if a process exists. If don't exist execute tasklist | find "notepad.exe" >nul And something THA may help with bat files or other scripts ? Best Regards You cannot. They appear on the system as instances of cmd.exe.How can i automate then to see is a process is running or not with a script. And if is not running, run it. Best Regards Quote from: Lemonilla on September 23, 2014, 09:43:38 AM tasklist | find "notepad.exe" >nulI use this Code: [Select]tasklist /fi "Imagename eq link.exe" 2>NUL | find /i /n "link.exe">NUL if "%ERRORLEVEL%"=="1" (goto D) else (goto B) first make a batch file than convert it to exe so I named it link.exe you must be carefull how you name it because some antivirus software can make you a trouble. to CONVERTING to exe I use "bat to exe CONVERTER" Quote from: Blisk on September 29, 2014, 01:21:04 AM first make a batch file than convert it to exe so I named it link.exeWhy do you even mention this? It has nothing to do with the original question. Nor does it help the OP solve their problem. |
|
| 938. |
Solve : Batch file to Sort and Move specific files by identifying a word inside the file? |
|
Answer» Hi All... |
|
| 939. |
Solve : Batch script to remove email user names? |
|
Answer» I am stuck on what should be a simple script. OS: Linux variant What OS are you using? DOH! Just noticed that. This is for a Win 7 machine. I already have a Linux Shell script that does the same thingTry this: Code: [Select]echo off setlocal enabledelayedexpansion (for /f "usebackq delims=" %%a in ("emails.txt") do ( set "var=%%a" echo(!var:*=! ))>>"domains.txt" PAUSE Foxidrive, Why didn't you just use the as a delimiter? Code: [Select]for /f "usebackq tokens=2 [email protected]" %%G in ("emails.txt") do echo %%G >>domains.txt Quote from: foxidrive on SEPTEMBER 29, 2014, 10:47:38 PM Try this: Thank You!!! Quote from: Squashman on September 30, 2014, 07:35:18 AM Foxidrive, I must be getting old - it didn't occur to me. Quote from: foxidrive on September 30, 2014, 08:44:27 AM I must be getting old - it didn't occur to me.It sucks getting old. Some days I walk into the KITCHEN and don't even remember why I went to the kitchen.When i bent over to TIE my shoes this AM i thought to myself..."what else can i do now i'm down here" ? ?Well at least I don't have trouble with my 1's and 2's. I have a solid leak every morning at 7am, and a full bowel motion every day at 7:30 am. Pity I don't get out of bed until 8am... |
|
| 940. |
Solve : Choice help? |
|
Answer» A few weeks ago I was asked to make an adventure game in batch, of all THINGS, for a game competition. That will be all saved locally and then once the competition is over I will send it to the judges to judge how well they play and then they will be score and that it. So I started but I had some problems and was wandering if you guys could help. It prints all values in the array table in java. Its just not a conventional way to weite it. It forces an error and breaks after the error. it's a bit of a poor example because it is doing something completely different from what foxidrive is suggesting. The direct equivalent in Java would be: Code: [Select]file.mkdir(sPath); the only error that can occur that cannot occur in your version is a "directory already exists" error. Checking for existence first is redundant. in an Actual application tasks involving files should check that the file exists first, but if it is ensuring that it exists, than the item already existing is not an error. Quote from: BC_Programmer on September 24, 2014, 06:16:24 PM completely different from what foxidrive Squashman is suggesting. I do agree that Squashman's code is what I'd use too. Quote from: foxidrive on September 24, 2014, 09:39:47 PM Not sure how people confuse us. We look nothing alike! |
|
| 941. |
Solve : log batch file? |
|
Answer» how to log this batch file in one single logfile.txt I have removed that line but it is the same Are you trying to tell us something? Quote from: foxidrive on September 23, 2014, 07:12:27 PM Are you trying to tell us something?Yes, still not getting full log of what I see in cmd when start this batch file. Have you any IDEA what can be worng? Quote from: Blisk on September 23, 2014, 11:48:10 PM Yes, still not getting full log of what I see in cmd when start this batch file.So you want to log everything? Not just the command that you gave as a singular example.everything what I get on screen when I run that in cmd.Check out [ulr=http://www.dostips.com/forum/viewtopic.php?f=3&t=5386&p=32561&hilit=tee#p32561]batchTee.bat[/url] by dbenham.If you want to see it on the screen and log it to a file then you would need to use some iteration of TEE. If you just want to log everything when you type it in from the command prompt then just do this. Code: [Select]C:\>MyBatchfile.bat >>logfile.txt 2>&1Remember if you really want to see everything then you need to make sure you are not suppressing any output with the ECHO OFF command. By default it is on but you might as WELL put ECHO ON at the top of your batch file just to be on the safe side.I don't have echo off in batch file and I just want to log all what I see in cmd when I run batch file. Quote from: Blisk on September 26, 2014, 01:21:09 AM I don't have echo off in batch fileQuote from: Lemonilla on September 24, 2014, 08:37:08 AM Check out batchTee.bat by dbenham. This is what you need, look at it.I tested it and now it WORKS, thank you. I have make a mistake before I forget to add at the end of batch file this 2>&1 |
|
| 942. |
Solve : Grid problems? |
|
Answer» After finishing my goal for the Adventure game for the month, I decided to start mucking around at what I could do, and my friend asked me to make a grid...... |
|
| 943. |
Solve : Batch code to upgrade specified softwares automatically everyday.? |
|
Answer» Hi All, |
|
| 944. |
Solve : Check for number of times a file has been accessed? |
|
Answer» I want to write a BATCH file that checks if a particular file has been accessed a certain number of times, then deletes it if it has. Is it bad form to multipost? On different forums, no, it is fine (of course!) to post the same question. You have done nothing wrong. Quote from: nathan323 on October 03, 2014, 04:11:44 PM Hi. Is it bad form to multipost? Im trying to get a good cross reference of answers. Just curious.. The only thing is that the majority of the regular posters are also on that forum, so what foxidrive meant by that was that he already posted on your other thread and wont be posting the same response here.ahhh, I get it, thanks.Well a COUPLE of things could happen. Two people helping you on two different forums may interpret your question differently and may lead you in the wrong direction which may confuse either you or the person helping you. And a lot of times I see people post a question and the question get answered or the person trying to help asks for more information and the original poster abandons the thread because they started getting help on another forum and has then wasted the time of the person trying to help. Either way it would be nice to know if you have posted on another forum so that everyone can see what is going on. Quote from: Squashman on October 03, 2014, 09:25:25 PM And a lot of times I see people post a question and the question get answered or the person trying to help asks for more information and the original poster abandons the thread because they started getting help on another forum and has then wasted the time of the person trying to help. The above is how I see it too. A poster will usually ignore every other site he has posted the question on when he gets an answer, and not tell them that he has an answer. I understand. I am aware of this THOUGH when I post and address all posts. From now on I might list the URL's of any other sites Ive posted to in each original post. Cheers everyone.Just curious why you would want to delete a file that seems as if it would be frequently accessed by the system or manually by the user? Files that are frequently accessed are usually not deleted. |
|
| 945. |
Solve : write each host IP in a file using host name? |
|
Answer» Hi, |
|
| 946. |
Solve : Execute all within the selected folder? |
|
Answer» I would like a script to open all the urls within a folder in tabs in the default browser, and any other launchable apps or documents in the folder with the default app. launcher. The task seems like an unrealistic explanation of what you want to do, and you seem to expect a solution to something that you aren't describing. I try this. A lot of windows, virtual machines, programs , documents collapsed my pc. After about of 20 minutes suffering i lost internet and reiniate the pc. Really don't seems a good code. The above code wouldn't have caused ANY of those issues...I am trying to analyze what happens. Seems everything on my desktop was executed. I have ten virtual machines about and only 4 GB RAm memory. Several pdf, word documents, and many folders. THUNDERBIRD messages. Too much load. Also execute several bats I have from good programmers to stop services and PROCESSES. Best Regards. 10 VM's on 1 PC with 4G of RAM ? ? There my friend is your issue right there... Quote from: patio on October 12, 2014, 12:24:56 PM 10 VM's on 1 PC with 4G of RAM ? ? I don't execute the VM at the same time..... But the script above did or try until collapse. I have other pc with 16 GB ram and i can have two or three virtual machines running at the same time. Best Regards Quote from: Esgrimidor on October 12, 2014, 12:16:59 PM I try this. BECAUSE BASED ON YOUR INITIAL DESCRIPTION, THAT IS WHAT YOU ASKED TO DO! Quote from: Esgrimidor on October 11, 2014, 01:29:21 PM I would like a script to open all the urls within a folder in tabs in the default browser, and any other launchable apps or documents in the folder with the default app. launcher. If you execute the script you were given it will do exactly what you describe to whatever is in the current folder! In this case, whatever is on your Desktop since you launched it from there! Quote from: Squashman on October 12, 2014, 12:51:57 PM BECAUSE BASED ON YOUR INITIAL DESCRIPTION, THAT IS WHAT YOU ASKED TO DO! Have you tried ? I will not try more. But a second try in a folder with eight url also collapsed my system. Endless console windows appearing and appearing. oh... Foxidrive forgot the if statement, though really not his fault. Sounded too much like homework to me, but here is the fix: Code: [Select]echo off for %%a in (*) do if not "%%a"=="%~nx0" start "" "%%a" pause It was opening itself each time it executed, though you should have been able to figure that one out if you had tried to debug it. Quote from: Lemonilla on October 12, 2014, 02:52:23 PM oh... Foxidrive forgot the if statement, though really not his fault. Sounded too much like homework to me, but here is the fix: Better wait a little more and try perhaps in a virtual machine or in a sandbox. Best Regards You need to think about your goal here...and re-state it as to what you want it to do...Or just keep it outside of the folder that is being processed and do a Change directory as the first LINE of code or a PUSHD. |
|
| 947. |
Solve : Safe Internet? |
|
Answer» I have a friend with problems with virus. What is the point of asking for a password? Anyone can open up the bat file and see the password you are checking the input against. Don't worry about that. Are not expert users. Only needed express is not allowed. even better is launch with the bat a set or url that are needed in this case for the special purpose. In general launcha urls from inside the virtual machine. Esgrimidor, Anything that really helps is useful. Bat your IDEA of DOS level passwords does does not find support. Microsoft has put password protection at the Windows log in. It would seem that other log in scripts are of no value. May I suggets this article: Windows 8 Security: What's New The PCWorld article was published two years ago, In PART it said: Quote Antivirus Comes PreinstalledTrue, people need hope. But offering a FALSE hope is hardly better than no hope. There are TOOLS that can reduce the risk of a virus infection. So far, I have never saw a DOS based program that helps. However, if you have found a new idea, please tell more. Nebelous query of the Month Finalist...Tell your friend to post here so we can try to help him or herWe have certainly helped you with a lot of batch files over the years. I would think you could at least start to attempt to write the batch file first and then ask for help.Hard times for me indeed. Don't worry. Try if you can. Quote from: Geek-9pm on October 11, 2014, 04:05:06 PM Esgrimidor, All I need is a simple password. With that is enough. Only target is ask a simple word. No matter in this case the additional security. It's a way to remember the browser in the system is only for certain uses. Best Regards Quote from: Esgrimidor on October 12, 2014, 01:24:13 PM Hard times for me indeed.There is only so many times we can give the fish to you. At some point you have to learn to fish. Quote from: Allan on October 11, 2014, 04:30:18 PM Tell your friend to post here so we can try to help him or her Don't write english It's 78 years old. I will continue with this project. Maybe I can help. I am 76 years old. Most things in Windows are now done at a higher level than DOS. An the things you do in DOS are local transitory, they are not a global and persistent. To gather a password for a specific purpose, you would write a program in one of the suitable languages that can present a visual interface to the user. Some of these can be built on DOS, but are at a higher level. For some time Microsoft has recommended that users subbasement their DOS batch files with Vb Script to make things easy. http://www.instructables.com/id/VBS-Tutorial-Basics/ Quote What is vbs?The above tutorial has scripts and picture to help ;you write a simple script to get information from a user. A VB Script can be invoked from inside a batch file. Please look over the tutorial. Teach a man to fish...Hard times for no programmers like me. Very nice to receive so many lessons about how to do. |
|
| 948. |
Solve : Trying to understand snake.bat's realtime input system? |
|
Answer» So I've been pondering this for quite a while, but I still cannot figure out how the real time input works in snake.bat. If anyone understands it and would be willing to walk me though it's process, It would be much appreciated. real time input worksBatch programs do not have real time input. They are batch programs. By definition they are background tasks. Explain what you think the program does. Then we can focus on just that little bit of code that does what you DESCRIBE. That code is much to large to post here. Tell us what you think it does and somebody here with exact the few lines of code that do what you think it does. It uses xcopy and a feature where the character is echoed, and that character is extracted to tell which character was pressed. Post in the snake.bat THREAD and Dave is most often HAPPY to answer specific questions Quote from: foxidrive on April 01, 2014, 11:18:09 PM Post in the snake.bat thread and Dave is most often happy to answer specific questionsAgreed. Why not go straight to the source and ask the question.The XCOPY input hack is not that complex. If you study the code and run some experiments, you should be able to figure it out. The interesting bit is how the game uses multiple processes and communicates between them via files. This is the critical design that allows the input to be non-blocking. See http://www.dostips.com/forum/viewtopic.php?p=31035#p31035 for a HIGH level explanation of the inter-process communication. Dave Benham |
|
| 949. |
Solve : [type] Input line too long? |
|
Answer» I'm getting a funny error that I thought was due to my abnormally long string, but when I started debugging I'm getting an error when using the 'TYPE' command. Has anyone ever had issues with this before? |
|
| 950. |
Solve : [HELP]Output two values in batch log to .csv with headers? |
|
Answer» Greetings Everyone, |
|