|
Answer» how can i make a batch file read from another file to do a set of commands? i need it to fix another computer.if you use < or sometimes << it is imput , and >> is output .. example
say you want to make a new file from scratch , type 00>>newfile.txt the 00 in red is just needed so >> can work , so it can be anything.. you can also use > to redirect output to a file, say you wanted "dir" output to go to a file you could type Dir >directory.txt .
< can be used to put input in a file , say if you TOOK the directory.txt .. from using the > and you typed del dir >dir.txt |del <dir.txt
REM For loop example to pull each entire line from another file REM Note that each line is executed independantly from all others
for /f "tokens=*" %%a in (file.txt) do CMD /C %%a thanks guys. that really helped!REM For loop example to pull each entire line from another file REM Note that each line is executed independantly from all others
for /f "tokens=*" %%a in (file.txt) do CMD /C %%a
Hello!
I have a SIMILAR dilemma with the difference of that instead of running independent commands one after the other, I need to run commands that depend on the result of the previous one. How do you do that with a FOR loop?
If I'd rephrase the original question, that would say: How can you run more than one command with a word picked from a TEXT file?
For example I have a text file computers.txt that has the LIST of all active computers like this:
cp001 cp002 cp005 cp022 etc.
Then I want the batch file to pick the first computer NAME, then do these or any multiple commands with the same computer name:
a) if not exist "\\%computer%\c$\program files\eudora\nicknames\sample.txt" copy whateverfilename.txt "\\%computer%\c$\program files\eudora\nicknames\"
b) echo %computer%>>resultlog.txt
...then go and pick the next computer name from the file computers.txt and run the same commands again until it finished reading the last name from the text file.
Geza Hi guys,
i have tried this to copy a given list of archives in list.txt to other disk:/dir but i could not copy files with spaced names:
FILE --- backuplist.bat @echo off for /f "tokens=*" %%a in (list.txt) do copy %%a d:\2\
FILE --- list.txt c:\3\1.jpg c:\3\2.jpg c:\3\3.jpg c:\3\4 4.jpg c:\3\5 5.jpg
This only copies the first three files (1.jpg, 2.jpg and 3.jpg) If i put alll the names in the file between "" ("c:\3\4 4.jpg") it works fine, but my list is pretty long!!! :-( Could i avoid edit the whole file or do it automated??? Any idea??? TIA create list.txt with quotes
if exist list.txt del list.txt for /f %%F in ('dir /b c:\3\*.jpg') do ( echo "%%F" >> list.txt )
|