Explore topic-wise InterviewSolutions in .

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.

801.

Solve : printing your hardware and drivers in a report?

Answer»

I seem to remember a Dos comand that would print a list of all hardware and  I think it even listed the drivers. I  can't remeber the command. Can anybody help me? :-/Not a DOS command but a program that M$ included with some versions of DOS. It is MSD.exe. The info it gives may or may not be accurate. It should be run from a DOS PROMPT outside Windows to get the DOS information. From a DOS prompt inside windows it will display the info that is passed to it by windows. Do not use it on 2k or XP systems unless you KNOW they are FAT32 FORMAT. If it is not on your HD and you are using W98x, you can find it on the windows CD in a directory named olddos.All you ever wanted to know about your system.

Everest Home Edition: http://www.lavalys.com/products/overview.php?pid=1&lang=en
Belarc's free Advisor will give a comprehensive analysis in an HTML file in Windows. The MSD utility for DOS is reasonably good in DOS, but other utilities (Norton's old SysInfo utility and Central Point Software's CPDesktop come to mind) give even better analyses. 
Thanks for the help. You have MADE installing a new HARD drive such much easier.
Thanks again

802.

Solve : Any way to run a batch file with NOUI??

Answer»

I am trying to run a batch file remotely.  Is there anyway to have it run without bringing up the DOS screen?  I wan't users to not know it is even running.

Thanks in advance!Use a .PIF with the .BAT file. In the program information file, specify 'run minimised'.

Add the following lines to your batch file:

[glb]echo off
mode CON:=nul:
break=off[/glb]

(current batch file text)

[glb]break=on
mode con:=con:[/glb]

These will disable echo of commands to the screen and ROUTE the program outputs to the NUL: device. Be sure to test the batch file before ADDING these lines as they disable the ability to monitor the batch file's progress or any error messages from the batch file.This still results in the MS-DOS icon appearing on the task bar for the DURATION of the DOS session...
There may be something you can put in a PIF to disable the taskbar session... check the OPTIONS.

803.

Solve : Delete everything?

Answer»

Hi. I am in a TIGHT jam right now, and any help is appreciated. I TRIED to install Windows, but after it INSTALLED, it wasn't ABLE to use the boot disk because it is not having a driver that works with my CD ROM drive. I have my own driver on a floppy disk. Any way.

How can I delete all partitions and erase everything, so that I may start with a fresh start?  Use a floppy boot disk with the following utilities:

himem.sys
emm386.exe
fdisk.exe (or fdisk.com)
format.com
sys.com

in addition to the CDROM drivers and personal favourite edittor, etc. Your autoexec.bat and config.sys should load XMS (himem.sys), dos=high,umb, EMS (emm386.exe noems), and the CDROM drivers.

You use FDISK to remove all partitions from the drive and assign new ones, then FORMAT to prepare them for OS install (the format of your first (primary boot) partition should include /S to include room for system files) Then you install your OS.

If this is in regards to Win9x, copy the entire contents of the CD to the hard drive by including

xcopy*.*

for the DOS version on the boot floppy and using

xcopy cdrom drive letter: c:\wininst /s /e

to copy the complete directory structure to the hard drive.  Then install from that copy. The copy is best placed on a partition other than the boot partition.Download the disk manufacturer's DIAGNOSTIC utility and use the option to write zeros to the drive.  It'll be like a factory-fresh disk.

804.

Solve : How do I boot up in dos w/o windows access??

Answer»

I want to retrieve some information in a text file from a hard drive that decided it didn't want to load up windows anymore.  I know the necesary dos commands to get to my document (i have been researching) however, being [unfortunately] raised on windows, i don't know how to boot in Dos without windows access.I can think of 3 ways:

1) Press the function key F8 when your computer BOOTING, just as windows is LOADING (I think must be before the window logo). U will be PROMPT whether u want to boot to normal mode, safe mode or DOS mode.

2) PUT a windows startup disk and set the PC to boot from your bootdisk 1st.

3) DISCONNECT the faulty disk and reconnect it in another working PC with same or newer OS as a seconday harddisk.Thanks much, SKy.  #1 sounds like it will be best for me. Quote

Thanks much, SKy.  #1 sounds like it will be best for me.


This will work for Win98, Win95, but not WinXP or Win2k.   See: http://www.bootdisk.com/
805.

Solve : Urgent Help : Batch File Terminate Program?

Answer» DEAR all,

I'm newbie in Batch File, I would like to seek assistance here.

The problem is, how to TERMINATE a program(e.g Calc.exe) in batch file and after terminate it, I would like to restart the program again.

How to do it in batch file? please help

Thanks in advance


Cheers,
yymaeAutoIt http://www.autoitscript.com/autoit3/ can solve this problem for you.Besides AutoIt, do you have another solutions?I don't have another solution, but I never needed another solution.  Depends on the OS you're using.. if you're using winXP, you can USE taskkill to kill any PROCESS.... for example, to kill calc.exe,

"taskkill /F /IM calc.exe"

"taskkill /?" - if you need more infor on what the F and IM stand for

if you're using an older OS like windows98, you'll have to download a resource from the microsoft website that includes "kill.exe" which will do the same thing as taskkill
806.

Solve : Log results of bat file with timestamp name.?

Answer»

I have done a search on the front page, and in the forums, and I couldn't find out how to do this.

I want to log the results on a bat file I run, and save it in a specific folder with the date and time as a name. Example: "2004.08.04-13.27.log"

The batch file I have runs a program, which DISPLAYS it's results in the open dos window, and then connects and uploads a file to and ftp server. I want to take all the information displayed on the dos file, create and store it in a log file.

I don't know how to copy what is displayed, and save it to a file.

Thanks for your help.Well, for many (most?) DOS applications, simply redirecting the output will do it.  For INSTANCE, the command:

DIR >C:\LISTING.TXT

... creates the directory listing in C:\LISTING.TXT.

http://garbo.uwasa.fi/pc/batchutil.html has a ton of DOS command LINE utilities, I'll bet something there will do the trick. I looked in that link, there doesn't seem to be any information about logging, or creating logs from your batch file.Well, it's a giant collection of utilities, that's all.  When I wanted what you seek, I WROTE a 10 line C program to do the job.

807.

Solve : Best method to offload files from failing SATA drive??

Answer»

I have a 2TB storage drive in my W7 64bit system that has suddenly developed errors (see attached image)

It's under warranty so the only thing I'm concerned about is recovering as much as I can of the 900-odd gigs of stored data and apps.

I've tried lots* of Windows-based copiers but they're all slowed up by Window's reluctance to deal with the ailing disk, so even a few gigs can take an hour or more. And then suddenly the disk can disappear from Windows altogether and doesn't come back until a reboot.

(*Windows copier, Teracopy Pro, O&O DiskImage, Unstoppable File Copier etc etc)

So I thought of XCopy or something similar in DOS.

However, I'm no expert with non-Windows solutions, so I'd appreciate advice.

Thanks for reading.
Have you chilled the drive before trying to recover your data?

I have seen drives that fail quickly last longer to copy data when the drive has been chilled in the fridge before use. You want to make sure the drive stays DRY while in fridge such as you can put it in a ziplock bag in fridge and chill it. Then have your computer open and ready to connect the drive. With computer off. Remove drive from fridge and connect it chilled. Then BOOT the system and go copying data. You might find that the drive will behave until it warms up and then cuts out again.

I have an IR Gun for measuring temperatures and a 500GB Maxtor drive I had was working for about an hour and then it would start to lag and DELAYED write errors. When i went to remove the drive I noticed that it was uncomfortably hot to the touch. Got my IR Gun to measure its temp and it was 158F at the hottest area around the motor and the PCB was in the 120-130F range. I was able to chill my drive and recover my important data before it would roast and cut out again.

Relocated sectors meas that an area of the drive is physically damaged and so you might find that some data you have is corrupt. If your lucky its not anything important that is trashed from damaged sectors.

XCOPY could be used to copy the data from this drive to a healthy drive. If your data is located in a single location you can xcopy the data from that target location and all files and subdirectories within it reconstructed onto a healthy drive ( as long as files are not in use )

My data on all my systems are located at C:\Data and so if i was to xcopy my data to a external drive or another internal drive I use something like this.

XCOPY C:\data\*.* F:\data\*.* /s/d/y/h

The switches I use here grab everything and if the destination already has an older version of this data  it will skip over files that are exact to date/time and name, any files that are newer than the files at the destination get overwritten at the destination. This XCOPY method also works best when you have a drive that runs for a while and then craps out. You can rechill the drive and then use the same instruction you used for your system and it will skip over files already transferred and it will transfer those that have not been transferred yet, basically picking up where it left off after skipping whats already been copied.

Note if your path has any spaces you will need to enclose the paths within "" such as XCOPY "C:\My Data\*.*" "F:\My Data\*.* /s/d/y/h" or you will get an error.You need to do it incrementally...in smaller chunks.  Priority files first...let the drive rest between operations and it should do fine.Thanks Dave. I've tried the freeze-drive technique a few times over the years - I'm a retired pc builder and serviceman - but never had much luck with it on customer's munted drives.

But heat's not the problem with my drive, as you can see from the temperature in the pic.

No, I think a DOS solution is likely best, but I've forgotten all I ever learned about those processes.

So I thought I'd ask the DOS experts . Mostly about the switches.

Like exclusions, say. There are a couple of 300GB sub-folders that I could probably leave for now, and try them again later when I've copied the more important stuff. Trouble is, they have long-ish names and I'm not sure Windows will let me rename them to something shorter.

Another thing is there's a lot of sub-folders within the source folder I want to copy from, and this source is also a sub-folder of the single-partition hard drive.

Here's a typical path:  S:\Download\Chrome stuff - where S is the ailing 2TB drive, Download is the 900G storage folder, and Chrome stuff a typical folder inside Download.
However, S:\Download\Music has a dozen or so subfolders.

Is there an exclusion switch? And maybe also one that will pass over uncopyable folders? After all, there are bad sectors on the drive 

PS: Thanks, Patio, just found your post. That's a good suggestion.




Here is the help for xcopy. As far as excluding damaged files, I am not aware of an exclusion of that type unless the destination already had a copy of the file and a COMPARISON made between current and last backup which can be done in a batch and a choice made as prompted to overwrite a file or not of one size and date/time with another. For the fact that you dont have a old backup to compare against I am not aware of any other way to test files for corrupt ones to skip over.


However you may have to add the /C switch to the xcopy to get it to skip when an error happens. This might be the solution for if the instruction encounters a file that cant be copied.

/C           Continues copying even if errors occur.

Quote

C:\>xcopy/?
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a separate line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
  /V           Verifies the size of each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /G           Allows the copying of encrypted files to destination that does
               not support encryption.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.
  /B           Copies the Symbolic Link itself versus the target of the link.
  /J           Copies using unbuffered I/O. Recommended for very large files.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

The OP may want to search the internet for:
Forensic Data Recovery

Some offer special software. But  others require you to ship the drive to them.
Prices vary. Watch out! 

Here's an article from one such company  that explains what might be done.
https://westerndatarecovery.com/services/forensic-data-recovery/
Quote
“Forensic techniques and expert knowledge are used to explain the current state of a digital artifact, such as a computer system, storage medium (e.g. hard disk or CD-ROM), or an electronic document (e.g. an email message or JPEG image).[3] The scope of a forensic ANALYSIS can vary from simple information retrieval to reconstructing a series of events.”
The process is often used in legal issues and can also be used to recover data from a bad drive.Hi

When working with a drive with bad sectors or slow access it is better to make a raw copy to a known good drive of the same size or larger capacity. This drive needs to be blank. Also it is better to have both the failing drive and the known good drive attached direct to sata ports in the computer. Then do the copy from the good drive.
To make the raw copy :
A program which is easy to use is https://hddguru.com/software/HDD-Raw-Copy-Tool/
This will skip bad sectors and allows you to restart the drive if windows decides to shut the drive down.
Or there is the linux tool DDrescue .
Also there is the option of using a linux live disk which would allow you to copy and paste the files you wanted from the drive using file manager.
Because of the way Linux accesses the drive it copes better with bad sectors .
Parted magic, although not free boots on most systems. It also includes DDrescue and file explorer.      https://partedmagic.com/
 

808.

Solve : edit a text file in numerous folders?

Answer»

Hello,
I have a folder, in that folder there are numerous other folders with random names, inside each of these folders there is a file called movie.nfo in that text file there is a line that says random text I was wondering if it would be possible to CREATE a batch script that could be run from the parent directory containing the random folders for it to edit these text files and replace random text with the name of the folder they are contained within, would save me some serious time if this could be done so would be grateful for any help given.
Thanks.if you need to do that only once you can use notepad++
with that you can change the same string in multiple files.
If not you can use a little program called fart.
And maybe use it in bachThanks for your reply Blisk, I have downloaded notepad++ and looks like this could do what I'm wanting if I just knew what phrase to use to call the parent folder name in the renaming process, any ideas?Hi, I'm still stuck on this problem I've spent I don't know how may hours trying to figure a solution to no avail, I've created scripts in the past but always with help as I don't pretend to know much of the language needed, I try and learn but the fequency that I actually need to make a script means I've forgoten half of what I've learned by the time it comes to need to write another, I've tried using notepad++ as suggested but don't think there's anyway to call the parent folder for the rename process, there's basically 3 things I need to achieve

1. method to open movie.nfo recursively through numerous subfolders
2. use a find and replace string for the text inside the movie.nfo files and
3. be able to call the parent folder of the movie.nfo file to be used in the replace string

surely that these 3 things must be achievable using a batch or vbs script?

I've read that there could be a problem using a batch file in that the text I'm trying to find includes < and > which I understand these are special characters that will cause the script to do something other than intended but also read that you can use ^ before special characters to stop this? I know how to use find and replace using a vbs script and that's fine in replacing random text but don't know how to do 1. and 3.

please someone help I'm pulling my hair out on this one!
Can you clarify one thing? In each subfolder you have exactly one movie.nfo file, and at the end you still want exactly one movie.nfo file, and everything in that file is the same as it was before, except that any line like this blablabla you want to change to sub folder name . Is that right. OK two things. Is that just the folder name or the WHOLE path?

Example

In a folder called sub101 you have movie.nfo, do you want to see this? sub101   ? Is that correct?

OK three things. Do you want the old movie.nfo to just vanish, or be renamed, e.g. movie.nfo.old ?

Fourth question: You have a main folder, and under this are a bunch of (let's face it!) folders with movies in them. Is each movie.nfo file in a folder one level below the main folder?
Thanks for your Reply Salmon Trout in response to your first reply you've interpreted it exactly correct in what I'm trying to do and regards to the old movie.nfo file yes I'd be happy for that to dissappear, overwritten etc and regarding 'Fourth question: You have a main folder, and under this are a bunch of (let's face it!) folders with movies in them. Is each movie.nfo file in a folder one level below the main folder?' yes that is also absolutely correct, thank you for your time, I do hope you can help (fingers crossed)I am going to use an example movie.nfo I found on the Kodi wiki on this page

https://kodi.wiki/view/NFO_files/Movies

I hope this is the right format?




File movie.nfo in subfolder sub101

1. Before


2. After
Yes Salmon Trout that’s PRECISELY what I want to achieve.I made 20 subfolders each with the same movie.nfo, and ran the batch below. It is a bit slow, even on an SSD. It has to process every line of each movie.nfo, and takes about 20 seconds each time on my system. 20 files took 8 minutes. Put the batch script in the folder above the subfolders.

I suggest you try it with a test folder first in case it trashes all your nfo files!!!! Also test the movie.nfo with whatever app you are using them for.

echo off
setlocal enabledelayedexpansion
set thisfolder="%~dp0"
echo.
cd /d "%thisfolder%"
set nfos=0
echo Folder: %thisfolder%
for /f "delims=" %%A in ('dir /b /ad') do if exist "%%A\movie.nfo" set /a nfos+=1
echo Found %nfos% movie.nfo file(s) under this folder   
echo Press a key to process files
echo or CTRL + C to abort
pause
echo %date% %time% Started
for /f "delims=" %%A in ('dir /b /ad') do (
   echo !date! !time! Checking folder %%A
   if exist "%%A\movie.nfo" (
      echo !date! !time! Found movie.nfo: YES
      cd "%%A"
      if exist movie.nfo.new del movie.nfo.new
      for /f "delims=" %%B in (movie.nfo) do (
         echo "%%B" | find "<title>" | find "</title>" >nul && (
            echo !date! !time! Old: %%B
            for /f "tokens=1-4 delims=^<^>" %%C in ("%%B") do (
               echo %%C^<title^>%%A^</title^> >> movie.nfo.new
               echo !date! !time! New: %%C^<title^>%%A^</title^>
               )
            ) || (
            echo %%B >> movie.nfo.new
            )
         )
      del movie.nfo
      ren movie.nfo.new movie.nfo
      cd "%thisfolder%"
      ) else (
      echo !date! !time! Found movie.nfo: NO
      )
   )
echo %date% %time% Finished - press a key to close
pause

 

Thanks so much Salmon, I’m out at the minute so will be a few hours before can try this out, but can’t wait to give it a go, the time it takes to process isn’t a big issue so that should be fine, I’ll report back when I’ve tried it.Thanks Salmon script works perfectly really appreciate your time in helping me with this, I did have an issue when first tried the script the script was escaping at the point where it says press key to continue or ctrl c to abort, I moved test folder to C: drive and it worked, thought it might have been due to security setting which did differ on the other drive so altered them and still no good on original test folder, tried it on another drive that worked, anyway to cut a long story short after a bit of head scratching worked out the reason was due to the folder was running it from had () in the title 'Movies (1)' on renaming the folder to 'Movies 1' the script worked, you'll probably understand the reson why the brackets in the folder name stopped it running but it really doesn't matter to me, I don't need the parent folder to contain brackets so all is good.
    GLAD it worked! Is this just a one-time thing, or are you going to be doing this a lot? Because I have been working on a much faster version using VBScript.
My VBscript processed the same 20 files in 0.6 seconds. As before, try it out on test files/folders first!!! Place as a .vbs file in the top folder (like the .bat) and you can double click it in Windows Explorer. You should not see a console window, just 2 message boxes.

Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = createobject("wscript.shell")
strScriptDir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)

iInfoCount = 0
For Each objFolder In objFSO.GetFolder(strScriptDir).SubFolders
   aFilePath        = split(objFolder.Path, "\")
   strSubFolderName = aFilePath(Ubound(aFilePath))
   strNFOpath       = objFolder.Path & "\" & "movie.nfo"
   If objFSO.FileExists(strNFOpath) Then
      iInfoCount = iInfoCount + 1
   End If
Next
v = msgbox("Found " & iInfoCount & " movie.nfo file(s)" & vbcrlf & vbcrlf & "Click OK to start or Cancel to quit", 1, "Movie.nfo processor")

if v = 2 Then
   wscript.quit
End If

st = timer
iFiles = 0
For Each objFolder In objFSO.GetFolder(strScriptDir).SubFolders
   aFilePath        = split(objFolder.Path, "\")
   strSubFolderName = aFilePath(Ubound(aFilePath))
   strNFOpath       = objFolder.Path & "\" & "movie.nfo"
   If objFSO.FileExists(strNFOpath) Then
      set nfoFile = objFSO.OpenTextFile(strNFOpath, 1)
      content = nfoFile.ReadAll
      aNFOfileLines = split(content, vbcrlf)
      For iLine = 0 To Ubound(aNFOfileLines)
            strThisLine = aNFOfileLines(iLine)
            If instr(strThisLine, "<title>") > 0 Then
               If instr(strThisLine, "</title>") > 0 Then
                  strLineIndent = Space(instr(strThisLine, "<title>")-1)
                  strOldLine = strThisLine
                  strNewLine = "<title>" & strSubFolderName & "</title>"
                  aNFOfileLines(iLine) = strLineIndent & strNewLine
                  Exit For
               End If
            End If
      Next
      nfoFile.close
      objShell.currentdirectory = objFolder
      Set objTextFile = objFSO.OpenTextFile ("movie.nfo.new", ForWriting, True)
      For iLine = 0 To Ubound(aNFOfileLines)
         objTextFile.WriteLine(aNFOfileLines(iLine))
      Next
      objTextFile.Close
      objFSO.DeleteFile "movie.nfo"
      objFso.MoveFile "movie.nfo.new", "movie.nfo"
      objShell.currentdirectory = strScriptDir
      iFiles = iFiles + 1
   End If
Next
et = timer
strMsg = "Processed " & iFiles & " file(s)" & vbcrlf & vbcrlf & "in " & et-st & " seconds"
v = msgbox(strMsg, 0, "Movie.nfo processor")


809.

Solve : Run JOB in cmd?

Answer» HI

I have to list of the job id to run by manual , so I write the operation menu to let operator run the job in sequence, but this option is banned by supervisor.  Alternative, I have to create the text file  contain the jobid number , then run the batch file to read this text file to run the job according the dependent and individual job. 

I create the text file which contain. To auto run P107C then P105C  after running completed P107C,  run P110C until P105C completed.

Can you please assist me how to write the script to read this jobid text file to auto run the job by dependent. 

P107C;IND=Y;;0
P105C;;P107C;0
P110C;;P107C;0
D101C;;P110C,P105C;0
P106C;IND=Y;;0
P118C;P106C;0
D102C;P118C;P106C;0
P111C;IND=Y;;0
P112C;P111C;0
P113C;P112C;0
D103C;P113C;P112C;0 Quote
but this option is banned by supervisor.

Is this supervisor going to allow a different METHOD of achieving the same goal?

Such as at my work place I can not bring in any media form of code because a virus etc can travel in on media. The systems I work with are isolated from the outside world in tightly controlled government networks and so for myself I got approval from my boss that while a USB stick, CD or DVD, or any other form of media with a program/script etc is on is strictly not allowed, they did allow me to manually type up the code in notepad and run it against QBasic which was on NT4 as well as batch scripting was allowed too because I myself typed everything that was to run on the server. And because I am not a rogue employee who would put anything bad in it, I was allowed to do this.

I'd highly advise you get written permission from supervisor before running any programs or SCRIPTS on their systems or you can be easily fired and then some. Once you have written CONFIRMATION that it is allowed, then MOVE forward and do just as was approved to protect yourself.  Hi ,

I run these a couple of batch file in our UAT first then it will roll out to production box.  Supervisor allow me to to do copy those batch file on the production.
810.

Solve : deleting space from result?

Answer»

I have tested a little script to take a number from TXT FILE and use it in batch, but problem is I get that litle square and script doesnt work.
How to get just a number so script will work. In file d:\number.txt is only a number for timeout DELAY

Code: [Select]set /p out=<d:\number.txt
TIMEOUT /T %out%
and this is what I getSimple answer: Just do not take a number from a file.
Put the number in the batch file itself.
Why is that HARD to do?

Quote from: Geek-9pm on April 06, 2019, 06:24:34 PM

Simple answer: Just do not take a number from a file.
Put the number in the batch file itself.
Why is that hard to do?

I know that.
Thing is I want to learn how to do itBlisk, how is the file number.txt made? What is that leading character before the '4'? It is not just a simple space; the timeout command doesn't mind spaces before the number.

Why is the number being got from a file?



You can get exactly this problem if number.txt has Unicode encoding. If you are creating the text in Notepad or some other editor, save with ANSI encoding.

If you doing it that way (with an editor), why?



Alternative:

Do 1 and 2 and maybe also 3

1. Save text with UTF-8 encoding.

2. Add this line at the top of your batch file underneath echo off

chcp 65001 >nul

3. As well as these things, also try a Unicode font for console such as Lucida Console.



I have created file with batch
copy /y nul d:\number.txt
echo 5 >> d:\number.txt

This also didn't help
echo off
chcp 65001 >nul
also if I save number.txt with UTF8 or ANSI, I get the same result.

What is than right way to do that?

So this is whole script now. and doesn't work
echo off
chcp 65001 >nul
echo 5 > d:\number.txt
set /p out=TIMEOUT /T %out%Try chcp 850 instead.

Did you change font to Lucida Console?
When I edit with notepad and add chcp 850 in batch it works
but when I generate number.txt with powershell it doesn't work
Is there more celan way to do this like ignore first charter?Not to *censored* in but: I suspect it sees the 5 as a stream number as in 2>nul. Try escaping the 5, echo ^5 > d:\number.txt

Just a thought. To avoid the stream number thing, you need a space after the number, before the > symbol.

See here, the first try leaves number.txt blank

C:\>echo 5> number.txt
ECHO is on.

C:\>type number.txt

C:\>dir number.txt

07/04/2019  18:20                 0 number.txt

C:\>echo 5 > number.txt

C:\>type number.txt
5

Quote from: Blisk
when I generate number.txt with powershell it doesn't work

Why Powershell?

Quote from: Blisk
copy /y nul d:\number.txt
echo 5 >> d:\number.txt

Why are you doing this??

This works every time for me....

C:\>echo 5 > d:\number.txt

C:\>set /p out=<d:\number.txt

C:\>timeout /T %out%

Waiting for 0 seconds, press a key to continue ...

C:\>chcp
Active code page: 850

Timeout waits correctly for 5 seconds, no CHCP change needed.





I am trying to learn some stuff which doesn't work.
Can you please try with my file, which doesn't work with me.

When I put in quotes I see there are tvo charters before number!
Somehov I should skip thatYour file says 148, and it is encoded as Unicode. How did you make it?

Anyhow, convert Unicode to ANSI with the TYPE command:

TYPE number.txt > number.txt

It works, I just tried it.




Yes this works now, thank you.
TYPE number.txt > number1.txt
set /p out=timeout /T %out%

I created number file with this powershell
1| % {Get-Random -Minimum 2 -Maximum 222 } | Out-File -FilePath D:\number.txt
811.

Solve : Each Command in Batch Suddenly Requires a Response - No longer runs on it's own?

Answer»

I'm having an unusual problem that's happening on only one computer where I have the same BATCH program running on 200 systems or more.  What is happening is that the DOS console is opening when the batch is initialized but I don't see the commands displayed like would they would normally.  The cursor is just sitting there.  I decided to HIT the Enter key and the first command in the batch executed.  Then, each time I hit the Enter key, another command executes until it runs through the whole batch file. 

Wait...  I have another program running on this computer (not mine), a C# program for video recording that writes what it's doing to the console.  The same thing is happening.  The console opens and the cursor just sits there.  I can start clicking the Enter key and the program will step through each command and display a new line in the console each time.   

This was happening intermittently and is now happening every time.

Other programs on this system that do not use the DOS console seem to run normally.

I've done a system restore and have asked all my friends but they quickly develop itchy scalps..   Does any one have an idea about what might be causing this behavior?   

Thanks for any clues!!   Check in the Command Prompt's Properties and MAKE sure QuickEdit mode is disabled. If so you'll want to change the default settings to disable it as well.Yes, I'd checked that.  It's not ENABLED...     Thank you.Check if Insert Mode is enabled also. If either one or both of QuickEdit Mode or Insert Mode is enabled, and you click within the console, it will pause the output.


I disabled the insert mode and the first time I ran the batch it ran all the way through.  The very next time the same behavior was back.  SIGH...  Thank you!

812.

Solve : Appending Files and Combining File names?

Answer»

Hi,

I'm new to DOS and I've written a batch file that combines the contents of multiple csv files, creating a new file (without duplicate headers). However, what I'm struggling to work out is how to rename the new file according to the filename/s of the original csvs.
For example, I have two csv files called:
YYMMDD TYPE 1_Part 1
YYMMDD Type 1_Part 2

What my batch file creates is a new file called "Combined data". I then manually rename the new file (in the format YYMMDD, followed by the type of data the file contains). So, the FINAL result is "YYMMDD Type 1".

I do this daily, but the dates and the type of data changes each time. So, essentially what I need to be able to do is to combine csvs which have the same DATE and 'Type' of data and produce a master csv named by the date of the file and the type of the data (without the '_Part x' on the END).

Any help would be much appreciated!

Thanks.To give you exact code we need a representative list of the filenames - as spaces and things will change the way it is handled.The spaces within the examples will remain the same. However, the character length of each part of text changes. I.e. 'Type' could be 'Model', '1' could be '15', Part could be 'Component' and '1' could be '100'.

E.g. one day it might be:
YYMMDD Model 15_Part 6
YYMMDD Model 15_Component 1

The desired outcome: YYMMDD Model 15

Another day it may be:
YYMMDD Design 12_Specification 3
YYMMDD Design 12_Specification 4

The desired outcome: YYMMDD Design 12

Again, what I'm essentially LOOKING to do is to rename the new file according to what is left of the underscore in the original files.

Thanks.If the part before the underscore is what you need then a simple for loop can extract it.

Code: [Select]for /f "delims=_" %%a in ("YYMMDD Model 15_Part 6") do echo "%%a"
Getting it inside your script will depend on how it is written.Was this enough information to help you?

813.

Solve : writing a dos command, would like advice please?

Answer»

Hello all,

 Im creating a Jenkins job, and wondering will the following work. I am a total novice at this stuff so please forgive me if the below sounds silly.

Basically I want to restart all nodes - unless they are called dugan, DIONE or example. I know i cant use != in dos but im having a job sercing for what I can use..

if %computername% != DUGAN,DIONE,EXAMPLE ( shutdown -r -f -t 10 -c "This computer is about to restart" )


There is no "or", you'll need to run three different commands.

The != is expressed as ' if not __ == __ 'I don't know if the jenkins command line Build Step allows multiple lines. I know it just get's written to a temporary file and run as a batch, so it probably does. (personally I usually just have it run a batch script that is part of the SVN repository so it can be updates along with the software it builds, but perhaps you are using jenkins for another purpose).

Code: [Select]if %computername%==DUGAN goto norestart
if %computername%==DIONE goto norestart
if %computername%==EXAMPLE goto norestart
shutdown -r -f -t 10 -c "this computer is about to restart"
:norestart

Code: [Select]echo off
set computerlist=DUGAN,DIONE,EXAMPLE
call set templist=%%computerlist:%computername%=%%
IF "%computerlist%"=="%templist%" shutdown -r -f -t 10 -c "This computer is about to restart"How many cats do we have to skin?  Here's another way:

Code: [Select]echo off
for %%a in (DUGAN DIONE EXAMPLE) do if /i "%computername%"=="%%a" goto :EOF
shutdown -r -f -t 10 -c "this computer is about to restart"
Guys that is just too cool. Thanks so much! Quote from: foxidrive on March 30, 2015, 05:03:54 PM

How many cats do we have to skin?  Here's another way:
I SAW a POOR DEAD kitty on the side of the road on my bike ride yesterday.  Aww.. poor kitty!

Code: [Select]
                    //Z/Z//                 
             |\    //Z/Z//   _,,,--,,_       
             /x`. //Z/Z//-'`'   ._  \-;;,_   
            |x4- //Z/Z//  ) )_   .;.(  `'-' 
           '---'//Z/Z//'(_/._)-'(_\_)       
               //Z/Z//                       
              //Z/Z//
 


Here's my kitty when he was younger. 

Code: [Select]        (`.
         ) )
        ( (
         \ \
          \ \
        .-'  `-.
       /        `.
      (      )    `-._ ,    _
       )   ,'         (.\--'(
       \  (         ) /      \
        \  \_(     / (    <6 (6
         \_)))\   (   `._  .:Y)__
          '''  \   `-._.'`---^_)))
                `-._ )))       ```
                     ```


In a futile attempt to remain on-topic...

Code: [Select]dir /b mouse.drv >"cat mouth.txt"
814.

Solve : help ? Can a file created with the Windows EDIT command have a file header?

Answer» HEY everyone can a file CREATED with the WINDOWS EDIT COMMAND have a file header? thanks in returnWhat sort of header did you WANT to create?file headerHomework request locked.
815.

Solve : looks like impossible for me may be nothing for you???

Answer»

I wanted  to allow people to view my files only once. A brillant guy suggested me to to this
1. Create a directory (folder) c:\test
2. Within that folder create a text file or copy in any file you desire - for this example use newtext.txt
3. Now use the file's properties to make newtext.txt hidden and read only
4. Now that the test file is present create a simple batch file called newtext.bat
5. newtext.bat only needs to contain these lines
notepad newtext.txt
attrib -h -r newtext.txt
del newtext.txt

works perfect for txt file but i DONT know how to do it for video (avi files). Computer is out of my medical field so simple solution like the ONE before will be appreciated. Thanking in advance.
P.S main problem is how to give command to open video file like notepad is opening there newtext.txt.

You need to use a player to play the video file.  This works using VLC to play the video file:

Code: [Select]"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" myvideo.mp4
attrib -h -r myvideo.mp4
del myvideo.mp4
This method will work on your machine, is that where they would be viewing the video from?  If they are using their own machine and accessing a shared folder on your machine then it will not work unless they have VLC installed in the same location as you do on your machine. Quote from: docdipesh on March 22, 2015, 08:03:48 AM

I wanted  to allow people to view my files only once.

5. newtext.bat only needs to contain these lines
notepad newtext.txt
attrib -h -r newtext.txt
del newtext.txt

works perfect for txt file

What stops them from saving the document again?

 Thank you strollin

but still does not work
you can see it
https://www.dropbox.com/s/u1hddm1liwr99h1/did%20not%20work.avi?dl=0It may help if the Original Poster can clarify some details.
1. Is in desirable to prevent users from seeing video again? Why?
2. Does  the video loose value over a period of time?
3. How many users are involved? Do they have used Windows based machines?
4. Is you service to be used over the world wide wide or just a local campus?
5. Have your tried  using media players to help control your presentations?
6. Are you familiar with he concept of a Podcast?
The link below is about Apple podcast.
Apple - iTunes - Podcasts - FAQs: For Podcast Makers
Just a suggestion. 


It looked like in the video you renamed the video file to myvideo.mp4.mp4 instead of myvideo.mp4.Strollin, thank you but it still does not work
https://www.dropbox.com/s/18g9fjyo0yb898j/still%20does%20not%20work.avi?dl=0Thank you geek,

1. I want my students to view my lecture note  only once .
2. yes video loses value over the period of time.
3. Students may be around 100 and all of them have only windows based or android approach.
4.Service  now is just over the campus locally . Hopefully in future in broader arena.
5.using media players to control presentation would be great but I have no idea on using it.
6. I am not familiar with the concept of a Podcast. I think it is only for IOS if i am not wrong. All of us dont have IOS based device.
Thanking you so much for the time.
Great day.Allow me to INTRODUCE thou to WordPress.
WordPress is one of a number of high level presentation platforms used in the Internet. In is platform  for Text, Audio, Video and an y mix. It is a structure that holds together lectures and documents that can be related or not. It can have categorizes, archives and feature pages.  Or it can be very plain.

It supports RSS feeds. I mentioned earlier, RSS is a type of podcast the uses e-mail to notify  clients of new materiel. It is server base and requires no specific OS. Users can have Windows, Mac or Android systems.

For campus use, your own computer could be the server. However, from my own experience, it is easier to just rent chap web space and use the automatic install features of the web site.

Most, almost all, web hosting cervices give  WordPress personal for no extra cost.
This is my WordPress Blog. As  you can see, it is rather plain.
http://geek9pm.com/wp_k9/

More  about using WordPress with RSS can be found at:
https://en.support.wordpress.com/feeds/

Here is a nice lecture series done with WordPress and video clips.
https://flippedemclassroom.wordpress.com/

http://WordPress.com gives commercial help for professionals.
http://WordPress.org is non-profit for personal users.
That is my best recommendation. 
Quote from: Geek-9pm on March 22, 2015, 09:40:38 PM
RSS is a type of podcast the uses e-mail to notify  clients of new materiel.

RSS doesn't use E-mail. Quote from: docdipesh on March 22, 2015, 08:44:12 PM
6. I am not familiar with the concept of a Podcast. I think it is only for IOS if i am not wrong. All of us dont have IOS based device.
Well my Zune must be using MAGIC these PAST 9 years to listen to podcasts.

I swear this question has been asked before on the forums. It is not really something you would do with a batch file. Quote from: BC_Programmer on March 23, 2015, 03:04:16 PM
RSS doesn't use E-mail.
I have been corrected. 
Notifications are sent to the  browser.
http://rss-tutorial.com/rss-how-does-it-work.htm
Quote
Summary
This is how RSS works:
    A website or a blog creates an RSS Feed. Many Blog services automatically create RSS Feeds. For Websites, RSS Feeds can be created manually or with software.
    The RSS Feed that is created is an XML file that lives on an Internet server. There are now hundreds of thousands of RSS Feeds sitting on Internet servers waiting patiently for an RSS Reader to subscribe to them.
    The RSS Feed Reader reads the RSS Feed file and displays it. The RSS Reader displays only new items from the RSS Feed.
RSS is definitely useful though. I'm not sure it would do exactly what the OP wants. However if they want to tightly control their content they would be better served to do so via a website. Even just preventing any single IP from viewing the video more than once would likely be better than trying to rely on some obfuscation trickery using hidden files and batch scripts. Just copying the folder it is in would workaround the trickery in this case.

Realistically this takes us back to Geek-9pm's question-

Quote
1. Is in desirable to prevent users from seeing video again? Why?
The first part was answered- effectively a yes- but the second part- why- was never addressed. What is the purpose of preventing this content from being viewed multiple times? "I don't want them to" isn't really enough.Thank you all but I was looking forward to strollin
816.

Solve : Batch script syntax help??

Answer»

I am currently trying to make a game in windows batch script, just a LITTLE TEXT based thing for fun. At one part of the game, the player has to be above a certain level to enter an area, and if they are below they are given a message and redirected. Problem is, it keeps telling me there is a syntax error even though I cant TELL what it is. Here, I'll let you look at the code and see if I can get any suggestions on how to improve this.
Code: [Select]:explore-east
cls
echo You turn to your right and see a large stone
echo structure that has been overgrown with thick
echo moss and grass and vines. It appears to be
echo the entrance to some kind of underground
echo catacombs.
pause
if '%lvl%' == '4'(
cls
echo A strong urge to explore inside the stone
echo structure fills you, but you know that you
echo arent strong enough to protect yourself from
echo whatever may be inside...
pause
goto explore
)
if '%lvl%' == '5' (
cls
echo You feel drawn to explore the inside of the
echo catacombs...
pause
cls
echo You MOVE some of the vines out of the way
echo and see a large door behind them. It has
echo symbols inscribed all over it. You push on it
echo but it doesnt budge.
pause
cls
echo You decide to head out and get some more
echo experience before you try to head into the
echo area again.
pause
goto explore
)
if '%lvl%' == '5' | '6' | '7' | '8' | '9' | '10' (
echo You enter the catacombs with no problem...
pause
goto Cata1
)
So there it is... If you can help, please give suggestions. Thanks!'|' is not a logical operator in batch script.
Code: [Select]set "yes="
for /L %%a in (5,1,10) do if %lvl% EQU %%a set yes=1
if not defined yes echo Go away or I SHALL taunt you for a second time! & pause & goto :start
echo Welcome Green Wizard!

817.

Solve : Anyone help? i was wondering could there be valuable data in unallocated space??

Answer»

is there any VALUABLE data in UNALLOCATED space? and how do I examine unallocated spaceNo NEED to double-post...

Topic CLOSED.

818.

Solve : can anyone solve this??

Answer»

If you decompressed a single PKZIP archived file that had 9 separate files CONTAINED in the archive how would you examine the file slack for each of the 9 files 


This is  where the sum is not the AGGREGATE of the parts. A ZIP algorithm can produce different results with even  similar files.
The more broad discussion is called 'Data compression.'
http://en.wikipedia.org/wiki/Data_compression
Quote

The design of data compression schemes involves trade-offs AMONG various factors, including the degree of compression, the amount of distortion introduced (when using lossy data compression), and the COMPUTATIONAL resources required to compress and uncompress the data.[5]
819.

Solve : Creating Folders from List of Files?

Answer»

Hello.

I have a bunch of files (in the hundreds) & I wish to put each in their own folder.

Code: [Select]X:\birthday2007.avi becomes Code: [Select]X:\birthday2007\birthday2007.avi
Does ANYBODY know how to do this? As I said, I have several hundred files. So I would need it to be done all at once.

Thanks. I actually just found a PROGRAM called Files 2 Folder. It seems to do the trick nicely.

Thanks.For any future EXPLORERS...

This is untested: try it on a folder of test files first - don't run the batch file from x:\ as well.

Code: [Select]echo off
for %%a in (x:\*.avi) do (md "%%~dpna" 2>nul & move "%%a" "%%~dpna")
pause

And to do it recursively:

Code: [Select]echo off
for /F "delims=" %%a in (' dir /b /s /a-d "x:\*.avi" ') do (md "%%~dpna" 2>nul & move "%%a" "%%~dpna")
pause

820.

Solve : help ?Name three normal file extensions for graphical image files and?

Answer»

Name three normal file EXTENSIONS for graphical image FILES and What are the file headers for these files?


Sorry, We don't HELP with homework.

821.

Solve : Run a batch file to produce results in cmd?

Answer»

i am new to MS dos and SQL and i was wondering if you can help me

I am TRYING to run a batch file and produce some results in ms dos

i dont know what command i need to use

i have created the bat file and a text file and i want to run the batch (bat) file to run that command in the txt file

and produce the results in CMD command prompt. can you help me with this one please?
Are you trying to pass SQL instructions from batch to SQL at command line?

I have been successful in doing this for batch files that backup and RESTORE the database from dump files. What are you trying to do with your instructions that are in the text file? You may not need the text file to begin with and might be able to contain it all within the batch file for the batched SQL instructions.

The only thing dangerous about use of batch for ACCOMPLISHING this is that the root permissions for the database are in PLAIN sight in the batch file, so if your the only one USING it your all set, but if you dont want others seeing the admin privilege credentials of your database then its too easy for someone to open up the batch file in an editor and see your root password etc.

822.

Solve : Auto execute the Batch file?

Answer» HI All,

I am creating a BATCH FILE on server by program running on client (Use of .bat file is to set environments).

I want to execute the .bat file automaticaly once it is GET created on server, is there any command I need to add in batch file while creating it through programm or I need to run new programm on server to execute the .bat file on server. if YES , please help me with the same?

Please assist.

Please let me know if you want more details.

Thanks in advance.

Quote from: hopes on May 14, 2014, 09:20:44 PM
I want to execute the .bat file automaticaly once it is get created on server

Please let me know if you want more details.

Yes please.
823.

Solve : Copy specific list of folders with files from one location to anather?

Answer» HELLO all,

I need help in copying a list of directories / folders from one location to  another  (let say from D: to E: or D:\ToCopy to e:\Copied).


* I have list of folders.
* I need the folders copied to be in same structure as in source.


look into xcopy or robocopy.  If you format your list on lines in a text file, you will also want to fermiliarize yourself with 'for /f'.  You will use this to loop through each LINE of your file.

Code: (psudo-code) [Select]for /f "DELIMS=" %%A in (list.txt) do xcopy "D:\ToCopy\%%A" "E:\Copied\%%A"

%%A WOULD be %A if you are running outside of a BATCH file.
824.

Solve : Use of for and findstr to copy lines where text string is present?

Answer»

I coded this in a bat file.
for /F "delims=" %%F in ('findstr " Form identifier " D:\EFILING\INPROCESS\sarwklymsgs.log') do copy "%%F" >> D:\EFILING\LOGS\formsids.log
 
Thought it would copy line that contained the findstr text to the end of a text file.
 
Seems to work but all I GET in output text file for each line that contains the findstr text is a line of text saying
The system cannot FIND the file specified.
 
The reason I say it is working is I get one line saying that for each line containing the findstr text.
So findstr is working but the copy has issues.
 
Can someone tell me what is wrong or a better way to code what I am trying to do.
Thank you for your TIME in helping me.
do echo "%%F" >> D:\EFILING\LOGS\formsids.logThis may be enough for what you need to do - the double quotes allow long PATH and filenames with SPACES also.


Code: [Select]findstr " Form identifier " "D:\EFILING\INPROCESS\sarwklymsgs.log" >> "D:\EFILING\LOGS\formsids.log" Quote from: foxidrive on April 22, 2014, 10:39:56 AM

This may be enough for what you need to do - the double quotes allow long path and filenames with spaces also.


Code: [Select]findstr " Form identifier " "D:\EFILING\INPROCESS\sarwklymsgs.log" >> "D:\EFILING\LOGS\formsids.log"
That should run quicker as well.
825.

Solve : Report of file names?

Answer»

I'm looking for the command to list files in a file structure with sub folders that will not show duplicate names.
What I have USED in the past is:  dir *.* /s ---but this will give me all dups.  How about showing an example of what you are trying to describe.Here's a sample attachment.

[recovering disk space, attachment deleted by admin]You know it is possible to COPY and paste from the CMD prompt.
Code: [Select]C:\Batch>dir /a-d /b /s *.txt
C:\Batch\temp\2.txt
C:\Batch\temp\3.txt
C:\Batch\temp\4.txt
C:\Batch\temp2\2.txt
C:\Batch\temp2\3.txt Quote from: st8ofid on April 22, 2014, 12:20:07 PM

I'm looking for the command to list files in a file structure with sub folders that will not show duplicate names.
What I have used in the past is:  dir *.* /s ---but this will give me all dups.

There is no single command to remove the duplicates.  You'll have to write code to do that.I THINK this would be very difficult to do without using temporary files to store the list of files in.  You could basically have to keep checking if the file NAME is found in the temporary file and if it isn't then add it to the temporary file. Quote from: Squashman on April 22, 2014, 11:42:40 PM
You basically have to keep checking if the file name is found in the temporary file and if it isn't then add it to the temporary file.

That's an effective method, though will be slower for thousands of files due to the file reading.  The OP will have to say if speed is a necessary FACTOR.
826.

Solve : Assigning value to variable from another variable?

Answer»

Hi, am trying to assign the value to the variable by passing it from another variable. its not WORKING. Below is what am trying to do

set vendor5=3
set x=5
set VENDOR=vendor%x%
echo %vendor%

The above script displaying "vendor5". i WANT to display 3 as i assigned 3 for vendor5 in first line.
please let me know what i am missing  . thanks in advance  ...
Without USING delayed expansion
Code: [Select]set vendor5=3
set x=5
call set vendor=%%vendor%x%%%
echo %vendor%Using Delayed Expansion
Code: [Select]setlocal enabledelayedexpansion
set vendor5=3
set x=5
set vendor=!vendor%x%!
echo %vendor%thank you Squashman

827.

Solve : Archive files that haven't been accessed in 18 months?

Answer»

Hello, I have to create a script that will :

1. archive files that are older than a period on my network drive.


2. make an exact duplicate folder structure INSIDE the  new Archive fiolder . 
 
3. Move all files not accessed in 18 MONTHS into their respective mirror folder in the new “archive" directory

Any suggestions? THANKS!
Look at Robocopy.  It has an option for Last Accessed date.  Thanks! Thank you
Double Thanx...Cool !    Make that a Tripple Thanks   because I didnt know that Robocopy had that feature, and I know of an application for it for an archive that we have that is a mix of extremely old and newer data, and it would be nice to move data that is really old off to a read only location since after a period of time there is no need for alterations to be made to certain files etc.

828.

Solve : DOS Exact String Matching?

Answer»

I have a FILE containing lines:
FWDIDF01        JGPS3GRP
......

I want to do an exact string match for the word FWDIDF01XX, but it is returning the line SHOWN above.  Here is my partial CODE:

Code: [Select]set IDF=FWDIDF01XX
FOR /F "tokens=*" %%a IN ('"findstr /b /i /c:"^%IDF%" %IDF_MAP%"') DO SET IDF_LINE="%%a"

Thanks in advance.....This solves the issue as described:

Code: [Select]ECHO off
set IDF_MAP=file.txt
 >%idf_map% echo FWDIDF01        JGPS3GRP
>>%idf_map% echo FWDIDF01XX        JGPS3GRP

set IDF=FWDIDF01XX
FOR /F "delims=" %%a IN ('findstr /i "^%IDF%" "%IDF_MAP%"') DO SET IDF_LINE="%%a"
pause

829.

Solve : Launch a program by Batch file?

Answer»

Dear all,

I am trying to AUTO some tasks in my JOB. The last step is convert a file to other format. Please advice me how can i launch a program open a file then save as to the other format and close a program by Batch file.

Thanks & regard,
PH.It depends on the filetype and how you are converting it, but there may be command LINE programs to do it for you.

A way to DRIVE a GUI program by batch file is by using AutoIt or VBS Sendkeys.

830.

Solve : findstr to validate successful run and copy selected lines to archive?

Answer»

At the bottom of this post is my input file (sarweekly.log) to findstr.
It is a log of output messages from a batch program execution.
Just before the file (sarweekly.log) is a listing of my BAT file (xxxxxx).
 
I have two findstr in that seem to be working, however, using ECHO on
to debug I noticed the the 1st findstr starts at the beginning of the input.
When it discovers the string it drops through the IF and EXECUTES the
2nd findstr. The 2nd findstr I thought would start over at the beginning
of the input. However, it starts at the next line of the input.  OK......
It works only because the 2nd findstr is looking for what is on the very
next line in the file.
Not having any DOS Command language exerience before being assigned
this work my mind see a problem I need experience and knowledge of findstr
or some other DOS Command to fix.

I was expecting each findstr to start at the beginning. I am sure you understand that.
Once the 2nd findstr found its string
I planned to issue multiple other findstr to search for strings:
 "Form identifier " and 'E-File"
as findstr discovered test I was going to do an IF
to  copy that line with the >> to an archive log
 
Now my mind is not even sure if this design is possible.
 
I hope all you experiences people have pitty but I do
expect you will get a laugh out of my situation. It is
good to laugh, even at my expense, but especially on Fridays.
 
Thank you to anyone who is investing their time looking and responding to my post.

HERE IS THE DOCUMENTATION
BEGINNING OF DOS Command BAT File
set SCRIPTLOG=D:\EFILING\INPROCESS\archives
echo . >> %SCRIPTLOG%
echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = =" >> %SCRIPTLOG%
echo . >> %SCRIPTLOG%
echo . - BEGIN. >> %SCRIPTLOG%
echo Start PROCESS COMPLETE TEST %date time% >> %SCRIPTLOG%
rem ========= Did program create a file =====================
findstr "E-file RCM_SAR_Form_" D:\EFILING\INPROCESS\sarwklymsgs.log
If %errorlevel% neq 0 THEN GoTo NoSAR
rem ==============================================
 
rem ======= YES THEN did program complete successfully ==========
findstr "Process Completed." D:\EFILING\INPROCESS\sarwklymsgs.log
if %errorlevel% neq 0 GoTo BadEnd
rem ==============================================
rem ----- HERE IS WHERE I FOUND OUT findstr was not starting over/
rem ----- at the beginning of file everytime.  It what prompted me to post
rem ----- IF THERE IS A WAY FOR FORCE A findstr to start at the beginning
rem ----- of a file I hope someone knows. Maybe my code could work Ha Ha!
rem ----- Another good laugh for you experienced people on a Friday
rem ===== Loop through log file and archive selected lines =-==========
:MvArcf
findstr " Form identifier " D:\EFILING\INPROCESS\sarwklymsgs.log
if %errorlevel% equ 0
copy /y  current line from findstr match >> D:\EFILING\LOGS\sarformsids.log
:MvArce
findstr "E-file RCM_SAR_Form_" D:\EFILING\INPROCESS\sarwklymsgs.log
if %errorlevel% equ 0
copy /y  current line from findstr match >> D:\EFILING\LOGS\sarfileids.log
GoTo END
rem ================================================

rem ================================================
:BadEnd
rem Program ended with errors
set errorlevel=1
GoTo END
rem ================================================
 
rem =================================================
:NoSAR
rem No Cases in Ready for Report, so NO SAR Form file is written
rem Force completion of entire following automation
rem =============================================================
set errorlevel=2
rem =============================================================
:END
echo STOP PROCESS COMPLETE TEST  %date% %time% >> %SCRIPTLOG%
echo . - END. >> %SCRIPTLOG%
END OF DOS Command BAT File
BEGINNING OF SARWKLYMSGS.LOG  (Input File). - BEGIN. 
Start utility THU 01/23/2014 15:08:38.37 
Thu Jan 23 15:08:39 CST 2014 - Connecting to the RCM server. [https://dev-ercm-ws-dns.com:10702/RCM]
  Form identifier 0000000909 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001005 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001101 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001119 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001009 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001121 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001111 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001401 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001403 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
E-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST created from 9 form(s), its size is 102KB.
Process completed.
Stop utility Thu 01/23/2014 15:08:47.54
. - END.
END OF SARWKLYMSGS.LOG  (Input File)There will have been errors on the console - THEN is not used in batch code.

If %errorlevel% neq 0 THEN GoTo NoSAR


When you post code, use code tags around it - highlight the code and click on the # icon above in the editor.


This syntax is incorrect, and a correct construction would be on the same line too.

Code: [Select]if %errorlevel% equ 0
copy /y  current line from findstr match >> D:\EFILING\LOGS\sarformsids.log Quote from: foxidrive on April 18, 2014, 10:38:46 AM

When you post code, use code tags around it - highlight the code and click on the # icon above in the editor.
Or you can actually type out the BB CODE tags.
[­code]Batch code goes here[­/code]How do any of your FINDSTR commands make you think it is not searching the file from the beginning of the file?

Every time you execute the FINDSTR command it is searching the file from the beginning and looking for your search parameter. Quote from: tommyb on April 18, 2014, 10:26:57 AM
2nd findstr. The 2nd findstr I thought would start over at the beginning
of the input. However, it starts at the next line of the input.

How do you know this?
Salmon Trout,
I say it because I turn set echo on.
The first findstr listed every line it searched.
The second findstr only listed the on line (which is the next line in the log file).
I thought the 2nd findstr was telling me it started where the 1st findstr ended.
 
So please educate me.Golly gee. Considering your first FINDSTR command basically finds most of the lines in your file I guess I can see how that would be confusing. It is going to output what you are searching for. What did you expect FINDSTR to do? Quote from: tommyb on April 18, 2014, 02:27:56 PM
The first findstr listed every line it searched.
The second findstr only listed the on line (which is the next line in the log file).

findstr searches the entire file for the text you provide. 
It can show various things depending on which switches you use, such as

The text you provide
Lines that do not contain the text you provide
Lines of text with the line number at the beginning
etc


831.

Solve : Batch File to get Strings?

Answer»

Hello All
I am new here and to dos too.

I have a big text file like this:

A1111-001,C:\text\A1111-001.jpg,Y,,,,
A1111-002,C:\text\A1111-002.jpg,,,,
A1111-003,C:\text\A1111-003.jpg,,,,,
A1111-004,C:\text\A1111-004.jpg,Y,,,
A1111-005,C:\text\A1111-005.jpg,,,,

I need a batch file to do get string of the FIRST line with "Y,,," and the last line without that to a new text file.

Exsample like this:
"A1111-001","A1111-003"
"A1111-004","A1111-005"

Thank you for the help! Is this a CSV file? If so, why not use a spreadsheet to parse it?
Using a BAT file to parse a CSV is so retro.
Like a horse and carriage rental.
Quote from: mtank on April 18, 2014, 07:47:12 PM


A1111-001,C:\text\A1111-001.jpg,Y,,,,
A1111-002,C:\text\A1111-002.jpg,,,,
A1111-003,C:\text\A1111-003.jpg,,,,,
A1111-004,C:\text\A1111-004.jpg,Y,,,
A1111-005,C:\text\A1111-005.jpg,,,,

I need a batch file to do get string of the first line with "Y,,," and the last line without that to a new text file.

Exsample like this:
"A1111-001","A1111-003"
"A1111-004","A1111-005"

Thank you for the help!
Your example contradicts your description.It's a text file not csv... Quote from: Squashman on April 18, 2014, 08:40:31 PM
Your example contradicts your description.
He wants the one before the Y and the Y for each Y.


EDIT:
Try this, it will write to new.txt
Code: [Select]echo off
if exist new.txt del new.txt
setlocal EnableDelayedExpansion
for /f "tokens=1-3 delims=," %%A in (test.txt) do (
if "%%C"=="Y" (
if not "!working!"=="" echo "!working!","!a!" >>new.txt
set working=%%A
)
set a=%%A
)
echo "!working!","!a!" >>new.txt
pause >nul

EDIT 2: Just saw you wanted it in a file, so I edited my code to accommodate.That works fine, Lemonilla Quote from: mtank on April 18, 2014, 08:42:53 PM
It's a text file not csv...

A CSV file is a text file with Comma SEPARATED Values, with lines like this: v1, v2, v3, v4

This is what you posted as an example:

Quote from: mtank
I have a big text file like this:

A1111-001,C:\text\A1111-001.jpg,Y,,,,
A1111-002,C:\text\A1111-002.jpg,,,,
A1111-003,C:\text\A1111-003.jpg,,,,,
A1111-004,C:\text\A1111-004.jpg,Y,,,
A1111-005,C:\text\A1111-005.jpg,,,,

Those are comma separated values. That is a csv file, although it may not have a ".csv" extension.
Quote from: Geek-9pm on April 18, 2014, 08:04:03 PM
Is this a CSV file? If so, why not use a spreadsheet to parse it?

Because you would have to click around in the spreadsheet program to get anything done (unless you were so good at scripting you wouldn't be asking here) Powershell has very good csv support, and that is not quite "retro" yet.

The last echo doesn't need delayed expansion. You are already out of the code block. Quote from: Squashman on April 19, 2014, 06:35:51 AM
The last echo doesn't need delayed expansion. You are already out of the code block.
True, ' echo "%working%","%a%" ' would work too, though I don't think there is a difference in performance between the two.Lemonilla you save my life. This code did exactly what i need, THANK YOU! Thanks all the help guys! Quote from: mtank on April 19, 2014, 09:27:56 AM
Lemonilla you save my life. This code did exactly what i need, THANK YOU! Thanks all the help guys!
Thank you for giving me something to do.  I've exhausted all my ideas for scripts awhile AGO.  Its good to have a new challenge.
832.

Solve : FOR COMMAND IN DOS BAT FILE?

Answer»

I am trying to use MULTIPLE FOR Commands to parse text in 2 text file. Keep all the variables active. Then do a move USING the variables to change the name by combining variables from both parse text file variables.
HERE IS A SAMPLE - I thought would work but NO.  It could not be that easy for a beginner.
for /f "tokens=1-9 delims=_-: " %%A in (d:\efiling\inprocess\sarfilename.txt) do
for /f "tokens=1-3 delims=_.-: " %%L in (d:\efiling\inprocess\ackfilename.txt) do (
move /y d:\efiling\acknowledgements\%%L_%%M.%%N d:\efiling\acknowledgements\%%A_%%B_%%C_%%D-%%E-%%F %%G-%%H_%%I.%%N"
 
Thank you for helping understand the proper syntax.
The rookie.I've run into issues with batch and Nested FOR loops myself in the past. Here is a related article. http://stackoverflow.com/questions/14689109/variable-not-setting-in-nested-for-loop-windows-batch

Also some typos...

move /y d:\efiling\acknowledgements\%%L_%%M.%%N d:\efiling\acknowledgements\%%A_%%B_%%C_%%D-%%E-%%F %%G-%%H_%%I.%%N"

Maybe should be ...

Quote

move /y "d:\efiling\acknowledgements\%%L_%%M.%%N" "d:\efiling\acknowledgements\%%A_%%B_%%C_%%D-%%E-%%F %%G-%%H_%%I.%%N" )

since its contained within the nested FOR by the start of the ( from....

Quote
for /f "tokens=1-3 delims=_.-: " %%L in (d:\efiling\inprocess\ackfilename.txt) do (


Note: This is untested... also be sure your using enable delayed expansion at the start of your batch. Someone else here might pick up on something else that is a problem as well with this. But unable to test this on work computer = uncertainty with what I gave you for corrections.

I think what you really want is a one to one relationship with the two files.  I am just assuming this.  Otherwise if there is 9 files in your SAR File Name and 9 in your Ack File name you are really only getting 9 output files that are exactly the same as the last file name listed in your Ack File.

Really need to see what is in your SAR and ACK Files.HERE IS A SAMPLE EXECUTION WITH ECHO ON.           Maybe someone can see why I am getting this error.
I parse two text files that each a a unique filename in them. Set each parsed field value to a unique local variable.
Build a move to rename a file with parts of the two text files variable values now set to local variable.

The problem come on the complex filename (It uses _ - and blank) in it filename. It parses OK.
However, when I build the new filename I get added spaces, a missing hour field right after where a REAL space exists
in the complex filename. 

For a rookie my eyes hurt and my brain know it has not enough experience.

ANYONE
I thank you in advance for the education on command language processing and solving this problem.

-----------------------THE EXAMPLE FOLLOWS --------------------------------------------------

D:\EFILING\BIN>rem -- begin archive function --

D:\EFILING\BIN>dir /b d:\efiling\acknowledgements\FINCEN*.*  1>d:\efiling\inprocess\ackfilename.txt

D:\EFILING\BIN>for /F "tokens=1-3 delims=_.-: " %L in (d:\efiling\inprocess\ackfilename.txt) do (copy /y "d:\efiling\acknowledgements\%L_%M.%N" d:\efiling\archive\%L_%M.%N )

D:\EFILING\BIN>(copy /y "d:\efiling\acknowledgements\FINCEN_20140130.ACKED" d:\efiling\archive\FINCEN_20140130.ACKED )
        1 file(s) copied.

D:\EFILING\BIN>rem -- end archive function --

D:\EFILING\BIN>rem -- begin rename function --

D:\EFILING\BIN>for /F "tokens=1-3 delims=_." %L in (d:\efiling\inprocess\ackfilename.txt) do (
set FI=%L
 set DT=%M
 set TY=%N
)

D:\EFILING\BIN>(
set FI=FINCEN
 set DT=20140130
 set TY=ACKED
)

D:\EFILING\BIN>for /F "tokens=1-9 delims=_-: " %A in (d:\efiling\inprocess\sarfilename.txt) do (
set RCM=%A
 set SAR=%B
 set FRM=%C
 set MO=%D
 set DA=%E
 set YR=%F
 set HH=%G
 set MN=%H
 set ID=%I
)

D:\EFILING\BIN>(
set RCM=RCM
 set SAR=SAR
 set FRM=Form
 set MO=01
 set DA=23
 set YR=2014
 set HH=15
 set MN=08
 set ID=TBSATEST
)

D:\EFILING\BIN>move /y "d:\efiling\acknowledgements\FINCEN_20140130.ACKED" "d:\efiling\acknowledgements\RCM _SAR _Form _01 -23 -2014  -08  _TBSATEST.ACKED"
        1 file(s) moved.

D:\EFILING\BIN>rem -- end rename function --
*
*
*
Quote from: tommyb on April 17, 2014, 11:15:36 AM
For a rookie my eyes hurt and my brain know it has not enough experience.

It might help to know that to assist the people reading here, it helps to give accurate and full information about what you want to do and also provide the text files (which you can attach to a post).

Posting code that doesn't work is seldom helpful, when you don't also include the text being parsed and a full description of the task.Thank you foxidrive for your post.  I apologize for not realizing the need for all information.
Here are the filename I am parsing and the one line enter they each contain.
ackfilename.txt contents:
FINCEN_20140130.ACKED
sarfilename.txt contents:
RCM_SAR_Form_01-23-2014 15-08_TBSATEST

I goal is a move command combining the parsed values of each filename.
IF I KNOW THE FILENAMES THE FIX POSITION CODE WOULD BE:
move /y "FINCEN_20140130.ACKED" "RCM_SAR_Form_01-23-2014 15-08_TBSATEST"
 
Hope this provides reviewer with enough info. I do appreciate anyones opinion.
Thank you,
The DOS Rookie
Test this: it will simply show you the command on the screen - so remove the echo keyword to make it work.


Code: [Select]echo off
for /f "usebackq delims=" %%a in ("ackfilename.txt") do (
   for /f "usebackq delims=" %%b in ("sarfilename.txt") do (
      echo move /y "%%a" "%%b"
   )
)
pause
foxidrive, Thank you for that example. It was almost prefect. One little MOD and all is well.
Now on to testing my nesting of FIND or FINDSTR.
When I get frustrated again, as I expect will HAPPEN, I post.
But your experience and advice was a big help.
A BIG THANK YOU
From,
TommyBTalk about over complicating the initial problem.Squashman, What can you expect from a DOS Command language rookie. I am sorry you are  .
Wait until my next post.
833.

Solve : Batch for comparing values?

Answer»

Hi people. I need some help if someone can help me?
I have a txt log file from where I need to take a value and compare it with value from another txt file.
If value from another file is lower than value from first file than it must take an action.

Belov is a log from first txt file. I need to take out value from last line (avg):140.5Kh/s. In second txt file I write my value, like 100

Code: [Select] [2014-04-17 07:13:00] Accepted 5d447098 Diff 65/32 GPU 0                     
(5s):140.8K (avg):140.4Kh/s | A:32  R:0  HW:0  U:4.9/m  WU:156.9/m          (5s):140.8K (avg):140.4Kh/s | A:32  R:0  HW:0  U:4.8/m  WU:154.9/m           [2014-04-17 07:13:12] Accepted e7790f5c Diff 42/32 GPU 0                     
(5s):140.9K (avg):140.4Kh/s | A:33  R:0  HW:0  U:4.9/m  WU:157.7/m           [2014-04-17 07:13:15] Accepted 79988ae3 Diff 45/32 GPU 0                     
 [2014-04-17 07:13:16] Accepted d68372c1 Diff 74/32 GPU 0                     
(5s):140.9K (avg):140.5Kh/s | A:35  R:0  HW:0  U:5.2/m  WU:165.2/m         
(5s):140.9K (avg):140.5Kh/s | A:35  R:0  HW:0  U:5.1/m  WU:163.2/m          (5s):141.0K (avg):140.5Kh/s | A:35  R:0  HW:0  U:5.0/m  WU:161.3/m      Please attach a sample of your text file to a post, and DESCRIBE the filenames and what you need to do. 

The file data you PASTED in looks like it was corrupted.No it is not corrupted it is that way.


[recovering disk space, attachment deleted by admin]Are you sure? The mylog.txt is nothing like what you posted above.

If the figure following (avg) on the last line is what you need to compare, does it have to take the figures after the decimal point into account
or can it just compare the figures to the left of the decimal point?Yes I am soure that's the way it is
yes the figure after avg and it is not important which from last line it can be first or last.
And decimal points also are not important, just the whole number, from (avg):140.5Kh/s just a 140.
and in next file I will write 100 and if value after avg drops under 100 it will run some applicationcompare.txt should only contain a whole number
and the code will compare the avg figure in the last line of myfile.log with that number.

If the avg figure is less than the number then it will launch the PROGRAM listed.

Code: [Select]echo off
for /f "usebackq tokens=5  delims=:. " %%a in ("myfile.log") do set avg=%%a
echo avg="%avg%"
for /f "usebackq delims=" %%a in ("compare.txt") do if %avg% LSS %%a start "" "c:\program files\folder\myapp.exe"
pause
wau, this is so great it works
it is so simple but so complicated for me because I don 't know how to program.

Need just one more thing here if you are willing to help.

one more file where it is written how many time is runned myapp.exe, so everytime is runned it add 1 more if it is runned 1 time than in file is 1 if it is runned 3 times than it is 3 in that file, etc.

If batch file found out that it is runned for example more than 3 times it runs nextmyapp.exe and not myapp.exe and delete that counter file to zero.

If nextmyapp.exe is runned more than 3 times it stops to run the whole batch file so it won't happend a loop.

Quote from: Blisk on April 17, 2014, 03:03:22 AM

Need just one more thing here if you are willing to help.

I'm glad it helps.

When you ask for free help then you should write the whole task out with as much information that you can provide.

Asking for more changes once you get some tested code that works means even more work for the people helping you,
as they have to change the code that is already written and tested, and then test it again.

sorry about that you are right.
But that crossed my mind after I tested this. I didn't think about the whole process. Sorry againCan I still hope for help for that?This runs myapp 3 times, then runs mynextapp 3 times, then relaunches the batch file.

It only launches the apps if the average figure is less than the figure in compare.txt


Code: [Select]echo off
:: initialise the app counter files
if not exist "app1.txt" type nul >"app1.txt"
if not exist "app2.txt" type nul >"app2.txt"
if not exist "compare.txt" echo compare.txt is missing&pause&goto :EOF


:: If app1 has run 3 times then set the variable to app2 (otherwise set it to app1)
find /c "run" <"app1.txt" | find "3" >nul && (set app=app2) || (set app=app1)

:: If app2 has run 3 times then remove the counter files and relaunch the batch file
find /c "run" <"app2.txt" | find "3" >nul && (
   del "app1.txt" "app2.txt"
   %0
)

:: get the average figure from the last line in the file
for /f "usebackq tokens=5  delims=:. " %%a in ("myfile.log") do set avg=%%a
echo avg="%avg%"

:: get the compare number from the file and if avg is lower,
:: increment the counter file and run the app - using the app as defined above.
for /f "usebackq delims=" %%a in ("compare.txt") do if %avg% LSS %%a (
   if "%app%"=="app1" >>"app1.txt" echo run& start "" "c:\program files\folder\myapp.exe"
   if "%app%"=="app2" >>"app2.txt" echo run& start "" "c:\program files\folder\mynextapp.exe"
)
Thank you, you really made my day today, finally works all like I wanted.
Thank you If I can ask for more help here not to opening new topic?

I need one mora batch file for copying the newest file from folder
login to folder test\new
is it possible to have just a PART of path in batch not full path?
because I need to make bach fule for each user if it is not possible just part of path.
because full path is
c:\users\mike\software\screener\database\database2014\office\login

c:\users\mike\software\screener\database\database2014\office\test\newOpen a new topic for different questions.  They are free.

If this is run from the login folder then it will copy the newest file to the new folder SHOWN in your path.

Code: [Select]echo off
for /f "delims=" %%a in ('dir /b /od /a-d') do set "lastest_file=%%a"
copy "%lastest_file%" "..\test\new"
Didn't know about opening new topic because on some forums doesn't like to have every question new topic.

This batch not working it copy only itself to folder test\new
that also is not ok because there must be only one file

I runned this from \login folder where batch file should be
834.

Solve : batch for run all bat files?

Answer»

I have to try to run all batch files under folder subfolder wih one batch
I tried this bot not working
for /d /r %%i in (D:\myfloder\Drivers\conf\) do if exist "%%i\copylog.bat" start /wait call "%%i\copylog.bat"

bat file which must be runed is under D:\myfloder\Drivers\conf\MIKE\archive\bat

I tried to run batch files from other topicThis will launch each batch file in that folder:

Code: [Select]echo off
cd /d "D:\myfloder\Drivers\conf"
for %%a in (*.bat) do call "%%a"
pause
Just make sure foxidrive's file isn't in D:\myflder\Drivers\conf or you will enter an infinite loop. Here is a workaround.

Code: [Select]echo off
cd /d "D:\myfloder\Drivers\conf"
for /f "delims=" %%A in ('dir /b *.bat ^| find /v "%~nx0"') do echo call "%%A"
echo.
echo All done.
pause

Proof of concept:
Code: (code) [Select]echo off

echo Before:
echo %time%
for %%a in (*.bat) do echo call "%%a"
echo %time%
echo.

echo After:
echo %time%
for /f "delims=" %%A in ('dir /b *.bat ^| find /v "%~nx0"') do echo call "%%A"
echo %time%
echo.

echo All done.
pause>nul
Code: (output) [Select]T:\>findAllBat
Before:
 9:43:12.28
call "colorsd.bat"
call "colorText.bat"
call "countLines.bat"
call "findAllBat.bat"
call "note.bat"
call "realtime.bat"
call "snakeV1.bat"
call "spaces.bat"
call "test.bat"
 9:43:12.29

After:
 9:43:12.30
call "colorsd.bat"
call "colorText.bat"
call "countLines.bat"
call "note.bat"
call "realtime.bat"
call "snakeV1.bat"
call "spaces.bat"
call "test.bat"
 9:43:12.37

All done.
lemonilla thanks but not working.
file not found Quote from: foxidrive on April 25, 2014, 03:47:15 AM

This will launch each batch file in that folder:

Code: [Select]echo off
cd /d "D:\myfloder\Drivers\conf"
for %%a in (*.bat) do call "%%a"
pause

here nothing happendsAre your batch files in this folder: D:\myfloder\Drivers\conf Quote from: Squashman on April 25, 2014, 01:26:26 PM
Are your batch files in this folder: D:\myfloder\Drivers\conf

no there must be batch which runs all batch files

batch files are under
 D:\myfloder\Drivers\conf\MIKE\archive\bat

but all folders are diferend because are from differend usernames, this one is for MIKE.
and there is 30 users and 30 folders which have 30 batch files which needs to be runned
  Quote from: Blisk on April 25, 2014, 01:36:28 PM
no there must be batch which runs all batch files

batch files are under
 D:\myfloder\Drivers\conf\MIKE\archive\bat

but all folders are diferend because are from differend usernames, this one is for MIKE.
and there is 30 users and 30 folders which have 30 batch files which needs to be runned
Then you got your first code example COMPLETELY BACKWARDS as your code is looking for all the batch files in that folder.
D:\myfloder\Drivers\conf\)Hmm,
If there are 30 users how are we doing to know which one is logged in for the correct directory path? Quote from: Squashman on April 25, 2014, 01:51:27 PM
Hmm,
If there are 30 users how are we doing to know which one is logged in for the correct directory path?

this is runned on server

and I need to run this batch files
Code: [Select]echo off
pushd "..\logfiles"
for /f "delims=" %%a in ('dir /b /od /a-d ') do set "lastest_file=%%a"
copy "%lastest_file%" "..\test\new"
popd"Runned is not a word."
Does your browser not have spell check.

Nor does your reply answer my question. Quote from: Squashman on April 25, 2014, 01:56:30 PM
"Runned is not a word."
Does your browser not have spell check.

Nor does your reply answer my question.

Don't know what you mean with user logged on?
Because it is not relevant for this batch files.

We need to search copy.bat files in subfolders
 D:\myfloder\Drivers\conf

and after that script will find copy.bat under

 D:\myfloder\Drivers\conf\MIKE\archive\bat
 D:\myfloder\Drivers\conf\JOE\archive\bat
 D:\myfloder\Drivers\conf\NIKE\archive\bat

and it will run that copy.bat files
So you SAID 30 folders with 30 batch files.  That is 900 batch files.  You really want to execute 900 batch files?I have no idea what you are trying to accomplish.  But this is my take on it.
Code: [Select]for /d %%G in (D:\myfloder\Drivers\conf\*) do (
FOR %%H in ("%%G\archive\bat\*.bat") do call "%%H"
)
835.

Solve : Batch file to use list of files and perform an action for each of the files?

Answer»

Hello.  I have to run a COMMAND line to process one file at a time in Irfanview.  My command line looks like this:

Code: [Select]"c:\program files (x86)\irfanview\i_view32.exe" c:\tif\430251.tif /extract=(c:\tiffsplit, tif)
"c:\program files (x86)\irfanview\i_view32.exe" c:\tif\430252.tif /extract=(c:\tiffsplit, tif)
"c:\program files (x86)\irfanview\i_view32.exe" c:\tif\430253.tif /extract=(c:\tiffsplit, tif)
"c:\program files (x86)\irfanview\i_view32.exe" c:\tif\430254.tif /extract=(c:\tiffsplit, tif)
"c:\program files (x86)\irfanview\i_view32.exe" c:\tif\430255.tif /extract=(c:\tiffsplit, tif)
"c:\program files (x86)\irfanview\i_view32.exe" c:\tif\430256.tif /extract=(c:\tiffsplit, tif)

I have to create this batch file in the following steps:
1.  run:  dir /b c:\temp &GT; list.txt       (to create a list of files)
2.  Copy/Paste the list into Excel
3.  Concatenate a command line for each file in Excel.
4.  Copy concatenated lines into a batch file.

Is there a way I can skip all of those steps and do something like:
forfiles /p c:\temp /m *.tif  IRFANVIEWSCRIPT

Thanks!

Brian
Code: [Select]echo off
for %%G in (c:\tif\*.tif) do "c:\program files (x86)\irfanview\i_view32.exe" "%%~G" /extract=(c:\tiffsplit, tif) Worked GREAT!  Thanks!

836.

Solve : what is meant by this?

Answer»

can any one tell me the meaning of this line in detail plz explain each character in detail actually i m new in SCRIPT writing. thx
For /F "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
Split the dataset (the output of the command 'date /t') into 4 tokens delimited by the / character or by SPACES, and return the 2nd of these tokens in the explicit metavariable %%a and the 3rd token in the implicit metavariable %%b and the 4th token in the implicit metavariable  %%c, and then set a STRING variable called mydate equal to these values separated by hyphens (minus signs). Type FOR /? at the prompt for full documentation.

837.

Solve : Help with creating script that anyone can run in Domain for locked down users.?

Answer»

Hi all,

Can anyone help with a .bat file creation.
I'm looking for a .bat file for running TRACEROUTE for any user in a Domain environment.
I think they will need elevated permissions to run it but I'm not 100% SURE.
When they try and remote into a specific Terminal Server it sometimes COMES up that the Computer they are remoting to isn't on or not AVAILABLE or even on the Network but it is. ( I know it is as I can connect to it remotely )
I would like them run a traceroute back to a specific server through a VPN that they are trying to connect to while they are mobile. ( all non admin USERS don't have the run command as they are locked down through group policy )
Any suggestions or help is welcome.
Thank you,

Joe
Not sure what not having access to the RUN command has anything to do with this.  If they have CMD.exe or .BAT files locked down then you might be out of luck.

As far as I know TRACERT can be run with any user.  I certainly can't see any reason why Microsoft would lock down that command to be run Elevated only.

So all you would have to do is put the TRACERT command into a file and name it accordingly.  Don't name it the same as the TRACERT command.  If you want the output logged to a file then use redirection to output it to a file instead of the screen.

838.

Solve : Listing log file in dd_mm_yy.txt format?

Answer» HI everyone,

I want to list log files whose names are changing daily. Like that;

C:\log\dd_mm_yy.txt

"dd_mm_yy.txt" is changing daily. What kind of a definition I must use in Windows command prompt to list the log file ? Could you PLEASE help me about how can I solve that problem?

Best Regards
Murat Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

Quote
C:\Users\Dave>dir/?
Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

  [drive:][path][filename]
              Specifies drive, directory, and/or files to list.

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  HIDDEN files               A  Files ready for archiving
               S  System files               I  Not content indexed files
               L  Reparse Points             -  Prefix MEANING not
  /B          Uses bare format (no heading information or summary).
  /C          Display the thousand separator in file sizes.  This is the
              default.  Use /-C to disable display of separator.
  /D          Same as wide but files are list sorted by column.
  /L          Uses lowercase.
  /N          New long list format where filenames are on the far right.
  /O          List by files in sorted order.
  sortorder    N  By name (alphabetic)       S  By size (smallest first)
               E  By extension (alphabetic)  D  By date/time (oldest first)
               G  Group directories first    -  Prefix to reverse order
Press any key to continue . . .

Dir /o *.txt

Will list the log files that are saved as text files in numeric/alpha order. You can use sort order to list differently. Code: [Select]C:\log>dir /a-d /b | findstr /R /C:"[0-9][0-9]_[0-9][0-9]_[0-9][0-9].txt"
07_05_14.txt
08_05_14.txt
09_05_14.txt
839.

Solve : files archive with drag and drop?

Answer»

Hello,

I have files with the samen filename but different file extensions.
With drag and drop of only 1 file, no-matters what the file extension is, i want to archive
all these files to one archive with the common filename.

I try this but it's not working for filenames with a sepparator in the filename.

-------------------------------------------------------------
cls

echo on

SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:
 
for /f "tokens=* delims= " %%F in ('echo %fName%') do (


rem echo REN %%~NXF %%~nF

rar a -ag[dd-mm-yyyy] %%~nF.rar %%~nF.*

)


------------------------------

cls

echo on

SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:
 
for /f "tokens=* delims= " %%F in ('echo %fName%') do (


rem echo REN %%~nxF %%~nF

rar a -ag[dd-mm-yyyy] %%~nF.rar %%~nF.*

)



thanks jrom



You need to surround the pathways in quotes or it will interpret them as multiple arguments.

I also made your for loop a little simpler.  Not SURE if you want to keep those changes.

Code: [Select]cls

echo on

SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if "%1"=="" set /p fName=Enter file name:
 
for /f "delims=" %%F in ("%fName%") do (

echo REN "%%~nxF" "%%~nF"

rar a -ag[dd-mm-yyyy] "%%~nF.rar" "%%~nF.*"

)

You don't need a loop:

Code: [Select]echo off
rar a -ag[dd-mm-yyyy] "%~n1.rar" "%~dpn1.*" Quote from: foxidrive on May 10, 2014, 09:12:14 AM

You don't need a loop:

Code: [Select]echo off
rar a -ag[dd-mm-yyyy] "%~n1.rar" "%~dpn1.*"

The loop allows for no input to be specified until the program runs, otherwise you will run it with %1 equal to nul. Quote from: Lemonilla on May 10, 2014, 11:21:53 PM
The loop allows for no input to be specified until the program runs, otherwise you will run it with %1 equal to nul.

Yes Lemonilla, the code doesn't allow for input but the thread is all about drag and drop on a batch file. 

Hi ,

Thanks all for your help.

Both scripts are use-able for me.
Only files with spaces in the filename are not archived.
How can this be DONE?

thanks in advance

jromWhich solution did you try?

Both Lemonilla's and mine preserve spaces - Lemonilla's code needs a %~1 so that the IF compare doesn't FAIL but the rar terms are quoted.

Are you using a modern version of RAR?Both scriptsRAR 5.10 beta 4Try this code and copy/paste the result on the SCREEN here in a reply.  Use a filename with spaces.

Code: [Select]echo off
echo %1
echo rar a -ag[dd-mm-yyyy] "%~n1.rar" "%~dpn1.*"
pauseHi foxidrive.

This is working correct, now i can also archive files with a space in the filename.
Thanks a lot.

jromSo what did you change? The only difference in Foxidrive's code was he put an echo statement so we could see the command it would execute without it executing.
840.

Solve : create a batch file?

Answer»

Hello,
i am working on a pipeline company and we deal with 100 of EXCEL sheets DAILY, our job basically is to extract data from database each day for all the pipelines by changing the date and time from excel, and this is takes alot of time to do. so, can i create a batch file where it can change the date and time AUTOMATICALLY?Batch cannot read and write Excel files but Vbscript can.how can i do that with vbscript? QUOTE from: almatar00 on APRIL 22, 2014, 02:13:57 PM

how can i do that with vbscript?

If you want exact details then more details about the task are needed.
841.

Solve : .exe versions help?

Answer»

Ok i have been tasked with having a swift free antivirus solution for our company.  Im using wget to download 3 PROGRAMS to a known folder then using start /wait to RUN through them silently one at a time. One thing i cannot FIGURE out is how can i launch a program when the .exe changes names for each version?  Basically the folders will be blank except for a .bat and wget.exe. We upload to CLIENTS computer from out FTP then run the .bat which downloads the programs and executes automatically with no input.

THANKS,
Neilhere is the generic script so far

Echo off
echo Downloading required files..........
cd progs
start /wait wget http://download.bleepingcomputer.com/dl/46f12a4412eb181eb1a5afba40143498/53719a84/windows/security/security-utilities/r/rkill/rkill.scr
start /wait wget http://www.sur-la-toile.com/RogueKiller/RogueKiller.exe
start /wait wget http://http://www.vipreantivirus.com/live/Download2/
start /wait rkill.scr -s
start /wait VIPRERescue29122.exe -s
start /wait RogueKiller.exe -hidenobody? Code: [Select]for %%a in (VIPRERescue*.exe) do start "" /wait "%%a" -sYOU ARE AWESOME !!

842.

Solve : How do you run a command on a list of files??

Answer»

Hi folks, I'm trying to merge a bunch of geotifs together using FWTools (gdalwarp specifically) but I'd like to first do a "dir /b *.tif > list.txt" on the directory to come up with a file list of the source .tifs. If I paste all the filenames into the command manually the command I need looks like this spread out on a single LINE:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic "C:\Temp\m_3208134_ne_17_1_20100928_20101105.tif" "C:\Temp\m_3208135_nw_17_1_20100708_20101105.tif" "C:\Temp\output_WGS84.tif"

EDIT: I think I can CD into the C:\Temp folder before running the command so I shouldn't need the path in addition to the filenames.

That works fine but I'll be pasting for 3 hours before I can run the command and I need to merge the entire group of tiles into several separate output .tifs ultimately, what I'd like to do is add the command to the beginning of the dir list and the output file to the end something like this:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic
17RLM705845_201012_0x3000m_4B_1.tif
17RLM705860_201012_0x3000m_4B_1.tif
17RLM705875_201012_0x3000m_4B_1.tif
17RLM720845_201012_0x3000m_4B_1.tif
17RLM720860_201012_0x3000m_4B_1.tif
17RLM720875_201012_0x3000m_4B_1.tif
output_WGS84.tif

I'm almost positive I've seen this demonstrated somewhere but I can't find it for the life of me. If I try to run the command as pasted above I get gdalwarp's help text because the command wasn't correct followed by 6 .tifs opened in PhotoShop and a file not found error for the output .tif . Can someone give me a hand with the syntax I need, or is this even possible?

As always, much appreciated!

JimYour command line shows two filenames and an output filename.

Where are the input filenames coming from?  Are they all in a single format?  How do we match the sets of two files?

In the second command with 6 files - how do the set of input filenames come about?Thanks for your reply foxidrive.

The imagery comes off the national map server as tiled .jp2 (JPG2000) in 5000 x 5000 pixel tiles. To cover a specific geographical area you draw a bounding box on a map and complete your order which results in an email with links to a number of tiled downloads in .zip files. I believe the filenames correspond to the coordinates of the tile somehow, probably in UTM format. Here I've extracted just a few of the .jp2s and used another FWTools function (gdal_translate) to convert them to geotifs with the FOR command, this step is (sometimes) necessary to eliminate an embedded alpha channel from the .jp2s prior to merging them, otherwise gdalwarp can merge the .jp2s directly. gdalwarp uses the embedded geodata to assemble these 5000 x 5000 px tiles into a large geotif, the filename of which you simply specify at the end of the list of source .tifs to be merged.

gdalwarp also reprojects the imagery from NAD83 to WGS84 projection in the process of merging them. The list I posted is an abbreviated example from another project, I currently have about 100 of these I need to stitch together but to keep them manageable in PhotoShop each output .tif NEEDS to be roughly 25000 x 15000px max. It's imperative that they come in under 2 Gb for the next step of processing which is to use an MS SDK supplied tool (resample.exe) to convert them to photoreal scenery for Flight Simulator. The tool chokes if the .tifs exceed 2 Gb. That means ideally 15 adjoining tiles in a 5x3 pattern should be merged into each output.tif. I have an auto-generated google earth .kml from the map server that shows the relationship of each of the tiles in GE, this allows me to sort the appropriate GROUPS of 15 into separate folders for processing each output file.

In the past I've used a macro in Textpad to turn a dir list of these source .tifs into a long one-line command as shown in the first example. I'm working with colleagues on this and it would be much easier to have them open a command window and type "dir /b *.tif > filelist.txt" and then parse the command into the resulting file list somehow rather than explain the use of macros in Textpad, lol. This is something that we'll be repeating a lot in the coming months so just trying to get a workflow down basically at this point.

Thanks again,
JimThanks for the overview, though I need to know how the filenames are arranged from the source - one directory or two or more?

if you did a dir /b *.tif >file.txt then what do you do with the filenames?  How do you order them for the executable command?

We have no information about how the command line is assembled from the list of files, and that is needed to write a batch script.I'm still downloading tiles so I don't yet know all the filenames or which .tifs will end up in which folders at this point, but assume I've sorted 15 of the source .tifs into an empty folder manually, using hypothetical filenames I would normally just dir the folder to list the filenames then put all the sources in line like this:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic 1.tif 2.tif 3.tif 4.tif 5.tif 6.tif 7.tif 8.tif 9.tif 10.tif 11.tif 12.tif 13.tif 14.tif 15.tif output_wgs84.tif

...or I could also do this:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic 15.tif 14.tif 13.tif 12.tif 11.tif 10.tif 9.tif 8.tif 7.tif 6.tif 5.tif 4.tif 3.tif 2.tif 1.tif output_wgs84.tif

It doesn't matter which order the source .tifs are in or how many there are because gdalwarp locates them in the output .tif according to the geo LOCATIONS embedded in the source .tifs. Either of the above commands will give me the same output, a mosaic of the tiles with the filename "output_wgs84.tif".


So if I were to dir the folder to a txt file, all I'm trying to do is somehow use that filelist in the command without removing the line breaks, it would just be nice if I could simply paste "gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic" at the head of the file and the output filename at the end:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic
1.tif
2.tif
3.tif
4.tif
5.tif
6.tif
7.tif
8.tif
9.tif
10.tif
11.tif
12.tif
13.tif
14.tif
15.tif
output_wgs84.tif

I was hoping something like these parentheses might work but of course they don't:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic (
1.tif
2.tif
3.tif
4.tif
5.tif
6.tif
7.tif
8.tif
9.tif
10.tif
11.tif
12.tif
13.tif
14.tif
15.tif
)
output_wgs84.tif

My plan was to ultimately do a dir /s from the upper directory and with some minimal editing turn it into a batch file like this where a merged .tif would be output for each folder full of sources:

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic
folder1\1.tif
folder1\2.tif
folder1\3.tif
...
folder1\15.tif
output_wgs84_01.tif

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic
folder2\1.tif
folder2\2.tif
folder2\3.tif
...
folder2\15.tif
output_wgs84_02.tif

gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic
folder2\1.tif
folder2\2.tif
folder2\3.tif
...
folder3\15.tif
output_wgs84_03.tif

etc.

The more I think about it though this is probably just not going to be possible as each line is interpreted as a command and I can't see any way around that. So what about using FOR?

for %f in (*.tif) do gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic "%f" "%~nf_WGS84.tif"

That works fine if you simply want to output a reprojected version of each source .tif with "_WGS84" appended to the filename, but it doesn't merge them all together into one. If I try:

for %f in (*.tif) do gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic "%f" "output_WGS84.tif"

then of course it simply wants to overwrite the output each time. I need something like this, lol:

for %f in (*.tif) do gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic "%f" "%f" "%f" "%f" "%f" "%f" "%f" "%f" "output_WGS84.tif"

But how could I possibly make something like that work?


Thanks again for the assistance.
JimSee what this does - it expects a series of folders below where the batch file is located and
the variable files is populated with the files in a folder, and then the gdalwarp command
is launched to create the output files in one place, with the folder name as part of the filenames.

It's untested.


Code: [Select]echo off
for /d /r %%a in (*) do (
   pushd "%%a"
      set files=
      for %%b in (*.tif) do call set files=%%files%% %%b
      call gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -t_srs "+proj=latlong +datum=WGS84" -r cubic %%files%% "c:\output folder\%%~nxa_wgs84.tif"
   popd
)
Thank you foxidrive, in the end it worked but I had to do some fiddling, your script was fine though.

FWTools has a "shell" that you must run these commands from, I'm not sure exactly what it does, it starts a batch called "setfw.bat" which is located in D:\MSFS\FWTools2.4.7. setfw.bat calls another batch in D:\MSFS\FWTools2.4.7\bin named "setfwenv.bat". This process obviously sets up an environment for these tools to run, I should have divulged that little tidbit previously:

setfw.bat:
Code: [Select]echo off
SET FWTOOLS_DIR=D:\MSFS\FWTOOL~1.7
call "%FWTOOLS_DIR%\bin\setfwenv.bat"
(for some REASON that all appears on one line if I edit setfw.bat in Notepad, pasting it here or opening the file in Textpad or Notepad++ the line breaks appear normally)

setfwenv.bat:
Code: [Select]echo off
REM ==========================================================================
REM This script is normally invoked from FWTools\setfw.bat

REM The FWTOOLS_OVERRIDE environment variable allows you to set a the
REM install directory in your environment, instead of having to edit
REM setfw.bat.  This is especially useful if you frequently upgrade to new
REM versions, and don't want to have to edit the file every time.

IF exist "%FWTOOLS_OVERRIDE%\setfw.bat" SET FWTOOLS_DIR=%FWTOOLS_OVERRIDE%

IF exist "%FWTOOLS_DIR%\setfw.bat" goto skip_err

echo FWTOOLS_DIR not set properly in setfw.bat, please fix and rerun.
goto ALL_DONE

:SKIP_ERR

PATH=%FWTOOLS_DIR%\bin;%FWTOOLS_DIR%\python;%PATH%
set PYTHONPATH=%FWTOOLS_DIR%\pymod
set PROJ_LIB=%FWTOOLS_DIR%\proj_lib
set GEOTIFF_CSV=%FWTOOLS_DIR%\data
set GDAL_DATA=%FWTOOLS_DIR%\data
set GDAL_DRIVER_PATH=%FWTOOLS_DIR%\gdal_plugins
REM set CPL_DEBUG=ON

:ALL_DONENo idea what I would ever do with %FWTOOLS_OVERRIDE% BTW.

First I started the FWTools shell and called your batch file from that, the batch was located in the root folder which contained the test folders and I also made a "c:\output folder" first. The result was a screenful of occurrences of gdalwarp's help text.

I assumed the problem was in calling the batch from the fwtools shell so I copied gdalwarp.exe into the root folder containing my test folders. The script I learned is looking for a copy of gdalwarp.exe in each of the test folders so I placed a copy in each. Then I learned about gdalwarp's dependencies for about the next hour, lol. Ultimately I wrote a batch to copy each of the dependencies into each of the 6 test folders, here's a list of everything I copied before I finally satisfied gdalwarp:

gdalwarp.exe
gdal_fw.dll
geos_fw.dll
geotiff_fw.dll
hdf5dll.dll
hdf_fw.dll
jpeg12_osgeo.dll
jpeg_osgeo.dll
libcurl.dll
libeay32.dll
libexpat.dll
libmysql.dll
libpq.dll
libtiff_fw.dll
lti_dsdk_dll.dll
mfhdf_fw.dll
msvcp71.dll
msvcr71.dll
NCScnet_fw.dll
NCSEcw_fw.dll
NCSUtil_fw.dll
netcdf.dll
ogdi_32b1.dll
proj.dll
sqlite3.dll
ssleay32.dll
szlibdll.dll
xerces-c_2_7.dll
zlib1.dll
zlib_osgeo.dll

With that done I ran your script and 10 minutes later ended up with 6 merged .tifs in the output folder bearing the names of the source folders. Perfect, it was a thing of beauty really! I will attempt to modify your script now so it references gdalwarp in the "D:\MSFS\FWTools2.4.7\bin" folder where all these dependencies are normally located, then I'll be able to skip the FWTools shell altogether and simply run the batch after populating the source folders with the appropriate source .tifs. I think I can take it from here and again thanks so much for your help!

Jim

843.

Solve : Filename backup with YYMMDD in filename?

Answer»

Hi there, I am trying to create a script to backup a few FILES - I have the backup script written, and it works - but I can't FIGURE out how to put YYMMDD date format into the filename. I've SCOURED Google and I can't find any help. Am I just retarded? Every sript I tried from Google gives me the same thing "MMYYYY". Which isn't what I want, nor what they say should happen.

Any help would be greatly appreciated.

Thanks.Would help to see your existing script and to also know what date you want to put into the file name.
Today's date?
File creation date?
File last modified date?I GUESS if it is a backup then today's date is needed - and this is a FAQ so you should find millions of scripts to deal with today's date.

The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.

Code: [Select]echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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=%YY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
pause

844.

Solve : Remove lines from text files in a directory (keeping original file name)?

Answer»

Can someone help me? I have a directory full of html files, in the html files, I want to remove all LINES that have "xxx

I can run the following command and it prints my output correct, but I don't know how to keep the original filename.

findstr /b /v /i /c:"
I don't want to have to run this for every file like

findstr /b /v /i /c:"> copy_fixed.htmThis is untested:

Code: [Select]ECHO off
for /f "delims=" %%a in ('dir *.htm /b /a-d ') do findstr /b /v /i /c:"<LI" "%%a" > "%%a.tmp" & move "%%a.tmp" "%%a"
  Quote from: foxidrive on April 29, 2014, 10:54:01 AM

This is untested:

Code: [Select]echo off
for /f "delims=" %%a in ('dir *.htm /b /a-d ') do findstr /b /v /i /c:"<li" "%%a" > "%%a.tmp" & move "%%a.tmp" "%%a"
 

THANK you... This was right... I was running it in command prompt - so i changed %%a to %a. I didn't want to get prompted on the moving of files, so I added a /Y to the move command... THank you so MUCH.
Final command:
Code: [Select]echo off
for /f "delims=" %a in ('dir *.htm /b /a-d ') do findstr /v /i /c:"<li" "%a" > "%a.tmp" & move /Y "%a.tmp" "%a"
845.

Solve : Copy text from a website, then rename files with it?

Answer»

Howdy all



I have folder after folder of TV seasons, all files have horribly ugly names. I have used a file renmaing program to rename them in a tidy uniform format, eg "The Simpsons (S05E03) - ".

Now what I usually do is open Wikipedia, go to the shows List Of Episodes page, copy each episode name and paste it to the end of each file name. Very time consuming.


I would like run a batch file that copies each episode name I guess into a new line in a text file, then use the text file to extract the names then append to each filename. I suppose I would have to MANUALLY open the web page and scroll so the information started a specific number of lines from the top of the browser (the same each time), the get string at the coordinates containing each episode name? To start..


UPDATE:

I have sorted the first part, getting a text file of episode names. I just copied the entire table from Wikipedia, PASTED into Word, then created a macro that formatted the table until only the epsiode names remained, then saved them to a new text file on the DESKTOP, then closed Word.
So now I just have to write a batch file that appends each video file name with each line for the text file.. Is this possible?Some examples of what all your data looks like and how we are suppose to match them to append the new file name would really help.Yes, as Squashman says.

If your files sort in the same order as the names in the file then it's a simple task.ok thanks for the replies.

Here are my list files:
The Walking Dead (S02E01) - .avi
The Walking Dead (S02E02) - .avi
The Walking Dead (S02E03) - .avi
The Walking Dead (S02E04) - .avi
The Walking Dead (S02E05) - .avi
The Walking Dead (S02E06) - .avi
The Walking Dead (S02E07) - .avi
The Walking Dead (S02E08) - .avi
The Walking Dead (S02E09) - .avi
The Walking Dead (S02E10) - .avi
The Walking Dead (S02E11) - .mp4
The Walking Dead (S02E12) - .mp4

I then want to append each file name with its CORRESPONDING episode name. These names are listed in a text file, each on a new line, in the same ascending order as the episodes:
What Lies Ahead
Bloodletting
Save the Last One
Cherokee Rose
Chupacabra
Secrets
Pretty Much Dead Already
Nebraska
Triggerfinger
18 Miles Out
Judge, Jury, Executioner
Better Angels
Beside the Dying Fire
Can you guarantee that the Episode names are in the correct order? If not we can't guarantee the accuracy of the Episode Name appending.

What do you want the output file name to look like?Yes. I just copied them from Wikipedia using the method I described.

I want them to look like what I showed above, eg.

The Walking Dead (S02E01) - What Lies Ahead.avi

I'll be doing this many times in the future, so I WANTED to know what the correct syntax was for the batch file. This question was multi-posted to this site. http://www.dostips.com/forum/viewtopic.php?f=3&t=5561It's most likely these files and copying are outside the Copyright laws so i'll suspend this discussion for now...
Feel free to PM me if this is not the case.

patio.

846.

Solve : Batch code help!?

Answer» HELLO, I am trying to create a script which read from a file for example composition.gcode and I want to extract values that starts with X, Y and Z.
For example in this file there is a structure like this:

Code: [Select]G21 ; set units to millimeters
M104 S200 ; set temperature
G28 ; home all axes
G1 Z5 F5000 ; lift nozzle
M109 S200 ; wait for temperature to be reached
G90 ; use absolute coordinates
G92 E0
M82 ; use absolute distances for extrusion
G1 F1800.000 E-1.00000
G92 E0
G1 Z15.350 F7800.000
G1 X152.500 Y152.500 F7800.000
G1 E1.00000 F1800.000
G1 X347.500 Y152.500 E18.37972 F378.000
G1 X347.500 Y347.500 E35.75944
...
G1 X343.831 Y156.169 E733.08114
G1 F1800.000 E732.08114
G92 E0
G1 Z20.350 F7800.000
G1 X347.500 Y152.500 F7800.000
G1 E1.00000 F1800.000
G1 X347.500 Y347.500 E249.28171 F1260
G1 X152.500 Y347.500 E497.56342
...
I want to delete or avoid the lines with ";" and replace in sequence the values for each X, Y and Z like this:

Code: [Select]CONST robtarget P1:=[[15.350,152.500,15.350],.....
CONST robtarget P2:=[[347.500,152.500,15.350],.....
CONST robtarget P3:=[[347.500,347.500,15.350],.....
...
CONST robtarget PM:=[[347.500,152.500,20.350],......
...
CONST robtarget Pn:=[[X,Y,Z],.....
...
but I tried a LOT of attempts, but no result made... Can someone help me?

I also have to generate 2 files (robtarget.txt and movel.txt) that will be included in Mod_%modnum%.mod to generate ABB rapid instructions...!
Like this:

Code: [Select]MODULE Mod_1234
 
CONST robtarget P1:=[[x,y,z],.....;
...

PROC Routine()
ConfL\Off;
MoveL P1,v60,z5,mytool\Wobj:=mywobj;
...
ENDPROC

PROC MainMove()
Routine;
ENDPROC

ENDMODULE
The portion of the code I used is:

Code: [Select]ECHO off
set nomefile=composition.gcode
set /a x=0
set /a riga=0
set modnum=1234
set wobj=mywobj
set tool=mytool
set vel=v60

IF EXIST Mod_%modnum%.mod DEL /f Mod_%modnum%.mod
IF EXIST movel.txt DEL /f movel.txt
IF EXIST robtarget.txt DEL /f robtarget.txt
IF EXIST xresult.txt DEL /f xresult.txt
IF EXIST yresult.txt DEL /f yresult.txt
IF EXIST zresult.txt DEL /f zresult.txt

findstr /n "Z" "%nomefile%" >> zresult.txt
findstr /n "X" "%nomefile%" >> xresult.txt
findstr /n "Y" "%nomefile%" >> yresult.txt

  set xval=%xvalnew%
  set yval=%yvalnew%
  set zval=%zvalnew%

:while
if %x% lss 20 (
  set /a riga+=1
echo CONST robtarget P%x%:=[[%xval%,%yval%,%zval%],[0.00223,-0.994008,-0.109258,-0.002251],[1,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]; >> robtarget.txt
echo MoveL P%x%,%vel%,z5,%tool%\Wobj:=%wobj%; >> movel.txt
::  pause>nul
  set /a x+=1
  set /a riga+=1
  goto :while
)

echo MODULE Mod_%modnum% >> Mod_%modnum%.mod
echo. >> Mod_%modnum%.mod
copy robtarget.txt >> Mod_%modnum%.mod
:: del robtarget.txt
echo PROC Routine() >> Mod_%modnum%.mod
echo ConfL\Off; >> Mod_%modnum%.mod
echo ENDPROC>> Mod_%modnum%.mod
echo.>> Mod_%modnum%.mod
echo PROC MainMove()>> Mod_%modnum%.mod
echo Routine;>> Mod_%modnum%.mod
echo ENDPROC>> Mod_%modnum%.mod
echo.>> Mod_%modnum%.mod
echo ENDMODULE>> Mod_%modnum%.mod
Thanks and have a good time! Multi posted - http://www.dostips.com/forum/viewtopic.php?f=3&t=5577
847.

Solve : File organizing problem?

Answer»

Hey everyone.

I have a bunch of files that i need to organize in folders that fits their name. Example:

..\file A_part1.txt
..\file A_part2.txt
..\file A_part3.txt
..\file B_part1.txt
..\file B_part2.txt
..\file C.txt

this NEEDS to become:

..\file A\file A_part1.txt
..\file A\file A_part2.txt
..\file A\file A_part3.txt
..\file B\file B_part1.txt
..\file B\file B_part2.txt
..\file C\file C.txt

As you can see in the example, the file part names are all seperated from the actual filename with underscore "_". This might help a batch file RECOGNIZE what the folder name should be.

Any help would be greatly appreciated thanksExcept for File C which does not have an underscore. So we would need to see all examples of your file names to be certain we are coding for everything possible.Of cause.
Heres a few real examples:
"1984 - speech_part1.txt"
"FN. 1988 - sabb.txt"
"Ttt88.txt"

That should cover it. only the files that are in parts, needs to be grouped in the same folder. Quote from: mthmobu


That should cover it. only the files that are in parts, needs to be grouped in the same folder.
So the example in your first post was incorrect regarding file C and we can in theory just look for files ending in _Part*.txt?Hehe yes but the files that isent in parts, still needs to go into its own folder as well.Clear as mud...Untested as I am POSTING from my phone.
Code: [Select]for /f "tokens=1* delims=_" %%G in ('dir /a-d /b *_part*.txt') do (
     mkdir "%%~G" 2>nul
     move "%%~G_%%~H" "%%~G"
)That was beautiful it worked PERFECTLY, i had over 20.000 files that needed sorting.
All the part files are now grouped perfectly, and the folder names are all correct.
You saved me Alot of WORK, thank you very much
848.

Solve : FOR skipping blank iterations?

Answer»

I am trying to write some code to edit a single cell of a .csv file.  I have it to where it will change the cell, but it will skip writing the empty cells.  Any ideas how I can fix this? I believe it has to do with the WAY the FOR loop operates.

Code: [Select]echo off
setlocal EnableDelayedExpansion

set file=.
set "target=%~1"
set "file=%~2"
set "change=%~3"

echo.
if not defined file call :error "No Target" && exit /b
if not defined target call :error "No Cell Defined" && exit /b
if not defined change call :error "No Change Declared" && exit /b
if exist %file% (
if exist %file%.new.csv del %file%.new.csv
) ELSE (
call :error "No Target"
exit /b
)

set "alpha=A/1 B/2 C/3 D/4 E/5 F/6 G/7 H/8 I/9 J/10 K/11 L/12 M/13 N/14 O/15 P/16 Q/17 R/18 S/19 T/20 U/21 V/22

W/23 X/24 Y/25 Z/26"


set a=1
:l
set /a a+=1
set /a c=%a%-1
set /a b=!target:~%c%,%a%!+0 2>nul || goto :error
if "%b%"=="0" goto :l


set row=!target:~0,%c%!
set col=!target:~%c%!


set b=0
set row_num=0
:a
set c=!row:~%b%,1!
for %%A in (%alpha%) do (
for /f "tokens=1,2 delims=/" %%B in ("%%A") do (
if "%%B"=="!c!" set row_tmp=!row_tmp!%%C\
if "%%B"=="!c!" set /a row_num+=1
)
)
set /a b+=1
if not "!row:~%b%,1!"=="" goto :a


set row_score=0
set /a row_num-=1
set row_tmp=%row_tmp:\= %
for %%A in (%row_tmp%) do (
set row_val=1
for /l %%G in (1,1,!row_num!) do set /a row_val*=26
set /a row_val*=%%A
set /a row_num-=1
set /a row_score+=!row_val!
)


set row=%col%
set col=%row_score%


set row_counter=0
for /f "delims=" %%A in (%file%) do (
set AA=%%A
set "AA=!AA:;=, ,!"
set /a row_counter+=1
if "!row_counter!"=="%row%" (
set a=0
for %%B in (!AA!) do (
set /a a+=1
if "!a!"=="%col%" (
0>nul set /p"=%change%," 1>>%file%.new.csv
) else (
0>nul set /p"=%%B," 1>>%file%.new.csv
)
)
echo. 1>>%file%.new.csv
) else (
echo !AA! 1>>%file%.new.csv
)
)



REM ====== Start Debug =====
REM show file
echo Old File
for /f "delims=" %%A in (%file%) do echo %%A
echo.
echo New File
for /f "delims=" %%A in (%file%.new.csv) do echo %%A



exit /b


:error
echo [ERROR] %~1

Code: (Demo) [Select]
T:\spreadsheets>spreadsheet A1 test2.csv "Testing"

Old File
1;;;1

New File
Testing,1,

T:\spreadsheets>
It could be in this line - commas and semicolons and equals etc are treated as whitespace in a for in do command.

You seem to be passing terms like CommaSpaceComma and that will just vanish in the for in do and be treated like a single space, unless it is double QUOTED.

Code: [Select]for %%B in (!AA!) do (
VBscript using the Excel object has been mentioned, and GAWK is probably a good choice too.

849.

Solve : Redirect result from FINDST (or FIND) to COPY, to copy certain files?

Answer»

Hello,

I have a folder with hundreds of text files, but only a hand full have the keyword "glossary"in them. I need to find these files and copy them to another folder.

I can easily identify which files they are by using:

Code: [Select]findstr /i /M "glossary:" *.txt
Where /I ignores case, and /M is so the result is only the file name.

Now all I need is to REDIRECT this to a COPY command, to copy each found file to another folder.

I understand that by using the pipe, the result of one command will be redirected to the next command. So the result of FINDSTR will be sent to COPY. But COPY also expects the destination folder.

If I try

Code: [Select]findstr /i /M "glossary:" *.txt | COPY /newfolder/
this won't work, because COPY expects the origin file and the destination folder, and above the destination folder is the first argument (and not the second).

I tried using

Code: [Select]findstr /i /M "glossary:" *.txt | COPY %1 /newfolder/
but that didn't work either.

I think I may have to redirect to a temporary folder and then use that to copy to the new folder.

But I would imagine I could do it directly.

Ideas?

Thanks.







Quote

have a folder with hundreds of text files, but only a hand full have the keyword "glossary"in them. I need to find these files and copy them to another folder.
You don't need a batch file to copy a few files.
Instead of fretting about tough details, do what you can do. You can make the results into a list. Right? Then edit the list with Notepad and turn it into a batch file list instead of a loop.

Suppose I had some files with 'man' in the name. The I might get a list for text files like this:
Code: [Select]pacman.txt
rayman.txt
mandate.txt
fatmanhop.txtUsing Notepad, I would put a # at the stat of each line and a $ at the end of the line.

Code: [Select]#pacman.txt$
#rayman.txt$
#mandate.txt$
#fatmanhop.txt$Even on a list of up to one hundred items, you can do this rather fast. Humans are like that. I am a human.
Next, I would tell notepad to replace every # with the word 'copy' with a space after it. Then back to top, replace every $ with a space and the target path.
When the above is done, I save may 'list.txt' files as 'list.bat' and run it as a bat file.
The time from concept to finish can be under half an hour.
Or, you can spend another day on loops and debugging.
The METHOD I use is easier to visualize. Because you see it.
And you can do exceptions very easily.

one line of code...

Code: [Select]for /f "delims=" %%A in ('findstr /i /M "glossary" *.txt') do copy "%%A" "\newfolder\"
Code: [Select]for /F "delims=" %%G in ('findstr /i /M "glossary:" *.txt') do copy "%%G" C:\NewFolder
Salmon beat me! Quote from: Squashman on July 31, 2012, 11:26:39 AM
Salmon beat me!

But you gave the more faithful reproduction of the OP's wishes; I overlooked the colon after "glossary". Still, I expect the OP would have figured it out.



 I want a batch code to  search a string exactly like "Interpretation (Interpret) Passed" from a set of HTML files locatind in folders and subfolders and send the files which contain that string to another folder. similarly i wanna even search "Interpretation (Interpret) Failed" and "Interpretation (Interpret) Incomplete" from html files and send to specified folder.
i tried with the code mentioned below:

echo OFF
for /f "delims=" %%f in ('findstr /S/M /C:"Interpretation (Interpret) Failed" *.html') do copy "%%f" C:\\failedreports
for /f "delims=" %%f in ('findstr /S/M /C:"Interpretation (Interpret) Incomplete" *.html') do copy "%%f" C:\incompletereports
for /f "delims=" %%f in ('findstr /S/M "Interpretation (Interpret) Passed" *.html') do copy "%%f" C:\Passed

But this code doesn't work .... Any Help Pls??
 Its very urgent Pls help me out
Thanks in advance....
The Topic is almost 2 years old...
Please start a new Topic if you need a solution...Hi patio, i already created a new post named-''To search and send "Interpretation (Interpret) Passed" Exactly from Html files'' SINCE no one responded there posted here to see if some GURU replies,.....

If some1 knows the solution pls reply in that post mentioned above ....

Thank u in advance:)***sigh***
850.

Solve : Batch file - Add subfolders into file names?

Answer»

Hi, I have a FOLDER called "Classical Piano MIDIS", which consists of 1-level subfolders and midi files.

Here's what I want to have DONE, rename all of the files contained in "Classical Piano Midis\*subfolder*\" to contain the name of the subfolder and a dash at the beginning of the file name.  ("*subfolder* - ")

For example, I want "C:\Users\Owner\Documents\Classical Piano Midis\Bach\Minuet in G.mid" renamed to ""C:\Users\Owner\Documents\Classical Piano Midis\Bach\Bach - Minuet in G.mid".
And "C:\Users\Raymond\Documents\Classical Piano Midis\Chopin\Scherzo No.2, Opus.31.mid" renamed to ""C:\Users\Raymond\Documents\Classical Piano Midis\Chopin\Chopin - Scherzo No.2, Opus.31.mid"

Thanks.Edit:  I no longer need this ACTUALLY, a programmer friend ended up doing what I NEEDED to do to those files (in a method other than using a batch file)Rather easy to do in batch should you ever need the solution.