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.

7151.

Solve : making programs witch run on ms dos?

Answer»

yo,
I want to make programs and games WITCH run on ms dos but I can't find any information on internet :-/
I think that if I knew how to (and if I had enough time of COURSE), I would make great games and stuff.
And if you don't believe me, check one of my websites under construction: www.dopeshit.nl.tt
And if you still don't believe me, ask eeh I don't know, your teacher orsomething? Get into programming - try QBASIC, Assembler etc to START with then move onto C, C++ etc...

Zillions of WWW sites with info

7152.

Solve : rename multiple files?

Answer»

im trying to rename multple files ina folder but keep the existing name and jsut add a word in the front. so for example


test.txt
test2.txt
test3.txt
test4.txt

rename them to...(im just adding cp to the front of the file name

cp test.txt
cp test2.txt
cp test3.txt
cp test4.txt

All of the files, or just some of them?
all of the files sorryCode: [SELECT]@for /f "delims=" %%A in (' dir /a-d /b *.* ^| find /v "%~nx0" ' ) do ren "%%~dpnxA" "cp %%~nxA"
Save this as a .bat file e.g. MyRename.Bat and run it in the folder. It will not rename itself.
Thanks alot it worked perfect. i had one more question can you exaplin what each part is doing? like what does "%~nx0" stand for? i know that the %%A is a varabile for the loop. but im trying to break down the code to understand everything its doing. if you can break it down that would be great. THANK you again



@for /f "delims=" %%A in (' dir /a-d /b *.* ^| find /v "%~nx0" ' ) do @echo ren "%%~dpnxA" "cp %%~nxA"
Quote from: daillest319 on October 24, 2012, 11:32:29 AM

Thanks alot it worked perfect. i had one more question can you exaplin what each part is doing? like what does "%~nx0" stand for? i know that the %%A is a varabile for the loop. but im trying to break down the code to understand everything its doing. if you can break it down that would be great. thank you again



@for /f "delims=" %%A in (' dir /a-d /b *.* ^| find /v "%~nx0" ' ) do @echo ren "%%~dpnxA" "cp %%~nxA"

I see you NOTICED the echo that I left in for debugging.

for /f "delims=" %%A in (dataset)
... the /f switch tells FOR to treat (dataset) as a source of lines to be processed. If dataset is a command enclosed in single quotes then the command is executed and the output is processed.

the command is : dir /a-d /b *.*
... list files, but not directories in bare format

^| find /v "%~nx0"

... PIPE the output of dir through find (the pipe symbol is escaped with a CARET if used in a FOR dataset). The /v switch says to find.exe, "show lines which do not contain the search string".

... the search string for find.exe is %~nx0.

%0 is the batch file name. The ~n and ~x modifiers mean "name" and "extension" so the batch file being run is filtered out of the file list produced by DIR, and thus the batch itself is not renamed.

The other variable modifiers used in the script are ~d ~p, drive and path respectively.

%%~dpnxA is the full drive letter, path, name and extension of each file listed by DIR

%%~nxA is the bare name

"cp %%~nxA" is the new name - that is, the original name and extension, with cp and a space in front of it.

to learn more about DIR. FOR, FIND, etc, type the command followed by /? and read the help.

thank you so much .Quote from: foxidrive on October 24, 2012, 04:28:02 PM
.

HuH ? ?I was going to suggest a simpler method - only then I realised it wasn't a filespec of test*.* but the OP wanted *.* and my method wouldn't have been appropriate due to a bug in for-in-do.

We used to be able to delete posts, but that ability was removed? So I edited it. Now i'll know what the period means foxidrive...

The feature just so you know was restricted due to a few posters that abused it incessantly...making many Topics almost un-intelligible.
Thanx for the clarification.

patio.Quote from: foxidrive on October 24, 2012, 05:44:33 PM
We used to be able to delete posts, but that ability was removed? So I edited it.

I have had to do this more than once. Sometimes I have managed to disguise the situation by hurriedly thinking up some other thing to post, more often I have just put a dot.
7153.

Solve : Residents services and program testing?

Answer»

Residents services and PROGRAM testing

I would like a bat to launch all the services and programs that I usually launch in the startup.
This is because sometimes some of them are closed without my intervention and i WANT to COME back again.
But not with multiple instances.
So I need to test that that process is not running before launch again.

do you know any program or bat for this.

Best Regards
So you want a program that will check if your stuff is running and open it if it isnt? can we get a list of the programs and pathways to them?


preliminary code
Code: [Select]tasklist | find "PROGRAM1.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM1.exe

you just copy this a bunch of times for each program you want. if you want it to continually check, use ':loop' at the beginning and 'goto loop' at the end as shown below

Code: [Select]@echo off
:loop

tasklist | find "PROGRAM1.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM1.exe

tasklist | find "PROGRAM2.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM2.exe

tasklist | find "PROGRAM3.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM3.exe

etc...

goto loop


tell me if you get any errors, it may need some tweaking.A slightly more concise option.
Code: [Select]tasklist | find "notepad.exe" >nul ||start notepad.exeQuote from: Lemonilla on October 25, 2012, 01:34:58 PM

So you want a program that will check if your stuff is running and open it if it isnt? can we get a list of the programs and pathways to them?


preliminary code
Code: [Select]tasklist | find "PROGRAM1.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM1.exe

you just copy this a bunch of times for each program you want. if you want it to continually check, use ':loop' at the beginning and 'goto loop' at the end as shown below

Code: [Select]@echo off
:loop

tasklist | find "PROGRAM1.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM1.exe

tasklist | find "PROGRAM2.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM2.exe

tasklist | find "PROGRAM3.exe" >nul
if %errorlevel% EQU 1 start <path>PROGRAM3.exe

etc...

goto loop


tell me if you get any errors, it may need some tweaking.

I use a very large list of residents under windows 7 64 bits, 16GB ram, i7 processor.

I put a screenshot, and may be you can indicate the type of care I have to take in the bat



I can add any other thing you require
Best Regards

Quote from: Squashman on October 25, 2012, 03:09:37 PM
A slightly more concise option.
Code: [Select]tasklist | find "notepad.exe" >nul ||start notepad.exe

Nice indeed. Goes well with programs in my data disks Y: or O: ?
7154.

Solve : Use Arguments in Batchfile!!!?

Answer»

Hello,
i just want SOMEONE to shed something about arguments being used in Batch file, i am not able to get a firm grip on this thing, i have downloaded many doc files and copy pasted materials from the web but it only revolvs around the same thing and thier is no full proof material to full one's querie. So i am requesting from this forum, to shed some light on this subject: beggining with a small example and extending it little by little.

Thank you:
When you start any windows PROGRAM, you can pass what are called 'arguments,' which are small pieces of data. You can tell a paint program what file to OPEN, for example. In batch files, you access the arguments with %1, %2, %3, etc.

Let's SAY you have a batch file called echoarg.bat, which contains one line:
Code: [Select]echo %1
When you type
Code: [Select]echoarg exampletext 2ndarg arg3into the command line, you will see exampletext appear on-screen. In this example, %2 will be "2ndarg" and %3 will be "arg3", but the batch file doesn't use those.

Hope this helps some, just ask if this needs more clarification.just a clarification on what TechnoGeek posted.

Say you have a batch file NAMED arg.bat that looked like this:
Code: [Select]@echo off
echo %1
echo %2
echo %3

and you called it like so:
Code: [Select]arg.bat A B C

it would compile as such:
Code: [Select]@echo off
echo A
echo B
echo C

with an output of:
Code: [Select]A
B
C

WARNING, if you were to call the arg.bat program above like so:
Code: [Select]arg.bat A B

it would compile as
Code: [Select]@echo off
echo A
echo B
echo

which would output as:
Code: [Select]A
B
echo is off.

I would recommend using 'echo.%1' to fix this issue.

7155.

Solve : User Variable Question?

Answer»

I'm trying to add this user variable to a batch file and I'm having no luck.

The variable name is: CVSROOT
The variable value is: :pserver:[emailprotected]:/usr/local/cvsroot

I tried doing something like this:

set CVSROOT=:pserver:[emailprotected]:/usr/local/cvsroot

...but that didn't do the trick.

Any ideas?Your SET statement works fine on my machine. Have you any error messages? What OS are you dealing with? Have you run out of environment space?

Let us KNOW. I'm using Windows XP Pro. I don't THINK I've run out of environment space.

Shouldn't the outcome of my SET statement end up in here?:



Where it says, "User VARIABLES for Dave"?Setting variables THRU a batch file are only exist within the scope of the batch file session. For more permanent results, you need to GO thru the XP shell object or do it manually.

7156.

Solve : unable to boot into windows 7 desktop?

Answer»

Hello,
I have a computer that will not boot to the windows desktop. I am able to access the cmd prompt using the windows 7 repair/installation disk. I want to copy all the files and folders from the bad desktop to an external hard drive. Is there a command to copy all files and folders to an external hard drive? if not, what is the best way to accomplish this using the cmd prompt?
Thanks for your time.Boot up a LIVE linux boot cdrom such as Ubuntu and USE the file manager to drag the "documents and settings" folder or the desktop to your external USB drive.

You need to see the files you are after in case some have slipped somewhere - a command line solution isn't appropriate for a rescue situation.Thanks foxidrive, your input is greatly appreciated. I will try that tonight.
Thanks again.Keep in mind everything on the desktop is nothing but shortcuts to files/folders and apps...

Have you attempted to run the repair option from the DVD ? ?...last on the list of options i believe in the RC.I've tried the repair option half a dozen times and it is UNABLE to fix it. The closest I've come to booting is I get a windows boot manager error and it restarts. Error number is 0x00000ex9.The Win7 DVD repair should fix this...is this a copy of Win7 ? ?the only disk that came with the computer is labeled:
operating system, Windows 7 upgrade option, vista home to windows 7 home edition. 64 bit edition.

I have tried all the repair options using this disk and they all are unable to repair the problem.

Would a windows 7 live CD be of use to me?

thanks.
There is no "live" Win 7 CD...if you find ONE it's illegal...
What is it you are trying to accomplish here ? ?

Copying OS files from an un-bootable PC won't get you any further down the road...Trying to use a windows repair tool that actually works and lets me get past the hanging black screen of death after the windows logo pops up.Then something in your steps got interrupted or went wrong...
You probably have to run the Win Repair on Vista 1st...then install the Win7 Update after Vista is running properly...

7157.

Solve : Batch Delete?

Answer»

I am looking to create a batch that can will delete files permanently.

The problem is I want to search for several file extensions (.xls, .zip, .txt).

These files will appear within a sub directory of a folder called "download". The download folder will exists in about 20 folder structures.

EG You could have a folder called A which has a folder within that called Download, and a folder within that called test which will contain the files. You can then have another folder called B on the same LEVEL as A that contains the same structure as A?

Any ideas? Batch language is not a programming language. But since everyone seems to think that it is, I OFFER this primitive solution:

Code: [Select]

@echo off
:start
if .%1==. goto end
for /f "tokens=1*" %%a in ('dir foldername /a:d /b /s ^| find /i "download"') do (
for /f "tokens=1*" %%i in ('dir "%%a\*.%1" /b') do (
echo %%a\%%i
)
)
shift
goto start

:end


This solution is quirky at best. It's also a self feeder. Pass the file extensions along the command line. Replace foldername with a folder of your choice.

Note: I am HESITANT to show posters how to delete files. As written, the file will simply echo back what would be deleted...change echo to del at your own risk. Files deleted thru batch files and scripts do not make a pit STOP in the recycle bin.

Good luck and next TIME mention your OS (it's not a state secret) and consider Win Scripting as a better and more robust solution.

7158.

Solve : Escape character for " in IF DOS command?

Answer»

I'm trying to CONDITIONALLY remove a possible leading " character in a variable. I thought this would work:

Code: [Select]IF '%TEMP:~0,1%' EQU '"' SET TEMP=%TEMP:~1%
but I GET the error message "SET was unexpected at this time.".

Thanks in advance for any help you may be able to provide.Try
Code: [Select]IF "%TEMP:~0,1%"=="^"" SET TEMP=%TEMP:~1%

This might be useful too:

Code: [Select]@echo off
set var="abc
set "var=%var:"=%"
echo.-%var%-
pause
And this if it is surrounded by quotes:

Code: [Select]for /f "delims=" %%a in ("%var%") do set "var=%%~a"Actually, if it is surrounded by quotes then you don't use the quotes in the () so this is more APPROPRIATE:

Code: [Select]for /f "delims=" %%a in (%var%) do set "var=%%~a"

7159.

Solve : Run dos program in XP?

Answer»

I know very little about DOS. I have an OLD program I would like to run through Windows XP. I copied it on my laptop and set up a batch file. It starts about 1 TIME in 20 attempts. Does anyone have any suggestions for me?Try to find "DosBox", and INSTALL it on your computer.
You can find this from the INTERNET and it's about 1MB.
Let's say that the program you want to run is located
at c:\ eg. c:\something.com
Then you'll have to run dosbox.
You'll see this...

z:\>_

and you'll have to type the following:

z:\>mount c: c:\
Drive C is mounted as local directory c:\
z:\>c:\
c:\>something

and your program should start running.

7160.

Solve : Displaying a message to screen with quotation & exclamation marks?

Answer»

Hi,

I need to echo the following message to screen in MS-DOS where setlocal enabledelayedexpansion is declared.

"The mail was successfully SENT!"

This is proving difficult because of the escape CHARACTERS used. Using ECHO The mail was successfully sent^^! shows the exclamation mark but not when ENCLOSED in quotation marks, as this shows as "The mail was successfully sent^".

Any ideas?
Code: [Select]@echo off
set var=!
setlocal EnableExtensions EnableDelayedExpansion
echo "The mail was successfully sent!var!"
pauseThanks :-)THis works for me, with just one escape character

@echo off
setlocal enabledelayedexpansion
echo "The mail was successfully sent^!"
pause

result

C:\>echo_exclamation.bat
"The mail was successfully sent!"
Press any key to continue . . .



Why not just toggle delayed EXPANSION off before the echo and back on after the echo.Quote from: Squashman on October 31, 2012, 05:32:46 PM

Why not just toggle delayed expansion off before the echo and back on after the echo.
If you're using variables with setlocal enabled, then those variables WOULD be wiped out once you did that. Too many people use an exclamation mark as if it was a period.
That's true!!
7161.

Solve : batch file not working help please?

Answer»

hi all i am making this batch file show some system commands and i cant get it to work

@echo off
:BEGIN
CLS
SET /P CVAR=Hello whats your name ?

echo %CVAR%, do you want to see a list of commands ?

CHOICE

If choice== y GOTO 1
IF choice== n GOTO 2


:1
ECHO Ok %CVAR% here they are
echo new folder command
mkdir C:\Users\Steven\Desktop\commands\new
echo dir Command
pause
dir C:\Users\Steven\Desktop\commands\new
goto end

:2
ECHO Ok %CVAR% good bye
goto end

pause

:end
pause
You need to study how the Choice command works, mainly. Type Choice /? at the prompt. Also how to do IF tests.
hi i cant work out why if i put yes or no it does yes on bothQuote from: sjolliffe2 on January 10, 2014, 02:26:39 PM

hi i cant work out why if i put yes or no it does yes on both
You need to check the errolevel. Not if they answered Y or N.

Code: [Select]C:\Users\Squash>choice
[Y,N]?Y

C:\Users\Squash>echo %errorlevel%
1

C:\Users\Squash>choice
[Y,N]?N

C:\Users\Squash>echo %errorlevel%
2
thanks got it hi hi do i set a count down timer ?Quote from: sjolliffe2 on January 10, 2014, 04:04:37 PM
hi hi do i set a count down timer ?

Try choice /? and study the options.
Or use 'timeout'. If you want only the number, put it in a 'for /f' loop.@sjolliffe2
writing like that can LEAD to spaghetti code if you not careful. This author recomends using "subroutines".

you could also try using a programming language if your env allows you to . vbscrtip/powershell included.Quote from: briandams on January 10, 2014, 06:21:15 PM
@sjolliffe2
writing like that can lead to spaghetti code if you not careful. This author recomends using "subroutines".

you could also try using a programming language if your env allows you to . vbscrtip/powershell included.
To avoid this you could put :1 and :2 into the if statement, but that can cause many more errors. As long as you format the white space properly and add APPROPRIATE comments you can avoid this. Often times looking back on my previous codes I get lost in the "function" based ones easier than in the linear "spaghetti" ones.I think that how hard something to READ is more based off how documented it is, because it's the documentation that explains how things work, and the purpose of certain parts of the code... Spaghetti code just means that you have to spend time following the individual "threads" of spaghetti loop around the line numbers... It's more unclean than it is unreadable, though documented spaghetti code is harder to read than documented subroutine oriented code.... but that is only because of the fact that you have to keep track of your spaghetti at the same time as the code itself. (And that is BORING.)Top-Down programming is the term they used way back, for code that starts and then progresses linearly.

It's useful for a small project and is easier to read in small projects, IMO.
7162.

Solve : How to create a batch command to change file names?

Answer»

Hi
I have a folder of 1000s of mp3 files with names in the following format:

02 Zenaida aurita.mp3
01 - Red-throated Loon.mp3

What I want to do is create a dos command that trawls through the folder and removes the 02, 01, - and initial space before the actual name so that I end up with just (Zenaida aurita.mp3). I want to do this for every file in the folder. Bear in mind that it is not just 01 OR 02. The files have any number at the beginning such as 099. However, I do not want any numbers at the end of the file name removed so some files are like this:

38 Black-chinned Mountain-Tanager (2).mp3

and this one should end up LOOKING like this:

Black-chinned Mountain-Tanager (2).mp3

Any help and ideas?This works here:

Filenames with % and ^ in them might give problems, and foreign language character sets.

Code: [Select]@echo off
del renmp3.bat.txt 2>nul
for %%a in (*.mp3) do (
for /f "tokens=1,2,* delims= " %%b in ("%%a") do (
for /f "delims=0123456789" %%e in ("%%bA") do (
if "%%e"=="A" (
if "%%c"=="-" (
>>renmp3.bat.txt echo ren "%%a" "%%d"
) else (
>>renmp3.bat.txt echo ren "%%a" "%%c %%d"
)
)
)
)
)
echo check renmp3.bat.txt for issues, if it's ok rename it .bat and run it.
pause
Quote

Hi foxidrive
Thanks, this worked brilliantly and did the job for the majority of the files. Much appreciated as it SAVED me huge work. There was one problem in that I discovered files with the hyphen sandwiched between numbers i.e.

099 - 01 BLACKBIRD.MP3
there were 100s of this type that the dos code did not rename. Is there an alteration to the code you can suggest to do this type?

Thanks again.

This is UNTESTED: it works in the same way. The REN commands will be placed in the file for you to examine.

If you have files like

109-03 title.mp3 (without spaces between the numbers and hyphens) then you'll need another variation.

Code: [Select]@echo off
del renmp3.bat.txt 2>nul
for %%a in (*.mp3) do (
for /f "tokens=1,2,3,* delims= " %%b in ("%%a") do (
for /f "delims=0123456789-" %%f in ("%%b%%c%%dA") do if "%%f"=="A" >>renmp3.bat.txt echo ren "%%a" "%%e"
)
)
echo check renmp3.bat.txt for issues, if it's ok rename it .bat and run it.
pause
These solutions have worked great. Thanks for all the help. I have converted over 6500 names in a SECOND which as you can imagine was not a manual task I would have liked.

Very very much appreciated. Thanks
7163.

Solve : Socket programming in dos?

Answer»

Hello,
i am working in c for designing a MAIL client to access an SMTP SERVER(unix). i want sockets to connect with it.can any one tell how to get SOCKET library for dos. i am using PPP as packet DRIVER please give me a solution.

7164.

Solve : Folder list?

Answer»

Hi,

I'm trying to display a the contents of a folder in a window. When I close the folder I wish the next folder listed in the batch to OPEN etc and so on through the list. At the moment:

start R:\foldername1
start R:\foldername2
start R:\foldername3

this opens all folders at once...

Any help appreciated.

THANKS
mamock
try start /wait "" "foldername"
Thanks for response.

I have tried this and they still open together.Does this workaround suffice for you?

If not then EXPLAIN what you are doing and someone might have an idea.

Code: [SELECT]@echo off
start "" R:\foldername1
pause
start "" R:\foldername2
pause
start "" R:\foldername3
I did a bit of research. Put simply, you can't do this with Explorer.exe, at least not from batch.
Thanks for all the help.

I just wanted to open a list of folders one at a time without having to use keyboard input to move on.

'pause' will have to do for now...

CheersIf this is your own computer or if you are allowed to run a free Explorer alternative such as Explorer++ then you can launch it and then use Tasklist in a LOOP to detect when it exits. If you are intending to use an employer's or school computer this may not be possible. (You do not have to use the alternative as an Explorer replacement; it can run independently.) Reply if you want guidance.




7165.

Solve : Set part of a user's input as a variable?

Answer»

How do I set part of a user's input equal to a variable?

The script asks for the user's login name. Login names are as such lastname>@ (ie [emailprotected]). I need to set a variable that is equal to everything after the "@" symbol.

I've tried this:

SET /P UPN=Enter the users UPN:
For /F "tokens=* [emailprotected]" %%F IN (%UPN%) DO SET FARMID=%%F
Echo %FARMID%

and not only doesn't it work (because %UPN% isn't a file) but I'm not certain that a For loop is called for. What's the right way to do it?

Thanks,

MJ

You forgot the quotes around %UPN%, also you are looking for the 2nd token, so I would change "Tokens=* to "Tokens=2.


SET /P UPN=Enter the users UPN:
For /F "tokens=2 [emailprotected]" %%F IN ("%UPN%") DO SET FARMID=%%F
Echo %FARMID%Code: [Select]C:\>set [emailprotected]

C:\>echo %upn%
[emailprotected]

C:\>set upn=%upn:*@=%

C:\>echo %upn%
widgetco

C:\>Leminolla - that did the job. Thanks!

Quote from: powlaz on January 07, 2014, 07:23:29 AM

but I'm not certain that a For loop is called for. What's the right way to do it?

Thanks,

MJ
No, you don't need the FOR command at all as I have demonstrated. Either way works. Use what you feel comfortable with.Squashman - my apologies. I glanced at the first line of your command (which won't work for my application of the command) and disregarded it. Based on your follow-up I actually APPLIED the logic in a way that will work for me and it works (of course you knew that)! Learned something new from you today, thank you!Sometimes I just like to open the cmd prompt and run the commands one at a time to show the user the output. Sometimes the visual helps. But the base code is just:
Code: [Select]SET /P UPN=Enter the users UPN:
set upn=%upn:*@=%Of course I would do some error checking on the input so I would end up doing this.

Code: [Select]:USERLABEL
SET UPN=
SET /P UPN=Enter the users UPN:
IF DEFINED UPN (
set UPN=%UPN:*@=%
) ELSE (
GOTO USERLABEL
)There are a few differences between these methods.

I don't think that any of these scenarios will COME up in your example, by the way...

If there is nothing before the @, the FOR method will return nothing, as it will read the @ as TABULATION, and the part of the string that you are looking for will be read as the first token, and ignored.
The special expansion method would in this case select everything except the @.

If the @ was followed by a second @, then the FOR method would eliminate the second @ as well, the expansion method wouldn't.

If there was an @ somewhere else in the company name, then the FOR method would detect everything after that @ as the THIRD token, and exclude it, the Expansion method however would have already found the substring it was looking for, and would ignore the second @

Assuming that everybody using the script has a name, and that company names don't include the @ symbol, then either method will work FINE, however it seems that if you aren't going to add some more code to make it secure then Squashman's method is more secure.

Also thanks Squashman, for that method. I'd never seen that used in place of for /f before.The asterisk only works as a wild card if it is the first character. It does not work in reverse and then you would need to use a FOR command to get the first token.
7166.

Solve : real easy question, probably?

Answer»

I'm STUCK in DOS and can't get back to windows the screen says C:\windows&GT; What command do I type here to load up windows again. THANKS in advance
win<enter>

7167.

Solve : Patch file to copy a single file to multiple UNIX machine?

Answer»

Hello,
This is my first post in this forum, I have been reading and learning from it all day.

I made a patch file to copy a new file to different unix devices , but i do it one by one.
i am looking for way to do all of them at once.
I am running Win 7 32bit

here is my patch file:

@ftp -i -s:"%~f0"&GOTO:EOF
OPEN 192.168.0.11
username
password
cd /etc
put C:test.txt
pwd

I am looking for way to take the IP address from a text file one by one or even list them in the script.
all my unix devices has the same username and password.

Thanks,


Open is not a DOS command.
You need to use FTP or a FTP client.It would seem that the OP is using the batch file as a script and ignoring the @FTP error

To FTP using a range of IP addresses in a file then you can use for /f but will need to create temp script files.Actually the first line tells DOS to switch to ftp mode, the Open command will be executed in FTP shell and my code in the first post is working 100% and i always use it to connect.

what i am looking for again is to connect to multiple IP addresses using the same batch or any other.

any help is really appreciated.

Thanks,Your batch is really just batch file that calls itself as an FTP script file. You will no LONGER be able to do it that way. You will need to use a FOR LOOP to read a list of IP addresses. One line for each IP address and then build your FTP script file on the fly with echo commands to a text file and then use the FTP command to CALL the script file.

Code: [Select]FOR /F "delims=" %%G in (IpFilename.txt) do (
>ftpscript.scr echo open %%G
>>ftpscript.scr echo username
etc......
ftp -i -s:"ftpscript.scr"
)Thank you for your help,

I am really new to Batch file and FOR command, could you please explain your code in more detail.

Thanks,Code: [Select]FOR /F "delims=" %%G in (IpFilename.txt) do (For command reads the file IpFilename.txt one line at a time and assigns each line to the variable %%G

Code: [Select]>ftpscript.scr echo open %%GThis physically writes the word OPEN and the IP address to the ftpscript.scr file. The > character tells the batch file to redirect the output of the ECHO command to the file. A single > will overwrite or create a new file.

Code: [Select]>>ftpscript.scr echo usernameThis physically writes the USERNAME to the ftpscript.scr file. The double >> characters tells the batch file the redirect the output of the echo command to the file and APPEND to the end of the file.

You just need to repeat the ECHO commands for the rest of the FTP script. I am sure you understand what the last line does.Thank you very much for your help.

I was able to use it as is after i added a line for the password and another for the put command.

also i created a file with a list of IP address and read little bit about "FOR /F" .

Now after your explanation I figured out how it works, courser i need more practice to be able to do some thing similar at my own.

Your help saves alot of time.

Thank you very much.

Abo FihmiHello,

I have a follow up question, what about if i need to open putty instead of ftp and do some commands for the same list of Devices.

Thanks,http://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter6.html#psftp
http://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter7.html#plink

Are you referring to running shell commands on your unix boxes or using secure ftp to your unix boxes.

What i am trying to do is to have a patch file to open a Linux box using Putty then execute some shell commands, then disconnect and connect to different one and execute the same commands.
it is not over SFTP.

Thanks,Did you read the link I gave you to PLINK?Yes, I am familiar with plink, here is my script:

start plink.exe -ssh [emailprotected] -pw Password /opt/sbin/rebuild.sh

what this script does is re build a specific box, what i need to do is run it for multiple boxes at once.

I need to have the IP address as variable and the IP addresses value will be listed in separate file just like what we did in ftp scenario.

Thanks,

Same for loop code I gave you as above. %%G will contain the IP address.

7168.

Solve : How to remove part of a string within a text file?

Answer»

Hi
I have a text FILE with many thousands of LINES in the following format:

crescent.mp3
blackbird.mp3
jay.mp3

I want a dos script to go through the text file LINE by line and remove the '.mp3' part from the end of each NAME. Any ideas??the mp3 PORTION is the file extension...if you remove it they will cease to plat anymore...Quote from: geroido on November 03, 2012, 10:04:13 AM

Hi
I have a text file with many thousands of lines in the following format:

crescent.mp3
blackbird.mp3
jay.mp3

I want a dos script to go through the text file line by line and remove the '.mp3' part from the end of each name. Any ideas??

If you want a new text file with line as in your text file, but with each line having the final 4 characters (.mp3) removed,

a script like this should work

@echo off
setlocal enabledelayedexpansion
set inputfile=birds1.txt
set outputfile=birds-no-extensions.txt
if exist "%outputfile%" del "%outputfile%"
for /f "delims=" %%A in (' type "%inputfile%" ' ) do (
set oldline=%%A
set newline=!oldline:~-0,-5!
echo Old: !oldline! New: !newline!
echo !newline! >> "%outputfile%"
)
echo done
pause

birds1.txt

Golden-bellied Euphonia.mp3
Golden-headed Manakin.mp3
Golden-spangled Piculet.mp3
Golden Collard Macaw.mp3
Golden Parakeet.mp3
Golden-winged Parakeet.mp3
Grassland Sparrow.mp3
Gray-*censored* Sabrewing.mp3
Gray-chested Greenlet.mp3
Gray-*censored* Martin.mp3
Gray-crowned Flycatcher.mp3
Gray-fronted Dove.mp3
Gray Monjita.mp3
Gray Hawk.mp3
Gray Antbird.mp3
Gray Antwren.mp3
Gray Rumped Swift.mp3
Gray-winged Trumpeter.mp3
Gray-headed Kite.mp3
Gray-headed Tanager.mp3
Gray-necked Wood-Rail.mp3
Grayish Mourner.mp3
Grayish Saltator.mp3
Great Jacamar.mp3
Great Kiskadee.mp3
Great Horned Owl.mp3
Great Tinamou.mp3
Great Rhea.mp3
Great Dusky Swift.mp3
Great Egret.mp3
Great Black Hawk.mp3
Great Antshrike.mp3
Greater Ani.mp3
Greater Thornbird.mp3
Greater Yellow-headed Vulture.mp3
Green-tailed Jacamar.mp3

birds-no-extensions.txt

Golden-bellied Euphonia
Golden-headed Manakin
Golden-spangled Piculet
Golden Collard Macaw
Golden Parakeet
Golden-winged Parakeet
Grassland Sparrow
Gray-*censored* Sabrewing
Gray-chested Greenlet
Gray-*censored* Martin
Gray-crowned Flycatcher
Gray-fronted Dove
Gray Monjita
Gray Hawk
Gray Antbird
Gray Antwren
Gray Rumped Swift
Gray-winged Trumpeter
Gray-headed Kite
Gray-headed Tanager
Gray-necked Wood-Rail
Grayish Mourner
Grayish Saltator
Great Jacamar
Great Kiskadee
Great Horned Owl
Great Tinamou
Great Rhea
Great Dusky Swift
Great Egret
Great Black Hawk
Great Antshrike
Greater Ani
Greater Thornbird
Greater Yellow-headed Vulture
Green-tailed Jacamar


Thanks for the help. Works greatCode: [Select]@echo off
set inputfile=birds1.txt
set outputfile=birds-no-extensions.txt
if exist "%outputfile%" del "%outputfile%"
for /f "delims=" %%A in (' type "%inputfile%" ' ) do (
echo %%~nA>>"%outputfile%"
)That's a more compact alternative, and the FOR part could be all on one line

@echo off
set inputfile=birds1.txt
set outputfile=birds-no-extensions.txt
if exist "%outputfile%" del "%outputfile%"
for /f "delims=" %%A in (' type "%inputfile%" ' ) do echo %%~nA>>"%outputfile%"


.
7169.

Solve : DOS 6.22 Hard Drive Issue?

Answer»

So I've recently acquired a stock Dell Latitude CP M233ST with a damaged hard drive. I cannot find a new drive for something this ancient, so I wish to use FDisk to partition off the damaged allocation units. I've partitioned a 10MB section using a Win98SE setup disk and now have my DOS 6.22 disk in the drive. These are CD-ROMs, not floppies, by the way. For some reason, though, FDisk will not read the internal HDD in DOS but will in the Win98SE disk. I've included the system info below. At this point I'm just looking for possible solutions to an unknown issue.

--- System Information/Specs ---
BIOS Version: A14
Processor: Pentium-233 MHz/MMX
Level 2 Cache: 512 KB
System Memory: 64 MB
Video Controller: NeoMagic 2160
Video Memory: 2 MB (Like I'm gonna use all that in DOS?)
Audio Controller: Crystal 4237B
Primary Hard Drive: 5253 MB
Diskette Drive A: Not Installed
Diskette Drive B: Not Installed
Diskette Reconfig: Any Time
Modular BAY: CD-ROM
Service Tag: CDW7L
Asset Tag: Not Installed
------
If you want my CMOS config, just ask. Though, I think the RTC battery is dead - it keeps resetting. I'll get to that eventually.If it has a floppy drive you should use it...and i'd replace the battery.Eheh, I don't have a floppy drive MODULE. I wish I did. It would be helpful. But at the moment I'm stuck with a CD-ROM. At least until I can get antiquated hardware.Both Newegg and Amazon have them in stock...internal models if you are here in the States...You could always make a CD act like a Read-only Floppy too as in for installation purposes. I converted one of my Ghost Floppies to CD using an older Roxio Easy CD Creator 5 which had the ability in options to make a Floppy into a CD. CD boots up system and it gives A: prompt.

Also made another that boots up system with NDIS2 driver for Intel Pro 100 Managed NIC and Ghost with Static IP address so I can send images from my master system with Ghost Images to the system requiring image over my LAN. 15 minutes LATER a reboot and I have my spare computer back up and running preconfigured from image.

Just not sure of legalities of converting your DOS 6.22 disk set to CD's.

FreeDOS can be burned to a CD from ISO download and just as good as 6.22 for running older games etc. Used that about 10 years ago for a project and it worked well.

7170.

Solve : Adding/removing a prefix to/from file names?

Answer»

I'd like automate a bulk RENAMING task with just one click or with a command. I suppose I need command line utility or a batch file that allows me to do this. The changes in all couples are the same: adding a prefix "DM-" to the files NAMES in one case, and removing the prefix in the other so as to restore the original names. Could you help me out with this? Thanx.

ADD PREFIX DM- TO CTF-*.* = DM-CTF-*.*
REMOVE PREFIX DM- FROM DM-CTF-*.* = CTF-*.*

ADD PREFIX DM- TO BR-*.* = DM-BR-*.*
REMOVE PREFIX DM- FROM DM-BR-*.* = BR-*.*

ADD PREFIX DM- TO AS-*.* = DM-AS-*.*
REMOVE PREFIX DM- FROM DM-AS-*.* = AS-*.*

ADD PREFIX DM- TO DOM-*.* = DM-DOM-*.*
REMOVE PREFIX DM- FROM DM-DOM-*.* = DOM-*.*

ADD PREFIX DM- TO ONS-*.* = DM-ONS-*.*
REMOVE PREFIX DM- FROM DM-ONS-*.* = ONS-*.*

ADD PREFIX DM- TO VCTF-*.* = DM-VCTF-*.*
REMOVE PREFIX DM- FROM DM-VCTF-*.* = VCTF-*.*Renaming files with wildcards can be tricky. You can end up with mangled files names that are imposssible to decipher.

There seems to be a pattern with your file names so this may not be so bad.

Quote

ADD PREFIX DM- TO CTF-*.* = DM-CTF-*.*

Code: [Select]
for /f "tokens=1-2 delims=." %%a in ('dir /b CTF-*.*') do ren %%a.%%b DM-%%a.%%b


Quote
REMOVE PREFIX DM- FROM DM-CTF-*.* = CTF-*.*

Code: [Select]
for /f "tokens=1-4 delims=-." %%a in ('dir /b DM-CTF-*.*') do ren %%a-%%b-%%c.%%d %%b-%%c.%%d


You should be able to work out the rest. You may want to consider making a test run in a test directory before you blast away at real files.

Good luck. Thanks for the information. It works as you say, however, I have batch of files with long names and space between. Can you please advice how I can add prefix to multiple files in one go?
For example:

"run dmc - walk this way.mp3" rename to: "2013 run dmc - walk this way.mp3"
"NWA - Hello.mp3" rename to: "2013 NWA - Hello.mp3"

Regards,
FSamie (a rookie)for /f "delims=" %%A in ('dir /b /a:d') do rename "%%A" "2013 %%A"

Is how I would do it, but I'm sure there are multiple ways that work.I think you meant /a-dTo support long filenames with spaces etc you just need the QUOTES in the ren portions.

Quote from: SIDEWINDER on December 03, 2005, 04:10:03 PM
Code: [Select]for /f "tokens=1-2 delims=." %%a in ('dir /b CTF-*.*') do ren "%%a.%%b" "DM-%%a.%%b"
Code: [Select]for /f "tokens=1-4 delims=-." %%a in ('dir /b DM-CTF-*.*') do ren "%%a-%%b-%%c.%%d" "%%b-%%c.%%d"


But it can be simplified too:

Code: [Select]for /f "delims=" %%a in ('dir /b CTF-*.*') do ren "%%a" "DM-%%a"
Code: [Select]for /f "tokens=1,* delims=-" %%a in ('dir /b DM-CTF-*.*') do ren "%%a-%%b" "%%b"
Quote from: Squashman on January 04, 2014, 08:04:18 PM
I think you meant /a-d
Yup, it's good to have people willing to look over your work for these kind of mistakes lemonilla and all you gurus here
Thank you very much, you people are truly good.

foxydrive
I tried your code to remove the extension, but it didn't work. Can you please take my example and remove the 2014 from it?

2014 jz - 99 problems.mp3
2014 mj - walk that way.mp3
Code: [Select][quote author=FSamie link=topic=15956.msg898900#msg898900 date=1389110499]
2014 jz - 99 problems.mp3
2014 mj - walk that way.mp3
[/quote]

Because 2014 is ALWAYS in the beginning, and we know that it is 4 characters long, we can set the file name equal to a string, and then remove the first 5 characters (to include the space as well).

setlocal EnableDelayedExpansion
for /f "delims=" %%A in ('dir /b /a:-d') do (
set a=%%A
rename "%%A" "!a:~5!"
)
[/code]

I would recommend testing this on dummy files before you give it a go.
I created a bat file with the following:

for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A rename "%%A" "!a:~5!")

but it didn't work.
Give this a run. It will echo the commands to the console so remove echo if you are happy with it.

Code: [Select]@echo off
for /f "tokens-1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b"
pause
foxi
I tried
for /f "tokens-1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b"
it didn't work.
Please have in mind I'm an absolute rookie who just created a .bat file with your codes and tried to remove the "2014 " prefix from my files in a specific folder.
Thanks in advanceQuote from: FSamie on January 07, 2014, 03:41:33 PM
I created a bat file with the following:

for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A rename "%%A" "!a:~5!")

but it didn't work.

You forgot to enable Delayed Expansion

Code: [Select]setlocal enableDelayedExpansion
for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A & rename "%%A" "!a:~5!")

(and your syntax was wrong after the 'do'. You had forgotten to separate 'set' and 'rename' with & or &&)Lemonilla
I tried your codes and they all work fine and summarised here


To add, for example "2014 " to all files:
for /f "delims=" %%A in ('dir /b /a-d') do rename "%%A" "2014 %%A"

To remove "2014 " from all files:

setlocal enableDelayedExpansion
for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A & rename "%%A" "!a:~5!")

Again, many thanks
FSamie (beginner)Quote from: FSamie on January 08, 2014, 07:25:56 AM
foxi
I tried
for /f "tokens-1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b"
it didn't work.

It always helps to mention the error messages on the console - for future posts anyway.

In this case I had hit - instead of = when I typed the code. Oops.

Try this:

Code: [Select]@echo off
for /f "tokens=1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b"
pause
7171.

Solve : Getting multiple lines of output as arguments to another program??

Answer»

Hi, I have an Acer laptop, running windows 7, etc.

My question is about obtaining a certain result in windows command prompt, either through a batch FILE or (preferably) through a single command.

What I'd like to do is take every line of output from ONE command and use each line as an argument for SEPARATE calls to another command.

Specifically, I'd like to take each line of output from this command:

powercfg -devicequery wake_armed

... and use each of the devices named (each appearing on a new line) as the last argument to this command:

powercfg -devicedisablewake

There are some troubles:

1. seems to require the string of the device's name to be placed in double-quotes in order to work, but that's not how powercfg outputs the devices -- it outputs each one as a string on a new line.

2. powercfg's help doesn't accept multiple devices being wake-disarmed at the same time, requiring some way of REPEATEDLY calling powercfg for each device needing disabling.

The purpose, of course, is to disable all wake-armed devices with "one click".

Can anybody explain to me what I'll need to do to obtain this result? Is it even possible to do this with some kind of command shorthand, through piping output, or will a batch file be absolutely required?

-- eyenottry
Code: [Select]for /f "delims=" %%A in ('powercfg -devicequery wake_armed') do (
powercfg -devicedisablewake %%A
timeout /t 1 >nul
)

I believe this is what you want. if it doesn't work, can you post the output of 'powercfg -devicequery wake_armed' for US?From prompt... in a batch use double percent signs (batch: %%A prompt: %A)

Demo mode; remove @echo to make it operate for real

C:\>for /f "delims=" %A in ('powercfg -devicequery wake_armed') do @echo powercfg -devicedisableawake "%A"
powercfg -devicedisableawake "NVIDIA nForce 10/100/1000 Mbps Networking Controller "
powercfg -devicedisableawake "Microsoft USB IntelliMouse Optical (002)"
powercfg -devicedisableawake "HID Keyboard Device (001)"

7172.

Solve : Batch file to play different window startup sounds randomly?

Answer»

Hi

I would like my Windows to startup with a different startup sound each time I log in but I have not written any batch file before. Please help me to get started.Change "C:\my wav FILES\" below to where you STORE your WAV files.
Pick any startup wav sound and note the filename.

Change this part below "c:\location and name\of your\startup wav file.wav" to the location and name you picked.

At the moment it will only echo the copy command and then pause, so you can test it.
Remove the echo keyword and the pause keyword when you are SURE it is echoing random names, to make it function, and put it in your startup group.

The random file routine came from Dostips.


Code: [Select]@echo off

cd /d "C:\my wav files\"

set "$="
for %%a in (*.wav) do set /a $+=1 & for /f %%b in ('call echo.%%$%%')do set "$file[%%b]=%%a"
set /a $random=%random% %% $ + 1

call set "file=%%$file[%$random%]%%"
echo copy /b /y "%file%" "c:\location and name\of your\startup wav file.wav"
pause
The scipt is not working. My waves files are located at C:\Media.

My files in C:\Media:
Sound1.wav
Sound2.wav

Below is my modification. I save this batch file at Startup folder . The file name keep changinga at the 2nd last STATEMENT echo copy /b /y "%file%" "c:\Media\Sound1.wav

everytime it plays the same file after restarts. Please help.

@echo off

cd /d "C:\Media"

set "$="
for %%a in (*.wav) do set /a $+=1 & for /f %%b in ('call echo.%%$%%')do set "$file[%%b]=%%a"
set /a $random=%random% %% $ + 1

call set "file=%%$file[%$random%]%%"
echo copy /b /y "%file%" "c:\Media\Sound1.wav"
pauseQuote from: Learning81 on November 06, 2012, 11:57:13 PM

The scipt is not working. My waves files are located at C:\Media.
The file name keep changinga at the 2nd last statement echo copy /b /y "%file%" "c:\Media\Sound1.wav

Change it to this line, now that it is echoing the random files.

copy /b /y "%file%" "c:\Media\Sound1.wav" >nul

and remove the pause
7173.

Solve : Help with File Open ErrorLevel in a DOS Batch?

Answer»

Hello, I've got a simple batch file that's running on a windows xp system and it's set to run a continuous loop looking for files to exist in a particular folder on my network DRIVE. The bat file basically consists of a bunch of IF EXIST commands see example below.
Code: [Select]:Loop
IF EXIST FILENAME1 GOTO JOB1
IF EXIST FILENAME2 GOTO JOB2
IF EXIST FILENAME3 GOTO JOB3
Goto Loop

:job1
run commands
Goto loop

:Job2
run commands
Goto loop

:Job3
run commands
Goto loop

This works but from time to time the batch encounters an open file that's being written to the network drive and it cause's all sorts of problems as you might imagine. I'm not very good with DOS IF statements etc so I can't figure out a way to do a simple test on the file after the IF EXIST command to see if it's OPEN or NOT and then either doing the GOTO Loop or GOTO Job#..

Thanks for your help...Scott Some people suggest trying to rename the file (and renaming it BACK if successful) but that doesn't always provide a true test of an open file, whereas COPY /B filename+NUL filename is more reliable (and does not alter the file!)

:loop
if exist filename1 COPY /B filename1+NUL filename1 > NUL 2>&1 && (GOTO Job1)
if exist filename2 COPY /B filename2+NUL filename2 > NUL 2>&1 && (GOTO Job2)
if exist filename3 COPY /B filename3+NUL filename3 > NUL 2>&1 && (GOTO Job3)
Goto loop

Thanks for the reply..

Do I need to clean up the file I'm coping too so the next time this file Exists and the copy command is invoked there won't be a problem over writing that file..

Thanks again for your help..
This is simpler to LOOK at, and should work the same...

:loop
if exist filename1 COPY /B filename1+NUL filename1 > NUL 2>&1 && (GOTO Job1)
if exist filename2 COPY /B filename2+NUL filename2 > NUL 2>&1 && (GOTO Job2)
if exist filename3 COPY /B filename3+NUL filename3 > NUL 2>&1 && (GOTO Job3)
Goto loop


Quote

Do I need to clean up the file I'm coping too so the next time this file Exists and the copy command is invoked there won't be a problem over writing that file..

Not sure what you mean here...

Thanks again for your help..

I don't exactly understand what this command is doing COPY /B filename1+NUL filename1 > NUL 2>&1 && ..

I see the COPY command so I assume that it's creating a file somewhere on my network drive so I was wondering if I needed to DELETE the copied file to keep the drive cleaned up to prevent other issues like over write errors etc the next time the loop condition exists..

Sorry for the dumb questions...There are no extra files produced. The way the test works is this:

What you are doing is copying each file onto itself. Normally you cannot copy a file to another file in the same folder with the same name. You get an error, "The file cannot be copied onto itself." You can try it yourself at the prompt. Say you have a file called test.txt. If you do...

copy test.txt test.txt

you get the error.

So you use a trick. NUL is a special empty file available in may operating systems including Windows. So you use the COPY file1+file2 file3 syntax, where the + sign means copy file1 and file2 to file3. The trick is that NUL is an empty file so copying file1+NUL to file2 just makes a copy of file1 in file2. A further trick is that this works if file2 already exists. So we copy file1+NUL to file1 (that is, itself, note the files are the same) We use the /B switch after COPY to force a binary (byte for byte copy) so that nothing in the file gets altered. If the file is not in use by another process, the operation succeeds and the file ends up the same as it was before. If the file is in use, the operation fails. We can test for failure or success using && and ||.

command1 && command2 - only if command1 was successful (errorlevel 0) then command2 is executed.

You have your loop going round and round testing if each file is in use. If it is in use, you would get an error message each time saying "The process cannot access the file because it is being used by another process." If the file was not in use, you would get a "1 file(s) copied" message. Either way, these would clutter up the screen each time so, using > we we redirect the console output stream to another instance of NUL (yes, you can do this!) also we use 2>&1 to redirect the (STDERR, stream 2) into the standard console stream (STDOUT, stream 1). So there are no messages on the screen.

I know this may seem confusing, but you can look on the web for explanations of the COPY command, NUL, stream REDIRECTION, as well as the && and || operators.Thank you for the detailed explanation I really appreciate your time and effort... This is exactly what I was looking for..

Thanks again for all of your help and guidance..

ScottAnother option from Dbenham on StackOverFlow.
http://stackoverflow.com/questions/10518151/how-to-check-in-command-line-if-given-file-or-directory-is-locked-that-it-is-usOne thing to be aware of is that in any multitasking operating system, there is no 100% foolproof way of knowing that a file is not in use, at the time you want to do something to it. You could do a check that comes back "not in use" and then, milliseconds later, before your script has a chance to do the next command, the file gets grabbed by another process. No matter how careful you are there is always a window between when you check if the file is available and when you actually use it. This may not pose much of a problem e.g. if you are looking to if an expected file exist in a folder, you find that it does, but the process that was writing it has not yet finished, and you know that after that happens, no other process is going to grab it.

7174.

Solve : Redirect output?

Answer»

Hi,
I am running a DOS command to backup one of my disk files:

xxcopy e:\*.* j:\ /BU/KS/H/E > SKIPFILE.TXT

During the running of this utility it outputs the name of any files that it can't backup (open, locked, etc). I am trying to redirect the output from the screen to a text file. It is not working. The file is created, but nothing is written to it and the output goes to the screen. When it is completed I have an empty file. I am running the utility out of the command prompt window. Also, my OS is Windows 7.

ThanksThere are TWO console output streams, identified by numbers. Stream 1 is called STDOUT and stream 2 is STDERR. Stream 1 is the normal console output and is assumed if no number is used. That is

echo 1> output.txt is equivalent to echo > output.txt

As you might guess STDERR is usually reserved for ERROR messages. To get STDERR into a file using redirection you can redirect stream 2 into the file like this

program.exe 2> errors.txt

Or to get all output you can merge stream 2 and stream 1 and then redirect into a file using this sequence of characters 2>&1.

EXAMPLE:

xcopy bla bla bla > yourfile.txt 2>&1Quote from: Salmon Trout on November 08, 2012, 10:16:49 AM


echo 1>output.txt is equivalent to echo >output.txt


I could have made this clearer

echo hello world >output.txt is equivalent to echo hello world 1>output.txt

If you do this DIR /b *.txt >output.txt you will get a list of any .txt files in the current folder into output.txt BUT if there are none, the error message file not found is output to stream 2 and appears on the screen (because you have not redirected stream 2) so you can do this

valid output to one file, errors to another file:

dir /b *.txt 1>textfiles.list 2>errors.txt

or everything in one file

dir /b *.txt > textfiles.list 2>&1

If you need to echo a string to a file, white space before the redirection symbol is important if the string is a single digit (any digit 0-9) or there might be white space then a single digit number at the end of the string:

C:\>echo my age is 1>test.txt & TYPE test.txt
my age is

C:\>echo my age is 1 >test.txt & type test.txt
my age is 1


Thus echo %var%>file.txt will NOT give the same result as echo %var% >file.txt if %var% is a digit, or ends with a space then a digit

C:\>set var=8

C:\>echo %var%
8

C:\>echo %var%>test.txt
ECHO is on.

C:\>echo %var% >test.txt

C:\>



Hi,
Thanks for responding to my post. But, That didn't work. I did notice there is a wrinkle to the process. I run the utility from the command window, but it opens up another DOS window and the output shows up there. I'm not sure what is going on.

ThanksAh. I didn't read your first post properly. I thought it said xcopy. Now I see you are using xxcopy, (which looks like a regular console program but isn't) I suggest you study the xxcopy documentation (the chm file) (in the downloaded installation zip archive) and the FAQs on the web site especially the logging options, which look like the /Oa and /On switches.
7175.

Solve : Modify Title for a lot of songs?

Answer»

Running Windows 8.1, been playing some Audiosurf. I have a lot of songs, but I found out I can add TAGS to them to alter gameplay http://www.audio-surf.com/forum/index.php/topic,3784.0.html. Is there a simple way to add text to the title of songs (like in file properties->details->title) without loosing the existing title or altering the filename other than doing manually?

Ask any other details needed and thanks in advance!Are they MP3 format songs?Quote from: foxidrive on January 04, 2014, 09:14:30 PM

Are they MP3 format songs?

MP3 can have tags at the beginning and END of the songs that have descriptions ETC with the beginning ID3 tags (V2.x) usually being the most commonly used these days.
You can get COMMAND line TOOLS to modify the ID3 tags.
7176.

Solve : BATCH PROGRAM TO RETRIEVE FILES ON WINDOWS 7?

Answer»

i would like to CREATE a batch program that searches for .csv file in numerous folders on a directory. if the file is found in any folder it creates a new folder and PLACES all the files in it.

example my path is U:/WED/processin_folders within this location there are over 300 folders.
if i type lets say broward. the batch program should go through each folder to search for broward, when it is found it places the files in a new folder call RESULTS. there can be more than one broward files, or a broward in each folder.Just clarifying the task:

Quote from: dstyles on November 08, 2012, 08:05:39 PM

i would like to create a batch program that searches for .csv file in numerous folders on a directory. if the file is found in any folder it creates a new folder and places all the files in it.

Creates a new folder where?

Do you want the files moved or copied into it?

Quote from:
example my path is U:/WED/processin_folders within this location there are over 300 folders.
if i type lets say broward. the batch program should go through each folder to search for broward, when it is found it places the files in a new folder call RESULTS. there can be more than one broward files, or a broward in each folder.

What do you want to do with the duplicates? i want the files to be copied to the home directory U:/WED create a folder called RESULTS, EACH FILE IN the each folder is dated so there should not be any duplicatesQuote from: dstyles on November 08, 2012, 09:05:16 PM
i want the files to be copied to the home directory U:/WED create a folder called RESULTS,

Ok..

Quote from:
EACH FILE IN the each folder is dated so there should not be any duplicates

If they have the same filename then they can't all be put in the same folder, without overwriting the one that was there already.

If there were say 28 broward.csv files, how do you want to HANDLE them?we could rename each file example broward_1_(date) broward_2_(date) etc each in sequential orderThis is untested: click on it and type in your search term. It doesn't add the date to the filename as the filenames can already be sorted by date in your file viewer.

It adds a number after the filename. 0 is the first one, then 1, 2, 3 etc.

Code: [Select]@echo off
set var=
set /p "var=Type your search string for .csv files: "
if not defined var goto :EOF
set "source=U:\WED\processin_folders"
dir "%source%\*.csv" /b /s /a-d |find /i "%var%">filelist.tmp
for /f "delims=" %%a in (filelist.tmp) do call :NEXT "%%a"
del filelist.tmp
goto :EOF

:next
set c=0
md "%source%\Results" 2>nul
:loop
if exist "%source%\Results\%~n1_%c%%~x1" set /a c=c+1 & goto :loop
echo copying %1 to "%source%\Results\%~n1_%c%%~x1"
copy /b "%~1" "%source%\Results\%~n1_%c%%~x1"
goto :EOFTHANKS I WILL TEST IT
7177.

Solve : Batch File to Remove a bracket and delete the line after the bracket.?

Answer»

Hi ,,

I am newbiew to the batch script. I want a batch file to delete the first bracket[( ] in a line and delete the bracket followed by a semi colon like this ); upto End of Line.


Example:

The text will be like this in a file test.txt.

#define VERSION_MAJOR_NUMBER 3 (version number (3333) it ); // declaration.


Now, I want the output to be in a same file or in a DIFF name like mentioned below.

#define VERSION_MAJOR_NUMBER 3 version number (3333) it





Please explain me step by step to achieve the output. I would make it run through the line one character at a time, and have the character that it finds change it's context...
This code has been tested and works for what you want
Code: [Select]set string=#define VERSION_MAJOR_NUMBER 3 (version number (3333) it ); // declaration.
set out=out.txt
set in=test.txt

for /f "tokens=* usebackq" %%f in ("%in%") do (set string=%%f
call :main)
goto :eof

:main
set mode=lead
:loop
set char=%string:~0,1%
set string=%string:~1%
call :route[%mode%]
if not "%string%"=="" if not "%mode%"=="end" goto :loop
echo %secstring%>>"%out%"
goto :eof

:route[lead]
if "%char%"=="(" (set mode=mid
goto :eof)
set secstring=%secstring%%char%
goto :eof

:route[mid]
if "%char%"==")" (set mode=testclose
goto :eof)
set secstring=%secstring%%char%
goto :eof

:route[testclose]
if "%char%"==";" (set mode=end
goto :eof)
set secstring=%secstring%)%char%
set mode=mid
goto :eof



There's the code, if you specifically want an explanation, then I can explain how it works.

[EDIT] I added the part that takes the INPUT from test.txt... misread the OP originally.
you can use sed.exe. downlaod from here

Code: [Select]@echo off
For /f "tokens=*" %%a In ('type test.txt ^|sed "s/(//" ^| sed "s/);.*//"') do (
echo %%a
)

Rem sed "s/(//" remove the first (
Rem sed "s/);.*// remove last bracket followed by ; and everything else.

Code: [Select]C:\>test.bat
#define VERSION_MAJOR_NUMBER 3 version number (3333) it
Hi Briandams,



Thanks for your valuable REPLY on this forum.
I tried it. but its not working for me. pls expalin the steps to try this. because i havent try like this before. Pls expalin step by step

7178.

Solve : Batch file OR...?

Answer»

I need a program OR batch file to create empty text (.txt) files based upon the first file.

For example: If the first text file is named 110612.txt i would like for the next one to be named 111312.txt (+7 days). If this is not possible, would it be possible to create and name the files in sequence... 001.txt, 002.txt, 003.txt... etc.?

I am thinking of a file that i could run... add the "prefix" for the text file... and the program would create "X" amount of files.

Is this possible?

Background... i have a PHP counter script for a web site that requires blank text files for each date. Instead of creating each file individually, i am looking for automation.It's easy to create a sequence.

This steps from 1001 to 1008 by 1 and then TAKES the last three digits to GET a zero-padded number.

Code: [Select]@ECHO off
setlocal enabledelayedexpansion
for /L %%b in (1001,1,1008) do (
set num=%%b
set num=!num:~-3!
type nul >"!num!.txt"
)
echo done
pauseBlue is a batch file, green is a screen grab of running it

@echo off
echo MyMonth = Monthname(wscript.arguments(0),True) > DateJump.vbs
echo MyDay = wscript.arguments(1) >> DateJump.vbs
echo MyYear = wscript.arguments(2) >> DateJump.vbs
echo MyJump = wscript.arguments(3) >> DateJump.vbs
echo MyNumber = wscript.arguments(4) >> DateJump.vbs
echo MyStartDate = MyMonth ^& " " ^& MyDay ^& " " ^& MyYear >> DateJump.vbs
echo MyInterval = "d" >> DateJump.vbs
echo wscript.echo FormatDate(MyStartDate) >> DateJump.vbs
echo for j = 2 to MyNumber >> DateJump.vbs
echo MyNewDate=DateAdd(MyInterval,MyJump,MyStartDate) >> DateJump.vbs
echo wscript.echo FormatDate(MyNewDate) >> DateJump.vbs
echo MyStartDate=MyNewDate >> DateJump.vbs
echo next >> DateJump.vbs
echo Public Function FormatDate (MyDate) >> DateJump.vbs
echo MyNewM = Month (MyDate) >> DateJump.vbs
echo MyNewD = Day (MyDate) >> DateJump.vbs
echo MyNewY = Year (MyDate) - 2000 >> DateJump.vbs
echo if MyNewM ^< 10 Then MyNewM = "0" ^& MyNewM >> DateJump.vbs
echo if MyNewD ^< 10 Then MyNewD = "0" ^& MyNewD >> DateJump.vbs
echo FormatDate = MyNewM ^& MyNewD ^& MyNewY >> DateJump.vbs
echo End Function >> DateJump.vbs
set /p mm="Start month: "
set /p dd="Start Day: "
set /p yy="Start Year: "
set /p jj="Jump days: "
set /p ff="No of files: "
for /f %%A in ('cscript //nologo DateJump.vbs %mm% %dd% %yy% %jj% %ff%') do (
echo Create %%A.txt
type nul > %%A.txt
)
Del DateJump.vbs
echo Done
pause



C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>dir
Volume in drive C is Win07
Volume SERIAL Number is E4DB-A92A

Directory of C:\Batch\Test\After 14-10-2012\WeeklyDate\Test

07/11/2012 21:00 <DIR> .
07/11/2012 21:00 <DIR> ..
07/11/2012 20:59 2,012 JD005.bat
1 File(s) 2,012 bytes
2 Dir(s) 31,607,975,936 bytes free

C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>jd005.bat
Start month: 11
Start Day: 7
Start Year: 2012
Jump days: 7
No of files: 6
Create 110712.txt
Create 111412.txt
Create 112112.txt
Create 112812.txt
Create 120512.txt
Create 121212.txt
Done
Press any key to CONTINUE . . .
C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>dir
Volume in drive C is Win07
Volume Serial Number is E4DB-A92A

Directory of C:\Batch\Test\After 14-10-2012\WeeklyDate\Test

07/11/2012 21:01 <DIR> .
07/11/2012 21:01 <DIR> ..
07/11/2012 21:01 0 110712.txt
07/11/2012 21:01 0 111412.txt
07/11/2012 21:01 0 112112.txt
07/11/2012 21:01 0 112812.txt
07/11/2012 21:01 0 120512.txt
07/11/2012 21:01 0 121212.txt
07/11/2012 20:59 2,012 JD005.bat
7 File(s) 2,012 bytes
2 Dir(s) 31,607,975,936 bytes free

C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>








Thank you! You are AWESOME!

7179.

Solve : Parse file names and rearrange variables for new name?

Answer»

I'm trying to RENAME a group of files that are named like this "KSFO-AM 05 to 10 (KSFO) 11_13_12 02.mp3" where I want to parse the name by the spaces found in the name and then re-arrange the name. I'm trying to use the FOLLOWING command:

for /f "tokens=1-7 usebackq delims=" "" %%A in ('dir /b ""KFSO-AM *02.mp3""') do Rename ""%%A %%B %%C %%D %%E %%F %%G"" "%%A%%C%%D%%G"

I'm not sure what I'm doing wrong... Must have something to do with spaces because I've used this parsing by other characters...

Thanks for any help!1. If you specify backq in the options block you should use backquotes to surround the command in the dataset. You used single QUOTES which are not the same.

2. Not sure what is going on in the options block. Looks weird at the end with all those quotes. See below. (You don't QUOTE a space in the options block; you just do delims= ")

3. You got the S and F opposite ways around in the dir /b wildcard and in the file name format. You showed the file format as KSFO-AM bla bla bla whereas dir /b is looking for filespec KFSO-AM bla bla bla

4. You seem to be too fond of quotes!

Having fixed these things and made the loop multiline I came up with this

(I have one file called KSFO-AM 05 to 10 (KSFO) 09_13_12 02.mp3 in the folder)

@echo off
for /f "tokens=1-7 usebackq delims= " %%A in (`dir /b "KSFO-AM *02.mp3"`) do (
echo Tokens:
echo A %%A
echo B %%B
echo C %%C
echo D %%D
echo E %%E
echo F %%F
echo G %%G
echo Command:
echo Rename "%%A %%B %%C %%D %%E %%F %%G" "%%A%%C%%D%%G"
)


Result:

Tokens:
A KSFO-AM
B 05
C to
D 10
E (KSFO)
F 09_13_12
G 02.mp3
Command:
Rename "KSFO-AM 05 to 10 (KSFO) 09_13_12 02.mp3" "KSFO-AMto1002.mp3"
I believe the quotes were trying to account for problems I was having with the wrong file name and going way down the wrong road! Thanks a lot for your help!

7180.

Solve : Creating Batch File...?

Answer»

Good Afternoon,

I was hoping someone could help. I seem to be struggling setting up a batch file for such a simple command. Basically what I want is 2 folders copying to an external hard drive. Below is what I want

c:/mail signature to E:\Backup
C:/my documents to E:\Backup

Any help would be great

Thanks in advance
Emmaxcopy "C:\My Documents" "E:\Backup\My Documents" /H /E /S /-Y /J
xcopy "C:\Mail Signature" "E:\Backup\Mail Signature" /H /E /S /-Y /J

Ready the 'xcopy /?' to verify all the settings you want are enabled.
Hello,

thanks for responding. One other thing..is there any way of showing a progress bar or percentage of what its copied already?

Regards
EmmaAdd /z to the end. See if that works the way you want it to.Hi Foxidrive, I did that but it DOESNT seem to work........?Sorry, my MISTAKE. It only works across a network, and it doesn't give a total progress bar.Quote from: elj on December 23, 2013, 02:59:50 AM

Hello,

thanks for responding. One other thing..is there any way of showing a progress bar or percentage of what its copied already?

Regards
Emma

if you have exhausted all possible ways, you can do your own progress bar through hardcore programming , or you could search for an already made tool that ties in to copying of files and showing you the progress. In the first place, if you want to see progress bar, it means you are not automating it? so another way is to search for GUI based "xcopy".

to do your own hard core programming in your favourite language.
Code: [Select]filesize = get total file size
somesize = some KB value less than total file size
while true
do
read file with somesize bytes
display progress bar if somesize still less than filesize
sizeleft = filesize - somesize
check to see if all bytes is read from file.
if all read, get out of loop
done
I have no idea about programming unfortunately I wish I did as most things I do would be so much easier....... I think I will leave the progress bar out but I have put echo on so it shows me what files its copying so I'll just stick with that for the time being.

Thanks EVERYONE for all your help.

Happy Christmas

EmmaThis isn't perfect; you won't get a dialog sometimes for a short-time operation e.g. small number of files with no conflicts -

You can use Visual Basic Script to show the Windows copy progress dialog

1. Save this script somewhere with the .vbs extension (e.g. CopyProg.vbs)

Const FOF_CREATEPROGRESSDLG = &H0&
strSourceFileSpec = wscript.arguments(0)
strTargetFolder = wscript.arguments(1)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strTargetFolder)
objFolder.CopyHere strSourceFileSpec, FOF_CREATEPROGRESSDLG

Call it from a batch like this

1. To copy all files and subfolders from the folder C:\My Documents to the folder D:\Targetfolder (which MUST already exist)

Note: On my system I need the \*.* after the source folder

wscript "c:\scripts\CopyProg.vbs" "C:\My Documents\*.*" "D:\Targetfolder"

2. To copy one file from one place to another

wscript "c:\scripts\CopyProg.vbs" "C:\batch\addup.cmd" "D:\batch"

Remarks: You may find you only get a dialog for a long operation or if target files already exist; for one or a few small files from one local hard drive to another the copy happens too quickly; if target files already exist you will be asked for skip/overwrite/rename options.

You don't need to include the full vbs file path if it is in the same folder as the batch script.

Tested on Windows 7

Alternative: install something like Teracopy and study the command line options (may not be an option in a workplace computer) (You can make Teracopy replace the Windows file copy dialog)

CopyProg.vbs syntax:

[cscript|wscript] Copyprog.vbs [move|copy] source dest flags

If no flags specified, there is a dialog for non-instant operations, and all file replace/overwrite options are presented to the user, in a dialog with a "Cancel" button.

Use quotes around source and dest if they have spaces.

Flags:

4 Don't display a progress box
8 Rename if target file already exists
16 Respond with "Yes to All "for any dialog box
64 Preserve undo information, if possible
128 Operate on files only if *.* is specified
256 Display a progress dialog but do not show file names
512 Don't confirm creation of new directory
1024 Don't display a user interface if an error occurs
2048 Don't copy security attributes
4096 Local directory only (no recursion)
8192 Only copy the specified files

Examples:
Wscript CopyProg.vbs copy "c:\batch" "D:\batch" 8 16 512
Cscript CopyProg.vbs move "d:\copysource\batch\001-999.txt" "E:\test"

Code: [Select]iFlags = 0
For j = 3 to (wscript.arguments.count)-1
iFlags = iFlags + Cint(wscript.arguments(j))
Next
strSourceFileSpec = wscript.arguments(1)
strTargetFolder = wscript.arguments(2)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strTargetFolder)
If lcase(wscript.arguments(0)) = "copy" Then
objFolder.CopyHere strSourceFileSpec, iFlags
End If
If lcase(wscript.arguments(0)) = "move" Then
objFolder.MoveHere strSourceFileSpec, iFlags
End If






7181.

Solve : Help Needed with document copy and rename?

Answer»

Hello to everyone

I'm new to DOS and i need some help with something that i have to do. I'll try to give as much detail as i can.

I have a folder(let's name it folder1) with several subfolders that include many documents(more than 4500) of 4 different types: excel(.xls & .xlsx), word( .doc % .docx), powerpoint(.ppt & .pptx) and pdfs.

I need to make a copy(let's name it folder2) of this big folder(folder1) but i have to replace the documents with blank ones but with the same title.

I thought that what i should do is to create blank documents of those types, and then make a batch file that will create the folders and the subfolders that exist at folder1, and then check the documents that exist there, copy the blank document from where i saved it and paste it in the new made folder in folder2 and give the name that this document had in folder1.

But i'm confused on how to use the dos commands to do all those commands with that sequence.

Can someone please help me with this?
Thanks in advanceMake sure that the source and destination formats are as shown, with trailing slash/and wildcards.

Code: [Select]@echo off
SET "source=c:\folder1\*.*"
set "dest=c:\folder2\"

xcopy "%source%" "%dest%" /t/e
for /f "tokens=2 delims=>" %%a in ('xcopy "%source%" "%dest%" /s/h/e/k/f/c/l') do (
for /f "tokens=*" %%b in ("%%a") do type nul >"%%b"
)
pauseThank you for your fast reply. I tried your code but there was an error(my OS is at greek and i'm not sure what is the proper translation in english but the message if i'm translating corectly is that "Cannot perform a cyclic copy" typed two times and then it prompts me to press any button to continue and when i do it it shuts down.
Let me give you some extra information.
My source folder is C:\Users\DM\Dropbox(what i named folder1) and that my destination folder is C:\Users\DM\Desktop\drop2.
(in case it is needed i made a blank document of each type of documents that are contained in folder1 in C:\Users\DM\Desktop\blank)

I changed in the code you gave me LIKE that

Code: [Select]@echo off
set "source=C:\Users\DM\Dropbox*.*"
set "dest=C:\Users\DM\Desktop\drop2"

xcopy "%source%" "%dest%" /t/e
for /f "tokens=2 delims=>" %%a in ('xcopy "%source%" "%dest%" /s/h/e/k/f/c/l') do (
for /f "tokens=*" %%b in ("%%a") do type nul >"%%b"
)
pauseDo i have to do something else?
Also this code will also create the subfolders that exist in folder1?
Again thank you very muchChange this line
set "source=C:\Users\DM\Dropbox*.*"

to this
set "source=C:\Users\DM\Dropbox\*.*"

It will create the folder structure, and a set of zero byte files with the name of the original documents.It works now, thank you very much. You just saved me from a lot of hours.
I wish you the best.

PS: Except the thanks button bellow, is there any other way to give you some "CREDITS" here?I'm pleased to hear it helps you - that's the best kind of feedback we can get.

The thanks button is used by the observant and interested people.Sorry if i'm being annoying.
Again i'm trying to translate from greek the "warnings" on cmd.
It types 2 times "memory is not enough"
Then 9 times "The system cannot LOCATE the disk(or drive) path specified" (it's one of the two drive/disk i think.)
Then 5 times "File name syntax, directory or volume label is incorect"

I tried to change some of the commands on your code with no luck, and after reading a while i'm not sure if the problem is because the number of characters that cmd can process is limited or something else. I'm SAYING that because there are some documents that i want to copy that are as "deep" as on the 7th or 8th subfolder (and some of them have big names)

The code is working but of a total of 9186 documents it is copying 1586
Thanks againI have to add that i checked and found that it stacks on an htm file that has the "<>" on its name.Quote from: jimakos05 on December 23, 2013, 08:05:29 AM

I have to add that i checked and found that it stacks on an htm file that has the "<>" on its name.

They are illegal filename characters in Windows - but there are similar looking ones in Unicode.

Unicode and foreign language characters are often problematic in batch files. You have to use the right
code page with non-English characters, using the CP command in the beginning of the batch file, and
if it is Unicode then that will fail in many ways with batch code. VB Script is a better choice there.

It's also possible that your path\filename length is too long for some of them too.
7182.

Solve : Specific Key press detection?

Answer»

Hello there!

I was MAKING a COMPLICATED batch program when I decided I wanted the user to be able to say press 1 to do something, and press 2 to something else.

I have seen it done before. Heck, I even copied it into notepad and ran it before, but I did not save it.

Any method will work fine, but I would prefer something maximum of 10 lines if possible.

Thank you in advance.for getting user input in DOS batch, use set /pMore secure, in windows 7 use "choice"As mentioned above:

choice.exe is not AVAILABLE in XP but it has the advantage of single key entry to do things.
For XP you can use choice.exe from Win9x etc or GET a clone of it, which you can find with google.

type choice /?
for the help.Thank you very much, Lemonilla and foxidrive, I did choice /? and got the INFORMATION I needed.
From what I had read, I thought Choice.exe was a sort of plugin, and If I wanted to share the program, that wouldn't be good.
Now, I know different though.
I suppose that means this case is CLOSED!
exit "Topic: Specific Key press detection.bat"

7183.

Solve : Exporting / Importing File names from https to Excel / Word?

Answer»

Quote from: foxidrive on November 16, 2012, 07:34:33 AM

So you take you bat and ball and go home rather than work *with* the people that are SOLVING your problem - for free.

Sir, I think I said I'm sorry and immensely thankful:)This will only work if all the files are .wav files.

EDITED: to ADD a delims section

Code: [Select]@echo off
del "output file.txt" 2>nul
for /f "delims=" %%a in (listofserialnumbers.txt) do (
for /f "delims=." %%b in ('find "-%%a-" ^< "list of files.txt"') do (
>>"output file.txt" echo %%b.wav
)
)Quote from: foxidrive on November 16, 2012, 07:54:53 AM
This will only work if all the files are .wav files.

EDITED: to add a delims section

Code: [Select]@echo off
del "output file.txt" 2>nul
for /f "delims=" %%a in (listofserialnumbers.txt) do (
for /f "delims=." %%b in ('find "-%%a-" ^< "list of files.txt"') do (
>>"output file.txt" echo %%b.wav
)
)

It definately did. Thanks again!
7184.

Solve : Batch Parser?

Answer» QUOTE from: Lemonilla on December 19, 2013, 02:02:00 PM
@echo off
REM set start of loop1
:loop1
REM set %a% to 100,000
set a=100000
REM set the start of the loop2
:loop2
REM increment %a% by 1
set /a a +=1
REM display %a% value
echo %a%
REM set close of loop2 in if statment
if not "%a%"=="1000000" goto :loop2
REM go back to loop1 to reset %a%
goto :loop1



Use this concept, hopefully it's what you need.

Thanks, that should provide me with the idea I need... should be able to get what I need from that.

I just need it as a kind of error-handling... the script will be executed about once a day, so it'll take a few years to reach the max number.
I just want to add that functionality soon, in case we all forget about that and a few years from now the SCANNERS won't recognise the barcodes because the numbers are too HIGH


@patio: I adore words which aren't heard as often in modern times...

@ghostdog: I learned some perl a few years back, but the computer on which this script is running is quite the oldtimer, so I don't want to impair the performance by adding further runtimes or so... that's why I want to try it using windows internal means... Quote from: rioc on December 20, 2013, 01:49:35 AM
@patio: I adore words which aren't heard as often in modern times...

I too have a love of English - crazy language that it is, with so many pitfalls for those learning it as a second language.

Quote from: rioc on December 19, 2013, 05:20:58 AM
Bligh me...

I think you mean 'blimey' from the LAND of Mad Englishmen.

Also, to make it easier to keep track of the number you are on, keep in mind you can do this:
'set /p a=<Text.txt' to grab the first line of a text file into %a%.
7185.

Solve : Batch file problem: is not expected at this time/moment?

Answer»

Hello,
i have a problem with a batch file. i om working for this code 2 ours, its not finished yet.
but when i start the file, it does everything but when it comes to the middle. it stops, like "exit"
i put --------------------- on the last PUNT it shows

the code:
Code: [Select]@echo off
:beveiliging1
if not exist "%appdata%\.minecraft\accounts" goto first_startup_settings
if exist "%appdata%\.minecraft\accounts" goto beveiliging2

:first_startup_settings
title First startup instalation
md %appdata%\.minecraft\accounts
md %appdata%\.minecraft\accounts\accounts
md %appdata%\.minecraft\accounts\settings
md %appdata%\.minecraft\accounts\minecraft
echo Instalation is succesfully finished
pause
del "first_startup"
goto beveiliging2

:beveiliging2
if not exist "%appdata%\.minecraft\accounts\name.txt" goto start2
if exist "%appdata%\.minecraft\accounts\name.txt" goto start3

:start2
set name=!missing!
goto beveiliging3

:start3
title minecraft username veranderen.
for /f "Delims=" %%a in (%appdata%\.minecraft\accounts\name.txt) do (

set name=%%a

)
goto beveiliging3

:beveiliging3
if exist "%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt" goto menu
if not exist "%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt" goto beveiliging3_1

:beveiliging3_1
cls
echo copy and paste the locations of the following things,
echo if you don't use some of those
echo download it, ore say none
echo as exemple of mincraft: C:\Users\%random%\AppData\Roaming\.minecraft
echo.
set /p mineshafter__location=copy and paste te location of mineshafter:
set /p minecraftsp__location=copy and paste te location of minecraftsp:
set minecraft_location=%appdata%\.minecraft\minecraft.exe
if %mineshafter__location%==none goto break_1
set mineshafter_location=%mineshafter__location%\mineshafter-proxy.jar
if %minecraftsp__location%==none goto break_2
set minecraftsp_location=%minecraftsp__location%\minecraftsp.jar
goto beveiliging3_3

:break_1
set mineshafter_location=none
goto beveiliging3_2

:break_2
set minecraftsp_location=none
goto beveiliging3_3

:beveiliging3_2
cls
if %minecraftsp__location%==none goto beveiliging3_3
set minecraftsp_location=%minecraftsp__location%\minecraftsp.jar
goto beveiliging3_3

:beveiliging3_3
cls
echo this is ride?
echo %mineshafter_location%
set /p beveiliging3_3_1=Yes/No :
if %beveiliging3_3_1%==No goto exit_reload
if %beveiliging3_3_1%==Yes goto beveiliging3_4
goto beveiliging3_3

:beveiliging3_4
echo %mineshafter_location% > "%appdata%\.minecraft\accounts\minecraft\mineshafterlocation.txt"
cls
echo this is ride?
echo %minecraftsp_location%
set /p beveiliging3_3_2=Yes/No :
if %beveiliging3_3_2%==No goto exit_reload
if %beveiliging3_3_2%==Yes goto beveiliging3_4_0
goto beveiliging3_4

:beveiliging3_4_0
echo %minecraftsp_location% > "%appdata%\.minecraft\accounts\minecraft\minecraftsplocation.txt"
echo %minecraft_location% > "%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt"
goto menu

:menu

for /f "Delims=" %%c in (%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt) do (

set minecraft_loc=%%c

)

for /f "Delims=" %%d in (%appdata%\.minecraft\accounts\minecraft\minecraftsplocation.txt) do (

set minecraftsp_loc=%%d

)
for /f "Delims=" %%e in (%appdata%\.minecraft\accounts\minecraft\mineshafterlocation.txt) do (

set mineshafter_loc=%%e

)
pause
if %minecraftsp_loc%==none set minecraftsp_loc=""
if %mineshafter_loc%==none set mineshafter_loc="'
pause
goto menu_start

:menu_start
title minecraft username veranderen. nu actief: %name%
cls
echo naar wie wil je veranderen?
set /p keuze= Hoe heet de avatar:
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%" goto a
if not exist "%appdata%\.minecraft\accounts\accounts\%keuze%" goto b

:a
copy "%appdata%\.minecraft\accounts\accounts\%keuze%" "%appdata%\.minecraft\lastlogin%"
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%_minecraft" start %appdata%\.minecraft\minecraft.exe
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%_mineshafter" start %
echo %keuze% > "%appdata%\.minecraft\accounts\name.txt"
pause
goto beveiliging1

:b
cls
echo wat gebruik je?
set /p keuze2= minecraft of mineshafter:
if %keuze2%== minecraft start %appdata%\.minecraft\minecraft.exe
if %keuze2%== mineshafter start C:\Users\luke\Documents\Bureaublad\minecraft\Minecraft\mineshafter-proxy.jar
pause
cls
echo typ je NAAM EN wachtwoord in %keuze2% en login
echo.
pause
cls
echo als je dat gedaan hebt, en je bent ingelogd
echo sluit %keuze2%
pause
cls
echo gelukt?
set /p keuze3= ja/nee:
if %keuze3%== ja goto c
if %keuze3%== nee goto b
pause
exit

:c
copy "%appdata%\.minecraft\lastlogin" "%appdata%\.minecraft\accounts\accounts\%keuze%"

goto menu

:exit_reload
echo pleas restart this application
pause
exit[/size]

here a small version where it GOES rong:
Code: [Select]:menu

for /f "Delims=" %%c in (%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt) do (

set minecraft_loc=%%c

)

for /f "Delims=" %%d in (%appdata%\.minecraft\accounts\minecraft\minecraftsplocation.txt) do (

set minecraftsp_loc=%%d

)
for /f "Delims=" %%e in (%appdata%\.minecraft\accounts\minecraft\mineshafterlocation.txt) do (

set mineshafter_loc=%%e

)
pause
if %minecraftsp_loc%==none set minecraftsp_loc=""
if %mineshafter_loc%==none set mineshafter_loc="'
pause
goto menu_start

:menu_start
title minecraft username veranderen. nu actief: %name%
cls
echo naar wie wil je veranderen?
set /p keuze= Hoe heet de avatar:
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%" goto a
if not exist "%appdata%\.minecraft\accounts\accounts\%keuze%" goto b
or view on: http://mibpaste.com/btsa0N

thank youTry wrapping these in double quotes - there could be long filename elements in the paths that need them.


"%minecraftsp_loc%"

"%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt"

set "minecraftsp_loc=%%d" and the other variables.

if "%minecraftsp_loc%"=="none" set minecraftsp_loc=""Wouw, It works thank you for command me
Thank you very muchnow i have an other problem,
on the same file.

the code:
Code: [Select]:menu

for /f "Delims=" %%c in (%appdata%\.minecraft\accounts\minecraft\minecraftlocation.txt) do (

set minecraft_loc=%%c

)

for /f "Delims=" %%d in (%appdata%\.minecraft\accounts\minecraft\minecraftsplocation.txt) do (

set minecraftsp_loc=%%d

)
for /f "Delims=" %%e in (%appdata%\.minecraft\accounts\minecraft\mineshafterlocation.txt) do (

set mineshafter_loc=%%e

)
if "%minecraftsp_loc%"=="none" set minecraftsp_loc2=""
if "%mineshafter_loc%"=="none" set mineshafter_loc2="'
if not "%minecraftsp_loc%"=="none" set minecraftsp_loc2=minecraftsp
if not "%mineshafter_loc%"=="none" set mineshafter_loc2=mineshafter
goto menu_start

:menu_start
title minecraft username changing. now active: %name%
cls
echo How CALLS the username you wanne use?
set /p keuze= Username:
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%" goto a
if not exist "%appdata%\.minecraft\accounts\accounts\%keuze%" goto b

:a
for /f "Delims=" %%d in (%appdata%\.minecraft\accounts\minecraft\%keuze%_start.txt) do (

set start_fenster=%%d

)
copy "%appdata%\.minecraft\accounts\accounts\%keuze%" "%appdata%\.minecraft\lastlogin%"
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%_minecraft" start %appdata%\.minecraft\minecraft.exe
if exist "%appdata%\.minecraft\accounts\accounts\%keuze%_mineshafter" start %
echo %keuze% > "%appdata%\.minecraft\accounts\name.txt"
start %%start_fenster%_log%
pause
goto beveiliging1
at onn of the least lines "start %%start_fenster%_log% how can i fix this, so it works
%start_fenster% comes from a text file
%..._log% is the location

i need to make the location again, or is is possible to make 2 %...% togetter 1 output

thank youI think this is what you want. Also, when you double quote the term you also need to provide empty double quotes after the start command - as that is an empty title command.

start "" "%start_fenster%%_log%"

7186.

Solve : Inconsistant results from batch file coding..?

Answer»

Hi all,
I am writing a batch file to check if data was entered into a database.

The batch file calls text files that run database queries and return the results in individual files.
The batch file then checks to see if these newly created files have data. If they have 0 bytes (no data) an email is sent out warning that data was not recorded. If they have more than 0 bytes (data returned from the query) then the email section is skipped and another test on another query is begun. This happens until all checks are completed.

The problem I am having is that I am getting inconsistant returns, meaning that the batch file is sending emails out when it shouldn't.
Is this a problem with the way I am coding this batch file?
I could use any help offered as I am pretty new at this sort of thing.


REM **** Start of opstats daily data check ****
REM **** Running SQLs to extract data if exists ****
d:
cd \opstats\verifydata
mysql < d:\opstats\verifydata\climate.txt
mysql < d:\opstats\verifydata\as400utilization.txt
mysql < d:\opstats\verifydata\rs6000utilization.txt
mysql < d:\opstats\verifydata\midnightprocess.txt
mysql < d:\opstats\verifydata\3rdshiftbills.txt
mysql < d:\opstats\verifydata\rs6000fullbu.txt
mysql < d:\opstats\verifydata\rs6000incbu.txt
mysql < d:\opstats\verifydata\rs6000jnlbu.txt


REM **** Pause to let SYSTEM catch up with happenings ****
TIMEOUT 50
cls
REM **** Something to check ****

cd \opstats
dir *.*
REM ****Begin process of checking for files****
REM ****Emails will be sent out if no data exists as a result of a query ****
:check1
TIMEOUT 5
cls
cd \opstats
dir climateReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check2

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing Climate Data" -f Statistics_Database


:check2
TIMEOUT 5
cls
cd \opstats
dir as400UtilizationReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check3

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing AS400 Utilization Data" -f Statistics_Database


:check3
TIMEOUT 5
cls
cd \opstats
dir rs6kUtilizationReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check4

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing RS6000 Utilization Data" -f Statistics_Database


:check4
TIMEOUT 5
cls
cd \opstats
dir midnightProcessReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check5

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing Midnight Process Data" -f Statistics_Database


:check5
TIMEOUT 5
cls
cd \opstats
dir 3rdShiftBillReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check6

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing 3rd Shift Bill Data" -f Statistics_Database


:check6
TIMEOUT 5
cls
cd \opstats
dir rs6kFullBuReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check7

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing RS6000 Full Backup Data" -f Statistics_Database


:check7
TIMEOUT 5
cls
cd \opstats
dir rs6kIncBuReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto check8

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing RS6000 Incremental Backup Data" -f Statistics_Database


:check8
TIMEOUT 5
cls
cd \opstats
dir rs6kJnlBuReport.txt | c:\winnt\system32\find "0 bytes" > NUL
if %ERRORLEVEL% NEQ 0 goto end

cd \opstats\verifydata
blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject

"Stats DB Missing RS6000 Journal Backup Data" -f Statistics_Database


:end
TIMEOUT 5
cls
REM **** Data checking has completed ****
REM **** Clean up to begin next ****


:cleanup
del d:\opstats\climateReport.txt
del d:\opstats\as400UtilizationReport.txt
del d:\opstats\rs6kUtilizationReport.txt
del d:\opstats\midnightProcessReport.txt
del d:\opstats\3rdShiftBillReport.txt
del d:\opstats\rs6kFullBuReport.txt
del d:\opstats\rs6kIncBuReport.txt
del d:\opstats\rs6kJnlBuReport.txt
TIMEOUT 5
cls
REM ****ALL Processing and Cleanup is complete****
TIMEOUT 5There does not appear to be any GLARING logic errors in your code. Double check that the input files to mysql are doing what you think they are doing. For debugging purposes, turn off the deletes at the bottom of the file and manually check whether an email should have been sent or not.

Good luck. I've done all that, I have run it without the deletes to verify data or LACK of data to make sure the files were CORRECT. It seems as though it is not reading the filesizes correctly all the time.
For EXAMPLE, this morning when I came in I ran the batch file after reading the reply and it again did not run correctly.
When it got to the rs6kUtilizationReport.txt file which is 281 bytes it sent out an email, this should have not happened.
I deleted the files and with the same data being generated, the email did not get sent when I reran the batch file a second time.

What is the whole find "0 bytes" > NUL statement, I had found it online and seemed to be what I was looking for. What does it EXACTLY mean?
Is there a way to rephrase this statement to work for me? Is the statement just checking the last place of the file size area? Could it be rounding?
My deadline for this "simple" project is fast approaching...There are a few ways to do this, none of them pretty.

Code: [Select]
for /f "tokens=1-4" %%a in ('dir filename.ext ^| find "filename"') do (if %%d EQU 0 goto wherever)


Change filename, ext and wherever to something appropriate and replace your errorlevel checks with this line.

Hope this helps.

7187.

Solve : How to rename the file with file size?

Answer»

I POSTED some TIME BACK Quote

One of your % SIGNS is not doubled.

Did you FIX that?

7188.

Solve : Trying to run a cmdline on a dir of 1500+ files?

Answer»

I'm trying to run a commandline call but I need the batch FILE to insert the FILENAME for each call.

Given a dir of x amount of files, I want it to run:

c:&GT;mycommand.exe <filename> <somearguments> <filename>.inf

If would be great if I could filter the filelist like *.jpg (pseudocode):

foreach *.jpg {
c:>mycommand.exe <filename> <somearguments> <filename>.inf
}

Heck, if it's possible to pull the basename out, I'd rather have:

foreach *.jpg {
c:>mycommand.exe <filename> <somearguments> <basename>.inf
}

Any ideas?

TIAFOR /f "delims=\ " %%a in ('dir/b *.jpg') do COMMAND %%a

replace command with the command you like.
This for LOOP is working with the NT4.0 command line.
If you are using pure DOS the f switch is not working.

hope this helps
uli

7189.

Solve : Please Help Me (CMD Help)?

Answer»

Please I need a lot of help. Okay here's the problem
I am able to log on to an account and it is on a domain called DETNSW.WIN
I want to change my account to ADMINISTRATOR (by adding it to the administrators group)
The details don't come up when I type in:

net USER shoaib.farooq /domain

I have tried A LOT of variations of this but still can't get it to change into an administrator account.
Also I need to know how to ADD an account using cmd to the domain (I know the basic net user [username] /add)

Please, Please Help Me.
- ShoaibQuote from: shoaib.farooq on December 19, 2013, 01:23:08 AM

I am able to log on to an account and it is on a domain called DETNSW.WIN
I want to change my account to administrator (by adding it to the administrators group)

UNLESS you are an administrator, you won't be able to do that.
7190.

Solve : copy screen?

Answer»

I am using the DOS promt in windows XP. My PROGRAM is very simple, it does a graphic in the total screen of DOS, I have to copy this graphic to a program like paint brush or corel draw to invert the colors.

Can anyone HELP me, I have already tried ALT+PRINT SCREEN and only PRINT SCREEN, but it didn´t work.right click on the main dos window bar and choose "edit", then "select all"
then choose "edit" again then "copy"
then past it into SOMETHING.... hope that HELPS.

7191.

Solve : Create folders based on part of a filename?

Answer»

I'm really pulling my hair out on this one. I collect PICTURES of motorcycles, hot rod cars (especially Mustangs), and racing boats. I use bulk file renamer to place them in the following format:

KawasakiNinja300-001-001.jpg
KawasakiNinja300-001-002.jpg
KawasakiNinja300-001-003.jpg
KawasakiNinja300-002-001.jpg
KawasakiNinja300-002-002.jpg
KawasakiNinja300-002-003.jpg
KawasakiNinja300-161-150.jpg

Sometimes the second part of the file name will not contain 3 NUMBERS but sometimes 2,1, or even 4. For example:

1990BlackMustangGT-01-01.jpg

LamborghiniCountach-1-01.jpg

And the list goes on with thousands of files in their respective directories.
The first part of the filename is the make and model of the vehicle. I use a hyphen as a separator to denote the numbered series that it belongs to and another hyphen to denote the INDIVIDUAL picture within the series. So essentially the filename is broken down into three parts using a hyphen as a separator.

I'm looking for a batch file that will move each file into a directory named after the numbers after the first hyphen and before the second hyphen (the second part of the filename).

Thank you so much.

Jason

Try this on a sample of your files - not the real set. It's UNTESTED. Run it from the root folder of your collection after testing.

If it works ok - remember not to run it twice on the same set of folders or it will create an extra level deep of folders.

Where it will have an issue is if any of the descriptive parts of the filename has a - in it. Say Kawasaki-Jawa-001-002.jpg

Code: [SELECT]@echo off
for /f "delims=" %%z in ('dir /ad /b /s') do (
pushd "%%z"
for %%a in (*.jpg) do (
for /f "tokens=2 delims=-" %%b in ("%%a") do (
md "%%b" 2>nul
move "%%a" "%%b" >nul
)
)
popd
)
pause

7192.

Solve : NET TIME /SET fails with "System error 5 has occured. Access is denied"?

Answer»

When I attempt to set the time as follows:

NET TIME \\127.0.0.1 /SET

it works correctly.

When I attempt to set the time thus:

NET TIME \\local-ip-address /SET

I get the error message:

System error 5 has occured.
Access is denied.

I've verified that the FOLLOWING Group Permission is in effect and applies for the user in question:

Local Computer Policy + Computer Configuration + Windows Settings + Security Settings + Local Policies + User Rights Assignment + "Change the system time"

The Windows Time Service is started.

(both probably obvious because the loopback works)

"local-ip-address" machine has "Enable Windows NTP server" group permission enabled.

The error occurs REGARDLESS of whether the Firewall is enabled or disabled.

Windows XP SP3, Workgroup networking. A different client machine in the workgroup works, no problem.

Is there another Group Policy or Registry value that applies here?

Thanks in advance for your time and consideration.You lack administrator permsI think he's well aware of the cause - he's setting local policies and wants to know which setting needs to be changed.

As for the OP's question - it WOULD be a network permission I think, to utilise 'net time'.

7193.

Solve : how to echo line both on screen and text file?

Answer»

I want to display the output both on screen and log.txt file

like

ECHO %%a > log.txt

this is redirecting to txt file. i want on screen as well

is ther any way?The only way I know of is to echo the line twice.

Code: [Select]echo %%A > log.txt
echo %%A

I know it is an extra line, but is there any reason this won't work?Unlike most Nix SYSTEMS there is not a native way to do this in batch. You can use the TEE command on most NIX operating systems to do this. I believe there is a Win32 port of it if you really want to do this.Quote from: Squashman on NOVEMBER 29, 2011, 05:59:52 PM

Unlike most Nix systems there is not a native way to do this in batch. You can use the TEE command on most NIX operating systems to do this. I believe there is a Win32 port of it if you really want to do this.

There are plenty of Tee.exe programs around, not to mention any number of Tee.bat. Tee.cmd and Tee.vbs scripts. The most cursory of Google searches will turn up plenty of results, which it would be both tedious and redundant to reproduce here. In particular searching the Google archive of alt.msdos.batch.nt using INTELLIGENTLY chosen search terms is a fruitful method of finding solutions.

If the OP is using a business or school system where installation of third party EXECUTABLES is not allowed, then a cmd or vbs approach may be the only way.


You can use:

echo %%a >> log.txt
echo %%a

in one line, maybe use a pipe, fork, or do:

echo %%a >> log.txt && echo %%a

Thats your best option
7194.

Solve : Splitting a path using a string in DOS batch.?

Answer»

I am having a hard time figuring out how to split a string (a path) by another string. I ave SEEN a few posts regarding this, however, people are always splitting using a single character like a '\' for example.

I need to SPECIFICALLY split this:
C:\abc\def\ghi\jkl\

by this:
def

so I get this: C:\abd\ and this \ghi\jkl\

And I need to be able to address both PIECES. Basically, I need to find that foldername in a string, and it is NEVER in the same place in the path, otherwise I would just split by '\' and count up to that folder... cant do that. What I have now seems to search for each letter individually.

Any ideas? below is where i left off, trying to figure out how to put the foldername "project" after the delims part.

Code: [Select]rem assuming %1 is flder dragged onto .bat file

for /f "tokens=1* delims=<foldername???>" %%a in ("%1") do (
set part1=%%a
set part2=%%b
)

echo part1 = %part1%
echo part2 = %part2%

Thanks for any help you can give!
Ken
I think you can just do

Code: [Select]mkdir "C:\%part1%\%part2%\%part3%and on and on...The issue is not adding the parts... the issue is how to SPLIT the parts... because from what I can find, the portion after the delims= part ONLY looks for single characters... so if i put foldername as the thing to split by, it will split it into- f if it finds one, then o if it finds one, then l if it finds one.. which is not USEFUL for this... splitstring.bat

@echo off
REM YOU NEED THIS
setlocal enabledelayedexpansion

REM If the passed parameter string has any spaces you must quote it
REM we unquote it using ~
set PassedString=%~1

REM May as well do the same with string to split on
set DelimString=%~2

REM The delim string must appear exactly ONCE in the passed string

REM Replace the delim string with a symbol which will not be in the
REM path to be split, in this example I use @
set [emailprotected]
call set tempstring=!PassedString:%DelimString%=%splitsub%!

REM Use FOR to split the modified string
for /f "tokens=1* delims=%splitsub%" %%A in ("%tempstring%") do set part1=%%A & set part2=%%B

REM Show that the 2 variables contain the desired substrings
echo Passed = %PassedString%
echo Part1 = %part1%
echo Part2 = %part2%


Example output:

C:\>splitstring.bat "D:\Backup\mystuff\programming\Visual Basic\project\ABCDE\DEF" "project"
Passed = D:\Backup\mystuff\programming\Visual Basic\project\ABCDE\DEF
Part1 = D:\Backup\mystuff\programming\Visual Basic\
Part2 = \ABCDE\DEF

C:\>splitstring.bat "D:\Backup\mystuff\programming\Visual Basic\project\ABCDE\DEF" "mystuff"
Passed = D:\Backup\mystuff\programming\Visual Basic\project\ABCDE\DEF
Part1 = D:\Backup\
Part2 = \programming\Visual Basic\project\ABCDE\DEF



wow, awesome! I think this is exactly what I am looking for. Thanks very much for your explanation of the quotes and the expand option.

Cheers!
Ken
May want to use the back slashes to make sure it matches on a whole directory name if that is what your original intention was.

Code: [Select]call set tempstring=!PassedString:\%DelimString%\=\%splitsub%\!Two other notes.
If you are using the CALL you do not need to use delayed expansion. You can double up your percents and it will still work fine.
Code: [Select]call set tempstring=%%PassedString:\%DelimString%\=\%splitsub%\%%
If you remove then CALL then you need to use delayed expansion.
Code: [Select]set tempstring=!PassedString:\%DelimString%\=\%splitsub%\!Quote from: Squashman on November 22, 2012, 07:27:43 PM

If you are using the CALL you do not need to use delayed expansion. You can double up your percents and it will still work fine.

I spent about 30 frustrating minutes adding various numbers of percents and then gave up and went with delayed expansion.
7195.

Solve : Change default printer?

Answer»

Hi,
I asked this question in win 7 forum but maybe I went to the wrong place.
I have 2 programs which need to use different printers in windows 7.
I start them with a batch file. Is there a command I can use to change the default printer?
Regards
GeofflTry this:

http://www.robvanderwoude.com/2kprintcontrol.php

*Foxidrive beat me to ANSWERING, and if that trick works with 7 you should be all set. If it doesnt work with 7, you might have to go with my suggested method below of network share.

How are these printers CONNECTED (LPT, USB, ETHERNET, etc ) and are they shared over network?

Without a registry Hack, injecting different default printer info, I cant see you being able to do this on the fly on the command line,.... BUT you could share your printers and name them the same share, but only have 1 share active at a TIME which could be batched. To the program it points to just the shared printer name, and it prints. Your batch could designate which printer is the one with the active share!Hi,
Two printers on a network. Both shared. I use printer pooling to connect the network printer to LPT1 and use Net Use to to connect LPT1 to the computer.
It is old dos stuff printing to LPT1 and this sends it to the network.
Just bought a new HP 8100 printer. The old HP309 worked fine. but the new one is really strange. First print after boot is ok. Then it wont print or prints twice.
If I change the driver back to the 309 driver it works fine, but then it won't run some of my other ancient programs.
I WANT to have 2 x 8100 printers - one for my old stuff and another for my other old stuff
Geoffl

7196.

Solve : Batch Script for Reading text, removing and copying?

Answer»

Hi guys,

I am extremely new to batch scripts and just WROTE my own batch script a few moments ago to SIMPLY open a file.

I am using Windows 7!

What I WANT to do:

I want to create a batch script which:
1. Reads a text file in a folder on my desktop and then searches for the files listed inside a destination folder and removes them if they exist (The list has a lot of files)
2. It then brings up a prompt which asks which batch script I would like to use next in the same source folder on the desktop. I would answer this by pressing a number which is assigned to each batch script i.e. the number 1 executes ENB1.bat etc.

The purpose of the next batch script would be to again read the contents of the file Line-by-Line and copy them into the destination folder with the same name.
And then, take make to the destination file.

Some HELP:-

Source File of Text files and the Batch: C:\Users\User Name\Desktop\Skyrim Batch Files

The Following Files are inside the "Skryim Batch Files" Folder:

Batch Scripts: Remove All ENBs.bat, ENB1.bat , ENB2.bat , ENB3.bat
Text File checked to remove files: Remove ENBs.txt
Text File to Copy ENB's: ENB1 Files.txt , ENB2 Files.txt , ENB3 Files.txt

This isn't inside "Skyrim Batch Files" Folder:

Destination Folder: : D:\Skyrim - Copy

So Remove All ENBs.bat would check the destination folder for the files in Remove ENBs.text and remove them
2.The command prompt would then ask me which batch file I would like to execute next and it would look like this:

"Which Batch Script would you like to execute next?:" 1. ENB1 2. ENB2 3. ENB3

By pressing 1, it runs ENB1.bat. By pressing 2, it runs ENB2.bat etc

The ENB.bat files also read seperate text documents respectively which are: ENB1.bat ---> ENB1 Files.txt, ENB2 ---> ENB2 Files.txt, ENB3.bat ---> ENB3 Files.txt
They would then copy each PROGRAM written on one line each and then put them in the destination folder

Then the program would end.

I might be asking for a lot, but I would appreciate it if you could help me make the script. I would love you even more if you used my exact file names haha

Thanks for all the help!

~ Brya



This assumes certain things about the text files.

"Remove ENBs.txt" contains program names only and is not quoted.

Each other text file contains on each line the drive:\path\filename.ext and is not quoted.

The 4 batch files are below:


Code: [Select]:: Remove All ENBs.bat
@echo off
for /f "delims=" %%a in ( ' type "Remove ENBs.txt" ' ) do (
del "D:\Skyrim - Copy\%%a" 2>nul
)
set var=
set /p "var=Which Batch Script would you like to execute next?: 1. ENB1 2. ENB2 3. ENB3 "
call enb%var%.bat

::ENB1.bat
@echo off
for /f "delims=" %%a in ( ' type "ENB1 files.txt" ' ) do (
echo copying "%%a"
copy /b "%%a" "D:\Skyrim - Copy" >nul
)

::ENB2.bat
@echo off
for /f "delims=" %%a in ( ' type "ENB2 files.txt" ' ) do (
echo copying "%%a"
copy /b "%%a" "D:\Skyrim - Copy" >nul
)

::ENB3.bat
@echo off
for /f "delims=" %%a in ( ' type "ENB3 files.txt" ' ) do (
echo copying "%%a"
copy /b "%%a" "D:\Skyrim - Copy" >nul
)

*censored*

Thankyou for all the help. I should have stated if the paths were quoted but thatnkyou for specifying they weren't

You have saved me a lot of time and space.

Thankyou very much!

7197.

Solve : Help needed on renaming filenames with .bat?

Answer»

Hello forum users,

First of all, my English isn't perfect; sorry for that. I like to do some editing on the PC-games I play. Now I kind of have an issue which needs your help.

I have a map with files named like this: head_1234_0.rx3 There a around 1500 of them, the numbers are all different and linked to a database. These are original files.
I also have one head_x_bump.rx3 were the x should be CORRESPONDING to the 1234. I need all 1500 files to have a corresponding head_x_bump file. I can do this manualy, but that's too much work. That's why I created a bat file with the following code:Code: [Select]echo Enter number
set /p number=
COPY head_x_bump.rx3 head_%number%_bump.rx3
It works, but it's still a lot of work. I thougt that maybe it's possible to create a bat file wich "reads" the file names of the orriginal files.
I have no idea how to do this.

So is it possible to link the "1234" in the orginial filename to a copied en renamed head_x_bump file?


so basicly you have 1 copy of a file named "head_x_bump.rx3" and you need to make a bunch of copies of it replacing x with a number?

Code: [Select]@echo off
set end=####

for /l %%A in (1,1,%end%) do copy "head_x_bump.rx3" "head_%%A_0.rx3" && echo Copied number %%A.

echo . . . Done
pause>nul

Or you have a bunch of "head_####_bump.rx3 and need a corresponding head_####_0.rx3 file for each,

Code: [Select]@echo off
end=####

for /l %%A in (1,1,%end%) do copy "head_%%A_bump.rx3" "head_%%A_0.rx3" && echo Copied number %%A.
echo . . . Done
pause>nul



Where end equals the total number of files (assuming there are no skips in numbers).Lemonilla, you want the 2nd line of your 2nd script to be

SET end=####Quote from: Lemonilla on December 15, 2013, 11:43:30 AM

so basicly you have 1 copy of a file named "head_x_bump.rx3" and you need to make a bunch of copies of it replacing x with a number?

Exactly!I added a picture to as example.



I have around 1500 head_x_0.rx3 files that need a corresponding head_x_bump.rx3 (of which
I have one version that I need to copy with corresponding numbers). For exaple the head_260084_bump.rx3 is what I need to create. Problem is -as you can see- the numbers do skip.

So basicly I'm LOOKING to make a copy of the head_x_bump and get the numbers from the head_260074_0.rx3 in the name of bump file at the position of the x

This creates the extra files, using the numbers from the existing files.

Code: [Select]@echo off
for /f "tokens=2 delims=_" %%a in ('dir head_*_0.rx3 /b /a-d ') do type nul >"head_%%a_bump.rx3"Wauw, thnx!! It looks like it creates the files, but doesn't copy the original head_x_bump file. almost there My mistake - but it's a simple change.

Code: [Select]@echo off
for /f "tokens=2 delims=_" %%a in ('dir head_*_0.rx3 /b /a-d ') do copy "head_x_bump.rx3" "head_%%a_bump.rx3" >nulI tried the same, but now I see I added an unnecessary >

Thnx a lot, it works!
7198.

Solve : Dos and ">>" switch?

Answer»

Wondering if some one can shed some light on how to use the >> switch.
basically I'm USING this switch with the xcopy command so that a TXT file is generated to show me what FILES are being copied and at what time.
The problem that i'm having is that I need to manually delete those TXT files so that the batch file runn successfully again. I need to know if there is a way to over write those txt files while using the >> switch
this is what im using
Xcopy F:\VSS\*.* I:\VSS /S/y/r/d >>VSS.txt

THANKS in advance!The >> symbol is used to append DATA to an existing file, or create one if it doesn't exist. The > symbol is used to create a NEW file or write over an existing one.

The choice is yours. Choose wisely. Thanks that did the trick

7199.

Solve : use batch to change text file's font.?

Answer»

Is there a way to change the font of a text FILE? I want to take user input and WRITE a text file using a different font.There are no native BATCH ways to change word documents.

Batch itself has no font formatting commands.Quote from: foxidrive on November 25, 2012, 06:38:24 PM

There are no native batch ways to change word documents.

Batch itself has no font formatting commands.

Then they do exist, I'd just have to FIND one?*.txt (text) documents do not have included formatting for fonts, just PLAIN text.Quote from: Lemonilla on November 25, 2012, 06:03:52 PM
Is there a way to change the font of a text file? I want to take user input and write a text file using a different font.

Text files don't have fonts; this is something done by whatever program you are using to view the text file - Notepad for example.

Quote from: Lemonilla on November 25, 2012, 09:39:56 PM
Then they do exist, I'd just have to find one?

They don't exist.
7200.

Solve : Make batch file FIND file extentions and in txt?

Answer»

how do i MAKE a BATCH FILE that finds FILES or files by extension then make it put results in txt?dir *.txt > log.txt

finds all txt files and WRITES it in log.txt.uli