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.

7651.

Solve : Batch - Count processes?

Answer»

Can someone help me with counting the number of opened processes of hlds.exe

something like

Code: [Select]TASKLIST /NH | FIND /I "hlds"
IF %ERRORLEVEL%==0 (
echo hlds Running
)
IF %ERRORLEVEL%==1 (
echo hlds not Running
)
But here it SHOWS me if i have 3 hlds.exe processes opened, show the details of each , and then "hlds Running"

but i want to count the number of them


Thx Did you read the help for the FIND command?
Quote

H:\>find /?
Searches for a TEXT string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I IGNORES the case of characters when searching for the string.
/OFF[LINE] Do not skip files with OFFLINE attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
7652.

Solve : Use control key in batch file?

Answer»

hi
i need to run some application (EXE file) and at the start of the program i need to PRESS CTRL+R to RELOAD data from database
now i need to CREATE some batch file to do this step automatically it means that :
1- start the program
2- press ctrl+R keys
i know how should i run program with batchfile but i cant solve step 2
please help me to solve this problem
thanxCan't be done with pure batch.
Look at using AutoHotKey or AutoIt.

7653.

Solve : file name never exists?

Answer»

Hi all,
Im writing a batch program that opens python files. Basically, if the person doesnt drag a python file onto the batch it asks them for a path, if the file doesnt exist they have to type it again(if they type nothing it opens the interpreter). However, no matter what file path i type, right or wrong, it always says the file doesnt exist...

Code: [Select]@Echo off
cd C:\Python27

IF (%1) == () GOTO GETFILE
ELSE GOTO HAVEFILE

:GETFILE
Set /p file=Choose a file:
IF (%file%) == () GOTO HAVEFILE
IF NOT EXIST (%file%) echo No file found
Set file=
GOTO GETFILE
CLS
python %file%
pause

:HAVEFILE
CLS
python %1
pause
Any advice?Dump those brackets. Use double quotes like most PEOPLE. What made you use brackets anyway? They are useful in the IF (x) == () tests, where they detect null variables, but you cannot use them with a variable which is being passed to the SYSTEM as a filename. Suppose %file% expands to myfile.py then when you run IF NOT EXIST (%file%) you are asking the system if a file named (myfile.pi) -- complete with brackets -- exists. This does not happen with quotes which are good for accommodating filenames with spaces as they are stripped off by the system. So use double quotes for both tasks.

Code: [Select]IF NOT EXIST "%file%" echo No file found

Perfect! Thankyou! I havent made a batch file in a while, i knew to use brackets on the IF statements i just assumed it would be the same for the IF EXIST Quote from: jpotts on May 13, 2012, 01:42:22 PM

Perfect! Thankyou! I havent made a batch file in a while, i knew to use brackets on the IF statements i just assumed it would be the same for the IF EXIST

You don't have to use brackets around the things being compared in IF statements. You can use most of the character set EXCEPT for the special characters such as <>& etc. Most people use double quotes like this

IF "%variable%" == ""

IF "%animal%" == "horse"

etc


Oh, i didnt know that. Thanks!In fact you don't have to use anything surrounding a variable if you are comparing one thing with another e.g.

if %animal% == horse
if %var1% == %var2%

etc.

If you use bare variables you will be all right until one of them happens to be blank in which case the script will fail, which is why many batch CODERS routinely surround them with quotes or other characters in IF tests. Just keep the other characters away from filenames.

Of course you do need to surround the variable if you are comparing one thing with nothing (a blank)

if "%animal%" == ""
if .%animal%. == ..
if [%animal%] == []




7654.

Solve : Can I shut down my LapTop from DOS like the Win95/98 does it??

Answer»

Hello!

I am now the proud owner of an old Medion Pentium-1 with 32MB RAM memory and installed DOS v7.10 (but it also have Win95 working on it).

The Win95 is capable of turning the LapTop OFF.

But INSTEAD of the Win95 - I usually work only in plain DOS,
so I'm wondering can I do a Power-off (or shutdown) of my LapTop from DOS by EXECUTING some kind of a command that will power-off my laptop like the Win95 does?

Best regards
Brana
It was not a requirement in the MSDOS days as COMPUTERS all had physical power buttons, but a QUICK google shows this link which MENTIONS a utulity.

http://stackoverflow.com/questions/2019463/shutdown-computer-in-ms-dos-using-acpi



When no application is open then the only thing that is running is command.com and TSRs in RAM. It's safe to turn off the laptop at any time then.

7655.

Solve : Manipulate Output of Find /C command?

Answer»

I need to run a script that does the FOLLOWING:

Queries a server farm to find all servers in a "converged" state, counts the number of servers and then takes additional actions based on the count.

I'm starting with this:

Code: [Select]wlbs query <farm> /passw<password here> | find /c "converged"
On the farm I'm testing against the "converged" count is 16. If the count is greater than 3 then the script should proceed to run ANOTHER set of commands. If the count (output of find /c) is less than or equal to 3 then the script should terminate.

I tried this: Code: [Select] If wlbs <farm> /passw<password here> | find /c "converged" > 3 echo Greater than 3! but it doesn't work. It outputs the results to a file named "3". I'm hoping not to have to create a text file to hold the results of the find /c command.

The WLBS query is necessary but I don't have to use find if you have another suggestion.

Your help is certainly appreciated.

Thanks,

MJYou could use FOR /F to parse the output of wlbs and put it into a variable. Something like this: (I don't have a farm to TEST it on, but it will be something very like this) Of course you understand the IP and password are just examples.

Code: [Select]for /f %%A in ( ' wlbs query 10.50.100.10 /passw pass_word ^| find /c "converged" ' ) do set NumberOfConverged=%%A
if %NumberOfConverged% gtr 3 echo Greater than 3!
Notes:

Variable names are not case-sensitive: %NumberOfConverged%, %NUMBEROFCONVERGED% and %numberofconverged% are the same variable, in fact any mixture of cases is OK. I like using CamelCase personally because I think it is more readable.

In the FOR dataset (the part in the brackets) you need to escape the pipe SYMBOL by preceding it with a caret.

Also in the FOR dataset I have inserted extra spaces (which are ignored) so you can see the single quotes than enclose the command) more clearly.

In batch language the comparison operators are not > < etc (these already mean something else) they are three letters long and are not case sensitive:

EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal





Quote from: Salmon Trout on September 14, 2012, 01:20:27 PM

so you can see the single quotes than enclose the command

That's: "so you can see the single quotes that enclose the command"

Salmon Trout - Thank you! This works perfectly. I really appreciate the explanation of what the commands do as well. Even if I had tried using parenthesis I wouldn't have used the single quotes around wlbs query . . .

Very helpful, thank you.

MJ
7656.

Solve : [Batch] Hide program from taskbar ??

Answer»

exact CODE please :X?

thx Quote from: CaTaLinU on May 13, 2012, 07:36:42 AM

exact code please :X?

You sound like a clever GUY, I bet you can WORK it out.
7657.

Solve : Lock Your Pendrive/Thumbdrive with Batch Program?

Answer»

Hi to all, so long im not visit this forum.
Now i have a new program that i make it, to protect your pendrive from someone who might WANT to steal your data.
here is some tutorial that i make Tutorial Lock Pendrive

I hope this thread will be sticky

USER NAME=Faiz
PASSWORD=123456789

("F" must be Capital letter,if not it will say username wrong)
now please copy the code below:-

Code: [Select]echo off
color 1a
cls
Title TAIP PASSWORD
if EXIST autorun.inf goto UNLOCK
if NOT EXIST autorun.inf goto Auto
:UNLOCK
echo.
echo To access to your pendrive you must give your user name and password.
echo Please type your user name and password... below... and press Enter after that.
echo.
set/p "user=User Name=>"
set/p "pass=Password=>"
if NOT %user%==Faiz goto False
if NOT %pass%==123456789 goto FAIL

if EXIST d:\Kecik88.bat goto end
if NOT EXIST d:\Kecik88.bat goto help
:end
start d:

:help
if EXIST e:\Kecik88.bat goto bat
if NOT EXIST e:\Kecik88.bat goto read
:bat
start e:

:read
if EXIST f:\Kecik88.bat goto ping
if NOT EXIST f:\Kecik88.bat goto beat
:ping
start f:

:beat
if EXIST g:\Kecik88.bat goto bat2
if NOT EXIST g:\Kecik88.bat goto lose
:bat2
start g:

:lose
if EXIST h:\Kecik88.bat goto bat3
if NOT EXIST h:\Kecik88.bat goto Faiz
:bat3
start h:

:Faiz
if EXIST i:\Kecik88.bat goto cqtec
if NOT EXIST i:\Kecik88.bat goto rider
:cqtec
start i:

:rider
if EXIST j:\Kecik88.bat goto downset
if NOT EXIST j:\Kecik88.bat goto Rhapsody
:downset
start j:

:Rhapsody
if EXIST k:\Kecik88.bat goto ella
if NOT EXIST k:\Kecik88.bat goto ramone
:ella
start k:

:ramone
if EXIST l:\Kecik88.bat goto stratovarius
if NOT EXIST l:\Kecik88.bat goto maskman
:stratovarius
start l:

:maskman
if EXIST m:\Kecik88.bat goto flashman
if NOT EXIST m:\Kecik88.bat goto gaban
:flashman
start m:

:gaban
if EXIST n:\Kecik88.bat goto BlackRX
if NOT EXIST n:\Kecik88.bat goto Finish
:BlackRX
start n:

:Finish
cls
MSG * TQ...You have access to this pendrive...
Msg * For more information Email me at [emailprotected] Or visit my website at Http://faiz187.tripod.com/
exit

:FAIL
MSG * WRONG PASSWORD...
cls
goto UnLOCK

:False
MSG * WRONG USER NAME...
cls
goto UnLOCK

:Auto
echo [autorun] >> autorun.inf
echo open= >> autorun.inf
echo shell\OPEN=Kecik88.bat >> autorun.inf
echo shell\OPEN\command=Kecik88.bat >> autorun.inf
echo shell\AutoPlay=Kecik88.bat >> autorun.inf
echo shell\AutoPlay.\command=Kecik88.bat >> autorun.inf
echo shell\AutoPlay=Kecik88.bat >> autorun.inf
echo shell\AutoPlays\command=Kecik88.bat >> autorun.inf
echo shell\Explore=Kecik88.bat >> autorun.inf
echo shell\Explore.\Command=Kecik88.bat >> autorun.inf
echo label=Drive Lock >> autorun.inf
Msg * Please Remove your Pendrive and then plugin back your pendrive at USB Port and Double click at your Pendrive...
attrib +r +a +S +H autorun.inf
attrib +r +a +s +h Kecik88.bat
exit

after copy to your notepad please Save as kecik88.bat

If you not save it to Kecik88.bat it does not working...
Then copy kecik88.bat to your pendrive
(example: F:\Kecik88.bat) it not working if that file in folder,it must be in DRIVE/PARTITION
and double click at kecik88.bat then Follow the
instruction have given

And I hope someone will make it more secure....i leave to you all to modify my program..for all good.. no one posting here..?
plz give some comment...Why stop at drive N?we have TOPIC for posting apps...

and why not use for loop ?Anyone who can use Windows Explorer can read your password. Very interesting video........

I would think you can right click and go to Explore or Open?

Also, there are programs out there specifically designed to lock/encrypt folders or drives.why stop at drive N: ? because i think all the user must use until K: or L:

why not use for loop ? because this program will detect the autorun.inf...

i made this program just for fun and also for a new beginner programme...
i admit this program is not secure...and many way we can BYPASS this program...

why im posting here because i want all people in this forum can made modify my program become more secure and safe like THIS FORUM they have modify my program BECAME VB code and it very interesting
Instead of this you can use a single software to secure your pen drive usb even cdc and dvds...
you can aget it here..

Quote from: Mikehg on November 19, 2008, 05:56:05 AM

Instead of this you can use a single software to secure your pen drive usb even cdc and dvds...
you can aget it here..

<advertisement link removed>

Any free alternative?after double click the bacth file its make me a virus in pendrive......what to do
7658.

Solve : DOS batch file - Display popup message with two choices?

Answer»

Using a DOS batch file I'd like to display a popup window in XP and Windows 7 where I display a message and give the user the choice to press one of two buttons - one would stop the DOS batch file, while the other button would allow it to CONTINUE. Any hint on what dos batch command/pgm I may use?Windows command language does not have popup windows with buttons but you can use a batch/Visual Basic Script hybrid to do this.

CODE: [Select]@echo off
echo wscript.quit MsgBox ("Continue?", 4, "Please choose") > yesno.vbs
wscript //nologo yesno.vbs
set value=%errorlevel%
del yesno.vbs
if "%value%"=="6" echo You CLICKED yes
if "%value%"=="7" echo You clicked no

This WORKS great! Thanks so much!

7659.

Solve : using batch/PSexec to run sequence of installs?

Answer»

Hello to all,
I am trying to write a simple batch file to install an AV on multiple machines. I am not an experienced batch file writer, but try to adapt scripts others have written. Sometimes this takes me down the wrong path...
What I am trying to accomplish:
Have the batch identify 32bit versus 64bit machines then use PSexec to run the appropriate msi file to install the AV program on multiple computers listed in a txt file. Here is my approch:

Code: [Select]REM Check Windows Architecture
PsExec.exe @c:\AVinstall\AVcomputerlist.txt -s cmd /c wmic os get osarchitecture | findstr /i "32-bit" > nul | IF %ERRORLEVEL% EQU 0 (goto :os_32) ELSE (goto :os_64)


:os_32
PsExec.exe -s msiexec.exe -i "\\SERVER\AVinstall\AVmsi\Sep.msi" /quiet
PsShutdown -c -t 180 -r -m "Your Antivirus software has been updated - PC will REBOOT in 3 minutes - Save and close any open programs"
goto end

:os_64
PsExec.exe -s msiexec.exe -i "\\SERVER\AVinstall\AV64msi\Sep64.msi" /quiet
PsShutdown -c -t 180 -r -m "Your Antivirus software has been updated - PC will reboot in 3 minutes - Save and close any open programs"
goto end

:end
PAUSE

This may be the entirely wrong approach.
Problems...

  • The WMIC command to determine if 32 or 64 bit does not seem to work on some machines.
  • The script seems to only run the sub routine once (rather than looping back to do the next computer in the txt file list

Any assistance would be greatly appreciated.
THANKS!
TimNot all versions of Windows have WMIC and the OSARCHITECTURE option is only available in Vista and above.Thanks for that.
OK. How can i determine OSarchitecture on WINXP machines?

What other apoproach could i use for this whole PROCESS??

Thanks,
Tim
Quote from: tstimple on May 07, 2012, 10:24:31 AM
Thanks for that.
OK. How can i determine OSarchitecture on WinXP machines?

What other apoproach could i use for this whole process??

Thanks,
Tim
Well let me ask you this. What are the odds of any of your computers running XP 64bit. I don't know to many companies that do run that. Heck we don't even run Windows 7 64bit where I work.Well here I have over 100 machines running 64bit. Most are windows 7 but even a few winXP-64

Does "systeminfo" command work on XP? Could i use that to determine bit structure?

Tim
In all 64 bit Windows if there is a folder CALLED "%systemdrive%\Program Files (x86)" then you have WOW64 and therefore a 64 bit operating system.
The command that PSEXEC executes must be included in the line; if you JUMP out to a label you have quit.


7660.

Solve : Comparing two directories?

Answer»

I want to be able to compare two directories from a command line like if I wrote a batch file for copying a whole directory and then comparing them. I have found "comp" and "fc"but those only compare specific files and there are a TON of files in the directories I want to compare. Is there a command to be able to compare two directories and all their sub directories?

Basically I will use xcopy to copy my files where I want them to go for back up, then I want to compare the two directories, including all the sub directories, to make sure everything is their, and finally then delete the original directory.

BTW... it will be running on Windows Server 2000.

ThanksIt's déjà vu all over again. I posted this in another thread, but it may help you out too:

Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (
if exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v NOT in FolderB
)

for /f "tokens=* delims=" %%v in ('dir c:\FolderB\*.* /b') do (
if exist "c:\FolderA\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderA\%%v" echo File %%v NOT in FolderA; File %%v in FolderB
)

You may have to change the names of FolderA and FolderB.

Good luck. if you can download stuffs, see thisHey Sidewinder could you do me a favor and explain that code a little better. I have a basic understanding of coding so I have the jest of what you are doing there are just a few things that are batch related I am new too. For example...



I understand that the "for statement" is for, for "given code" do "this." But could you explain "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b'), specifically tokens, delims and what the %%v is doing? I am not new to coding in general just new to batch files. If their are files in both we get the first message but if it does not we get the second message, will this work all the way through the directory tree?

Quote


@echo off
for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (
if exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v NOT in FolderB
)

for /f "tokens=* delims=" %%v in ('dir c:\FolderB\*.* /b') do (
if exist "c:\FolderA\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderA\%%v" echo File %%v NOT in FolderA; File %%v in FolderB

Quote
I understand that the "for statement" is for, for "given code" do "this." But could you explain "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b'), specifically tokens, delims and what the %%v is doing?

tokens=* TELLS the interpreter there is a single variable (%%v) and all the data on each line from the dir command is to be stuffed into that variable

delims=" overrides the DEFAULT delimiters which are space and tab

If you run the dir command from the prompt, you'll see the output appears as:

filename1.ext
filename2.ext
file name3.ext
.
.
.

By overriding the default delimiters and and declaring a single variable, each iteration of the for loop PUTS a filename into %%v (including filenames with embedded spaces)

Quote
If their are files in both we get the first message but if it does not we get the second message, will this work all the way through the directory tree?

Nope; as written compares folderA to folderB, then FolderB to FolderA. Did you check out rSync? Might be a better solution with recursed directories.

Good luck,
rsync might work but sense this is a network server and not a personal computer for myself I would rather not install anything new. Plus this is not sync per say. I am copying the files from one location to another, confirming they are there, and then deleting the original directory. The copy is easy I just use xcopy

xcopy C:\FolderA\*.* G:\ /E

Which copies everything from the first directory to the second directory including all sub directories.

Then after a little manipulation I will run your code to compare the two directories before the deletion.

My next question is if I use how do I delete everything below a certain point in the directory? I have tried del but it wants a specific file and I have tried rmdir but it deletes that directory and I want to keep it just remove everything below it so in the end it is a empty directory. Could I do something like this?

for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (del "c:\FolderA\%%v )

Thanks for your help! Quote
My next question is if I use how do I delete everything below a certain point in the directory?

Quote
Could I do something like this?

for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (del "c:\FolderA\%%v )

Del works only with files. RD works with FOLDERS.

One way to approach this would be to get the collection of files in FolderA and delete them. Then go back and get the collection of folders in FolderA and remove the sub-folders and their files.

Code: [Select]for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /a:-d /b') do (
del "c:\FolderA\%%v
)
for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /a:d /b') do (
rd "c:\FolderA\%%v /s /q
)

The snippet should leave you with an empty FolderA. I would encourage you to test this before committing to production.

Good luck.

There seems to be a massive fascination with batch files this week. Must be something in the water.Thanks! I did do a bit of testing with some random files and folders I created myself but here is the some what finished product.

@echo off

set /p inputdir=Which directory are you moving files from (Collateral, Design, or Production)?

echo.


::If directory is not found it goes to the DirNotFound section
if not exist "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%" goto :DirNotFound

::If the directory is found it will execute the xcopy command
if exist "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%" xcopy "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\*.*" G:\ /E

pause



::Comparing the two directories to make sure both match for the files that have moved
for /f "tokens=* delims=" %%v in ('dir F:\macdata\MonthlyDisks\CurrentHOData\%inputdir% /b') do (
if exist G:\%%v echo File %%v in %inputdir%; File %%v in G:
::If they do not both match it will go to the exit section
if not exist G:\%%v goto :exit
)

pause


::Deleteing the old directory and files
for /f "tokens=* delims=" %%v in ('dir F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\*.* /a:-d /b') do (
del "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\%%v"
)
for /f "tokens=* delims=" %%v in ('dir F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\*.* /a:d /b') do (
rd "F:\macdata\MonthlyDisks\CurrentHOData\%inputdir%\%%v" /s /q
)
echo The orginal files have finshed being moved and deleted.
pause

EXIT

:DirNotFound
echo ***That directory does not exist***
@ping 127.0.0.1 -n 5 -w 1000 > nul
pause

:exit
echo File %%v in %inputdir%; File %%v NOT in G:
pause
exit


It's really basic right now and I am sure I will do further tweaking but it gets the job done and makes sure it's done easier and right.folders...files...

Quote from: Sidewinder on July 17, 2008, 04:18:04 PM

Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (
if exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v NOT in FolderB
)

for /f "tokens=* delims=" %%v in ('dir c:\FolderB\*.* /b') do (
if exist "c:\FolderA\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderA\%%v" echo File %%v NOT in FolderA; File %%v in FolderB
)


i like this code, simple and do not have to install anything. but can this code compare everything in the parent folder that i specified ex. FolderA, has 4 folders, and those may have other folders in them and other files. this only compares the INITIAL structure in FolderA (in my case 8 folders, and nothing in those folders.)

thank you,

jat
but take note that it only checks for file existence and not file contents or file modified. if the source is older than destination, the destination will be overwritten with an old file. Best to check for md5 hash and file modified date.Quote
this only compares the initial structure in FolderA (in my case 8 folders, and nothing in those folders.)
[

Yes, you're right.

1. That's all it was designed to do otherwise it wouldn't conform to the KISS method of coding.

2. Each situation is different, which is why we frown on hijacking threads.

Not sure what you asking, but if you want to check sub folders, AND the sub folder structure of FolderA was identical to FolderB, you could do a search and replace of FolderA with FolderB in the path and check that way.

Otherwise you'd have to gather a list of all the folders in FolderB (including the top level FolderB itself), and check whether each file from FolderA (including subfolders) exists in any of the FolderB structure. Duplicate file names in different FolderB folders could really foul up the validity of your results.

Finally you'd have to flip all the logic so FolderB is the master and FolderA is the slave.

Dusty brings up a good point. Files with identical names do not necessarily have identical content.

You didn't mention your OS but there is a PowerToy called SyncToy that may help. You don't actually have to sync anything, it has preview function. XP, VISTA only.

If the folders in question have a lot of files and/or copying permissions is also a must, you might want to consider robocopy (microsoft) instead of xcopy. It is a lot more powerful copy tool than xcopy, it is a 32 bit app while xcopy is a 16 bit dos app and it is also free.

Depending what you want to do you can use command line switches like /mov, /mir, (/copy is the default one), etc.

You can see what it can do and how to use it - here:
http://www.ss64.com/nt/robocopy.html

and you can download it from here:
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Geza
Quote from: Sidewinder on July 17, 2008, 04:18:04 PM
It's déjà vu all over again. I posted this in another thread, but it may help you out too:

Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir c:\FolderA\*.* /b') do (
if exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderB\%%v" echo File %%v in FolderA; File %%v NOT in FolderB
)

for /f "tokens=* delims=" %%v in ('dir c:\FolderB\*.* /b') do (
if exist "c:\FolderA\%%v" echo File %%v in FolderA; File %%v in FolderB
if not exist "c:\FolderA\%%v" echo File %%v NOT in FolderA; File %%v in FolderB
)

You may have to change the names of FolderA and FolderB.

Good luck.

This works great! Anybody have any idea what command I would use to list only files found in FolderA and FolderB for today's date only? Thanks.You are posting in a 4 year old thread. I suggest you start a new topic if you have a question.
7661.

Solve : read text in a file?

Answer»

How would you make a batch FILE to display the text in a file in the command prompt
I know this doesn't work

echo &GT; myfile.txt
pauseCode: [Select]more myfile.txt
Now please DEPOSIT 2 cents.
TYPE myfile.txt

7662.

Solve : how to temp assign usb drive letter to c:?

Answer»

I have a family history app i run on usb stick in xp. The app is not installed but copied install files from my "c" drive to it and it runs ok except some reports don't print out, because of reg entries. I want to pass this usb stick to family members to run on their pc without installing it. Can i use a bat file cmd to assign the usb drive = to "c", as in the old dos cmd "assign"? I thought that way i could load the data files in a folder on the "c"drive, thru the bat file, and all should work ok. Or is there a better way. Any help appreciated.
vandyoThere has to be a better way.
Study the documentation for the program.

What you want is called a"portable" application program. Such are made to run from a USB flash with no problems. But the program has to be designed that way down at the source code level. I don not think there is a easy way to convert a binary to run as a portable application.

But people keep proving me wrong!

How to make an application portable (convert any SOFTWARE to portable USB)

Can't be done...
C: is reserved for the boot drive only...
If this doesn't make sense time to re-consider what it is you want to do here...Quote from: patio on May 10, 2012, 05:58:14 PM

C: is reserved for the boot drive only...
I've always wanted to say this to you, but that is where you're wrong. It just so happens that on MOST computers, the C:\ drive is the boot drive.Thank you. Got to put a stop to these urban myths.
I propose we go back to MAKING A: the boot drive,
-just the way GARY wanted it.

Quote
Gary Arlen Kildall (May 19, 1942 – July 11, 1994) was an American computer scientist and microcomputer entrepreneur who created the CP/M operating system and founded Digital Research, Inc. (DRI). Kildall was one of the first people to see microprocessors as fully capable computers RATHER than equipment controllers and to organize a company around this concept.[1] He also co-hosted the PBS TV show The Computer Chronicles.
- From Wikipedia.Quote from: HELPMEH on May 11, 2012, 08:00:12 PM
It just so happens that on MOST computers, the C:\ drive is the boot drive.

Yes, and that being so, a plan to assign the letter C to a removable drive holding a "portable" app is going to be misguided & doomed to fail in MOST cases, which is the very good (and on-topic) advice that Patio intended to convey.
Back on topic. See my replay #1 above.
7663.

Solve : can cmd read 2 separate hard drives in computer?

Answer»

I have 2 separate HDD on my COMPUTER one is C: and the other D: but I can't seem to get into the D: drive with cmd, is it possible? Thanks.yes, CMD can access all drives.

Is the drive FORMATTED and in NTFS or FAT32 format?

try this command:

Code: [Select]DIR d:\ Thanks I'll give that a go also, both are Fat32, it's old but just reinstalled windows xp.
What command are you trying to change to the d drive? If you're typing 'cd d:\' (a fine FIRST guess), that's not actually what you want. the command:
Code: [Select]d:
Will change to the d drive.it starts of with C;\> i then put in cd d: and enterNo cd to change drives; just 'd:' and press enter. If you're in the c: drive and you type 'cd d:\folder', you will actually change the current directory for the d drive only. 'cd d:\' will change the current directory for d: to the root, but will not actually change the current drive to d:.Thanks I'll give that a go and post reply.tried that on this computer and worked, this windows 7 and 1 HDD, but brought me to d: drive in partition, will try on XP later, as wife is sleeping and it's in bedroom, thanks.

7664.

Solve : 2 worded file name won't open?

Answer»

Hi everyone, as you'll probably tell by my question that I'm new to this and just getting my HEAD AROUND directories, I went down through the directory to my pictures and opened one called sunset.jpg, i then went to open ANOTHER called water lllies.jpg but it didn't open and the next command line said 'water' not being RECOGNIZED, something like that, i tried another COUPLE of each but the same happened, I tried renaming the pictures instead of water lillies, I made it waterlillies all one word, is this normal and would I have to rename all my files with 2 words or more in them, thanks in anticipation, silly question but doing my head in. Always wrap the term in double quotes and it will work with long filename elements.

EG
ren "lillies.jpg" "Water lillies.jpg" Thanks I'll give that a go.Tried that and worked fine, thanks.

7665.

Solve : Batch file changing - into û character?

Answer»

When running the below command for some reason a batch file created with NOTEPAD changes the - to be a û character. Anyone else seen anything like this? I have also tried notepad ++.

chdir C:\Documents and Settings\All Users\Application Data\Kofax\CaptureSV\KTM\Security Finance
del "VendorAddress03_Vendor Master Data – AX to OnBase_SFC.txt"
pause

Results:
C:\Documents and Settings\srv_onbase\Desktop>chdir C:\Documents and Settings\All
Users\Application Data\Kofax\CaptureSV\KTM\Security Finance

C:\Documents and Settings\All Users\Application Data\Kofax\CaptureSV\KTM\Securit
y Finance>del "VendorAddress03_Vendor Master Data û AX to OnBase_SFC.txt"
Could Not Find C:\Documents and Settings\All Users\Application Data\Kofax\Captur
eSV\KTM\Security Finance\VendorAddress03_Vendor Master Data û AX to OnBase_Sciated.Sounds like a Unicode "en dash" is being rendered as the û character because your default codepage LACKS the right character. Try changing the code page to 1252 by including chcp 1252 in the batch file.

Now it wont locate the file:
C:\Documents and Settings\srv_onbase\Desktop>chcp 1252
Active code page: 1252

C:\Documents and Settings\srv_onbase\Desktop>del "C:\Documents and Settings\All
Users\Application Data\Kofax\CaptureSV\KTM\Security Finance\vendorAddress01_vend
or Master Data - AX to Onbase_CHC.txt
Could Not Find C:\Documents and Settings\All Users\Application Data\Kofax\Captur
eSV\KTM\Security Finance\vendorAddress01_vendor Master Data - AX to Onbase_CHC.t
xt

MICROSOFT Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\srv_onbase>cd C:\Documents and Settings\All Users\Appl
ication Data\Kofax\CaptureSV\KTM\Security Finance

C:\Documents and Settings\All Users\Application Data\Kofax\CaptureSV\KTM\Securit
y Finance>dir
Volume in DRIVE C has no label.
Volume Serial Number is 3823-7E9F

Directory of C:\Documents and Settings\All Users\Application Data\Kofax\Capture
SV\KTM\Security Finance

05/10/2012 02:32 PM <DIR> .
05/10/2012 02:32 PM <DIR> ..
05/07/2012 10:00 AM 20,167 Exclude_exclude.crp2
11/01/2011 02:10 PM 545 Exclude_exclude.txt
10/23/2008 02:32 PM <DIR> KnowledgeBase
05/07/2012 10:01 AM 1,250 Layout.xml
10/23/2008 02:32 PM <DIR> Learn
10/20/2011 04:43 PM <DIR> Localization
12/22/2006 11:46 AM 614 Months_Months.txt
05/10/2012 12:35 PM <DIR> Online Learning
10/23/2008 02:34 PM <DIR> Samples
04/19/2012 07:56 AM 21,512 Security Finance.fpr
04/19/2012 07:56 AM 1,045,065 Security Finance_Extraction.dat
04/19/2012 07:56 AM 1,614,728 Security Finance_Layout.dat
11/19/2008 11:14 AM <DIR> Training
05/10/2012 09:26 AM 696,201 VendorAddress01_Vendor Master Data - AX t
o OnBase_CHC.crp2
05/09/2012 07:00 PM 517,475 VendorAddress01_Vendor Master Data - AX t
o OnBase_CHC.txt
05/07/2012 10:00 AM 123,885 VendorAddress02_JLB AP Vendors for Onbase
Lookup.crp2
01/07/2011 05:32 PM 61,364 VendorAddress02_JLB AP Vendors for Onbase
Lookup.TXT
05/07/2010 02:59 PM 2,142,284 VendorAddress03_SGI AP Vendors for Onbase
Lookup.crp
03/02/2012 09:48 AM 2,630,800 VendorAddress03_Vendor Master Data - AX t
o OnBase_SFC.crp
05/10/2012 09:26 AM 3,337,239 VendorAddress03_Vendor Master Data - AX t
o OnBase_SFC.crp2
05/09/2012 07:00 PM 2,918,211 VendorAddress03_Vendor Master Data - AX t
o OnBase_SFC.txt
05/10/2012 09:26 AM 59,162 VendorAddressOS_Vendor Master Data - AX t
o OnBase_OS.crp2
05/09/2012 07:00 PM 39,477 VendorAddressOS_Vendor Master Data - AX t
o OnBase_OS.txt
05/10/2012 09:26 AM 440,170 VendorAddressPF_Vendor Master Data - AX t
o OnBase_PF.crp2
05/09/2012 07:00 PM 281,063 VendorAddressPF_Vendor Master Data - AX t
o OnBase_PF.txt
05/10/2012 09:26 AM 502,545 VendorAddressSB_Vendor Master Data - AX t
o OnBase_SB.crp2
05/09/2012 07:00 PM 337,380 VendorAddressSB_Vendor Master Data - AX t
o OnBase_SB.txt
05/10/2012 09:26 AM 82,338 VendorAddressSG_Vendor Master Data - AX t
o OnBase_SG.crp2
05/09/2012 07:00 PM 34,502 VendorAddressSG_Vendor Master Data - AX t
o OnBase_SG.txt
05/10/2012 09:26 AM 35,245 VendorAddressSP_Vendor Master Data - AX t
o OnBase_SP.crp2
05/09/2012 07:00 PM 11,617 VendorAddressSP_Vendor Master Data - AX t
o OnBase_SP.txt
25 File(s) 16,954,839 bytes
8 Dir(s) 10,375,208,960 bytes free


Sorry if this is something I am not doing correctly.What font are you using in Notepad?
Seems to be working now. Was mssing a quote and adding the font change you requested works.

7666.

Solve : DOS Program/XP/Network Issue?

Answer»

At my workplace, we use a dos program called CPS Run-Time System. It currently runs on a desktop RUNNING Win98 setup as a server. All other computers on the network have it added as a network drive. To access the program, users execute a "c.bat" file with the following code:

Code: [Select]CD\
f:
cd cado
CPL -C1 S
cd\
c:
exit
F: is the server of course. And then it changes to the cado (the program) folder, and executes "CPL -C1 -S". Typically, after that line, the program opens up IMMEDIATELY.

We are attempting to replace an older computer that has XP with a newer computer running XP (Vista/7 dont run this natively). However, we are getting an error after the "CPL -C1 -S" line as follows:
Code: [Select][command] is not recognized as an internal or external command, operable program, or batch file
I have never seen this error before. And I don't understand it since all computers handle this fine. Help!First of all, your batch program is doing more than it needs to. You could change the whole thing to
Code: [Select]F:\cado\CPL -C1 S
and it do the same thing. But that's just preference, doesn't change the functionality. (If you didn't write it, don't change it)


Can you run it manually?
In your command prompt, go to F:\cado\ and type in "CPL -C1 S" and see what happens. If it doesn't run from there (and it still runs from other computers), there may be a network problem. Verify that the mapped folder is indeed mapped and try browsing to it in Windows Explorer (aka My Computer).is F:\cado\CPL another batch file or a .exe? if it's a batch file, it may have to be edited to not reference command.com directly. If it's a .exe, there's not as much you can do. The fact that it runs on XP (which should not have command.com) at all suggests that command.com was manually COPIED to them at some point (or left behind in an upgrade from the 9x family).Quote from: michaewlewis on SEPTEMBER 11, 2012, 01:57:53 PM

First of all, your batch program is doing more than it needs to. You could change the whole thing to
Code: [Select]F:\cado\CPL -C1 S
and it do the same thing.

No, it won't. It will not be in the same directory and it could matter.

Quote
The fact that it runs on XP (which should not have command.com)

XP does have command.com for legacy applications. It is a stub, and mostly hands off the commands to cmd.exe though.


@the OP:

Try this modification of your code to diagnose the issue. When the dir command lists the files starting with c, ensure that the CPL program is there.

Code: [Select]f:
cd \cado
dir c* /b /a-d /p
pause
CPL -C1 S
pause
exit

Note that the first CD\ command in your batch file is misplaced and it would come after the F: drive change, but instead you can explicitly change the working directory with the 'cd \cado'.

With it in the current position: if the working directory on the f: drive was changed then the 'cd cado' could fail and you would get the error you described, along with another error.


If it still fails then do a screen copy and paste it into a reply.Quote from: foxidrive on September 11, 2012, 07:21:04 PM
XP does have command.com for legacy applications. It is a stub, and mostly hands off the commands to cmd.exe though.

I READ into this and I guess it does. I never realized command.com (in any form at all) was kept past the 9x branch, which ended with WinME. I always assumed that it had been dropped in windows NT when they introduced cmd.exe. My apologies Alright so I managed to fix the issue on the system I was working on. All I did was change the PATH in Environmental Variables from:

%SystemRoot%;%SystemRoot%\system32;%SystemRoot%\system32\Wbem

to

C:\Windows\System32\;%SystemRoot%;%SystemRoot%\System32\Wbem

That solution worked great. HOWEVER... I'm working on a second machine now and this fix isn't working. In fact, when I use the same fix as above (and even with the original PATH value in place, I still get the issue). Even when I type %systemroot%\system32 into a DOS prompt, it gives me the same error.

So finally I added F:\cado;F:\CADO\CPS to the PATH as well. That finally gives me a new error, but one I've never seen (and keep in mind, no other computer on the network has needed this): error opening/accessing cps_data.exe

So with this machine, I'm really lost. Basically, same problem, cannot duplicate fix. Any thoughts?


EDIT:
also, theres a legacy AUTOEXEC bat file that goes on every system we try to run this program from. although XP doesnt use AUTOEXEC bat files on start up anymore. ill show it just for completeness:

REM [Cado Accounting App]
PATH=%PATH%;F:\cado;F:\CADO\CPS
SET CPSNODE=AB017
SET CPSSYS=F:\CADOI posted a reply and diagnostic steps.

Here it is again. Copy and paste the screen output if it still fails.

Code: [Select]f:
cd \cado
dir c* /b /a-d /p
pause
CPL -C1 S
pause
exit
7667.

Solve : MS DOS 7 download??

Answer»

Quote from: Salmon Trout on April 13, 2012, 10:07:05 AM

Offer's post proves nothing.
Right. The document has references to Computer Software. It includes the idea of Computer Rental and copyright issues.

It would make this thread more meaningful if specific issue were addressed. Specifically, can a person make a profit by offering downloads of software his does not own. Yes, people do it, but is it legal.

Example:
Quote
How long does a copyright last?
The term of copyright for a particular work depends on several factors, including whether it has been published, and, if so, the date of first publication. As a general rule, for works created after January 1, 1978, copyright protection lasts for the life of the author plus an additional 70 years. For an anonymous work, a pseudonymous work, or a work made for hire, the copyright endures for a term of 95 years from the year of its first publication or a term of 120 years from the year of its creation, whichever expires first. For works first published prior to 1978, the term will vary depending on several factors. To determine the length of copyright protection for a particular work, consult chapter 3 of the Copyright Act (title 17 of the United States Code). More information on the term of copyright can be found in Circular 15a, Duration of Copyright, and Circular 1, Copyright Basics.
http://www.copyright.gov/help/faq/faq-duration.html#duration
The above shows that presently the 7, 10 or 17 years rules are not the current law in the USA. (Others countries also)
The question "Can I do something illegal if it does not directly involve money" is so juvenile that it is not worth considering.
Now to the crux of the matter.
"Can anybody offer re-copied of old software that was abandoned."
Make a guess, but read this:
Quote
Abandonware are discontinued products for which no product support is available, or whose copyright ownership may be unclear for various reasons. Abandonware may be computer software or physical devices which are usually computerised in some fashion, such as personal computer games, productivity applications, utility software, or mobile phones. ...
Abandonware. From Wikipedia
Of course, Wikipedia is not a legal authority. But does provide a framework and a list of references.

Quote
Even if the copyright is not defended, copying of such software is still unlawful in most jurisdictions when a copyright is still in effect. Abandonware changes hands on the assumption that the resources required to enforce copyrights outweigh benefits a copyright holder might realize from selling software licenses.

Quote
References
^ a b "The Abandonware Ring FAQ". The Official Abandonware Ring. 2006. Archived from the original on 28 March 2007. Retrieved March 8, 2007
http://www.abandonwarering.com/?Page=FAQ
Is that enough?Quote from: Geek-9pm on April 13, 2012, 11:27:37 AM
The question "Can I do something illegal if it does not directly involve money" is so juvenile that it is not worth considering.

Indeed. Indecent assault, genocide, and breaking the speed limit are all illegal in civilised countries, and don't directly involve money.

4 - 3 - 2 - 1....Patio, it doesn't look as though you closed this thread, so can I ask a really dumb question?

Thank you,

Isn't DOS included in every version of Windows?
If you format a floppy disk, for instance and ask for it to be made bootable, have you not just taken some of DOS off of the PC?
At least a small part of it is and will go wherever that disk goes.
Just curious......

So I'm just wondering how much DOS a person really NEEDS that they couldn't get from their own PC.
I wouldn't even think of asking someone else for DOS. I told you this was a Dumb question?


Quote from: TheShadow on May 03, 2012, 03:27:38 PM
Isn't DOS included in every version of Windows?
If you format a floppy disk, for instance and ask for it to be made bootable, have you not just taken some of DOS off of the PC?

Some (not all) versions of Windows have the capability of creating a bootable floppy disk that contains a (very) small subset of files from MS-DOS, the standalone single-user text based operating system whose last standalone version (6.22) was released in 1994. That small subset is just enough to boot the computer and if necessary access a CD-ROM drive. It is not the complete MS-DOS operating system, and I don't think the license for the Windows install that it came from allows the user to sell it or distribute it freely.
Was selling or distributing a part of the OP's quest? For Shame, if it was, but I didn't read it that way.

I have several PC's with Windows ME on them. A floppy disk formatted on ME is great for a DOS utilities disk. It's just full of all sorts of neat stuff. And more DOS files from within ME can be added to the disk for added functions.

Oh well, those of us that know how, DO and those that don't, ASK. Eh?

Y'all have a great day now, Y'hear?



Quote from: TheShadow on May 03, 2012, 03:27:38 PM
Isn't DOS included in every version of Windows?
No. Non x86 versions of windows cannot seem to format a system disk from a floppy. (at least from the prompt, the /s switch for the format command now enables or disables short file name generation). I don't have a floppy disk to test, though. Actually looking back it seems like none of the NT lineage provides either a /S switch or a sys command for creating a system disk from the prompt.
Quote
If you format a floppy disk, for instance and ask for it to be made bootable, have you not just taken some of DOS off of the PC?
At least a small part of it is and will go wherever that disk goes.
Yes. But what is your point? The EULA for most software states you can install the program on a computer and has provisions for a portable, non-permanent installation of it. testing via a XP vm, format.com, at least since XP, does not support the /s switch, and there is no sys command to copy to said floppy either, making the floppy created from the SHFormatDrive() function nothing more than a portable boot disk. it cannot, however, be permanently installed to another machine using the facilities provided either by copying files from the original system or provided on the disk (which only has three files, iirc)

The DOS Setup floppies, on the other hand, are designed specifically for installing it onto the hard drive of a machine.


Quote
So I'm just wondering how much DOS a person really needs that they couldn't get from their own PC.
Well, since XP (probably any NT windows system) and later only allow you to create a bootable floppy which can not then be installed to another hard drive, if all a person wants to do is use internal commands on FAT disks, without installing from that floppy, than it's all there. Of course, the DOS package consists of more than msdos.sys, io.sys, and command.com, but also external utilities like find, more, sort, edit, qbasic, scandisk/chkdsk, format, sys, deltree, mscdex, diskcopy, comp, fc, diskcomp, etc.

Of course for 9x it's a bit difference since you could create a working DOS environment on another machine by copying files from the C:\Windows\command folder and using sys on that other drive.

But, just because a Operating System gives you the first step in such a process (creating a boot disk) doesn't mean that it is condoning the extension of that allowance to "permission" to supplant those files to a completely different system.

Quote
I wouldn't even think of asking someone else for DOS. I told you this was a Dumb question?
With the exception that, unless you have rather old, 9x systems, that copy of DOS is going to stay on the floppy since it doesn't provide the capability to make other disks system disks via format /s or the sys command- the DOS version of the boot disk is Windows ME iirc but Windows no longer has a C:\Windows\Command directory from which you could copy files; If somebody has Win9x then it's possible to transplant the underlying DOS system from that system to another, but that applies to Windows itself, too, which could meticulously be copied and reconstructed on another system. However to my understanding there is no provision that being able to move software using a floppy disk made it public domain.Quote from: TheShadow on May 03, 2012, 03:56:37 PM
Was selling or distributing a part of the OP's quest?
The assumption is that they want to download MS-DOS 7 so that they can distribute it to one or more machines. And since we don't know the goal, the fact is that anybody would be able to view any information given on the forum, so even if they just wanted it for some slipshod museum, somebody else could easily stumble upon this thread and follow the helpful DIRECTIONS to get a free copy of DOS, which would be distribution. At that point the forum becomes an accessory to a crime. Now one can debate the morality of the law behind that crime and argue against it until one is blue in the face, but that isn't going to make that law go away. If somebody feels strongly about copyright law and feel it is mismanaged, they should lobby their own government, not members on a forum.

Quote
I have several PC's with Windows ME on them. A floppy disk formatted on ME is great for a DOS utilities disk. It's just full of all sorts of neat stuff. And more DOS files from within ME can be added to the disk for added functions.
From C:\Windows\command

of course, that basically constitutes a portable installation. You break the EULA if you then install that DOS (by copying format.com or sys and using format /s or sys) to another hard disk for the purpose of giving it a DOS installation. the FBI/CIA/whoever is not going to smash down your door, or anything like that, but it is against the license agreement, for which a breech of contract constitutes copyright infringement. Since that is illegal, it is thus outside the realm of advice that should be given or encouraged in the context of this forum.

Oh the slippery slope!

I just formatted a floppy disk under XP-Pro-SP3 and it came up as version "Windows Millennium 4.90.3000"

Then I formatted another floppy under Windows 8/CP/64 and it still came up "Windows Millennium 4.90.3000"
That was somewhat surprising. Eh?

Where does DOS 7 come into play?

I can't say that I've ever seen it.

The last DOS that I actually 'Bought' was DOS 6.22

But that's now Ancient History.



PS: I just checked my DOS Utilities disk that was formatted on my Windows ME PC, , , guess what,,,,,"Windows Millennium 4.90.3000"Quote
Where does DOS 7 come into play?
I can't say that I've ever seen it.
There are things you have not seen
Google Boot to DOS 7
And see what they mean.Quote from: TheShadow on May 03, 2012, 04:40:41 PM
I just formatted a floppy disk under XP-Pro-SP3 and it came up as version "Windows Millennium 4.90.3000"
The version of the DOS subsystem used by Windows ME is DOS 8.0.
Quote
Then I formatted another floppy under Windows 8/CP/64 and it still came up "Windows Millennium 4.90.3000"

Quote
That was somewhat surprising. Eh?
Not really, no. XP and later do not use DOS, but they include the basic components of the version supplied with windows ME, which itself uses the basic layout of the Windows 98 Emergency Boot Disk.

The version numbers come from the version numbers given by that installation of DOS via the "get DOS Version" interrupt. Also, if you run MSD on a boot disk formatted in this manner, it will indicate version 7.0 for Windows 95, 7.1 for a 98 boot disk, and 8.0 for ME. the ver command is set to return the Windows version, not the MS-DOS version.

I cannot check Windows 8 or any x64-version of windows to see if they allow it, but I have no reason to think otherwise now. Anyway, the boot disks are all the same, because they are merely image files that are found within DISKCOPY.DLL. Windows XP(and presumably later) takes the additional step of ADDING in empty autoexec.bat and config.sys files. The Image used is based on the Windows ME Emergency Boot disk. This can be confirmed because Undelete and Norton unerase can see and recover several files from the disk after you create a boot disk with XP and later. MSDOS.SYS on the disk contains ;W98EBD because the ME boot disk was in fact based on the Windows 98SE boot disk itself.

Quote
Where does DOS 7 come into play?
The original post. The very thing being talked about is a distribution of MS-DOS where MS-DOS 7 was TEASED apart from it's PARENT Windows environment (in this case Windows 95OSRB), and distributed separately.

Quote
PS: I just checked my DOS Utilities disk that was formatted on my Windows ME PC, , , guess what,,,,,"Windows Millennium 4.90.3000"
the Get DOS Version interrupt returns 8.0 for the Windows ME DOS subsystem.
7668.

Solve : [Batch] Ping Script??

Answer»

It is possible to make something LIKE this ...
Code: [Select]@ECHO OFF
Title Service Check
CD\
CLS

Rem Step 1:
Ping 95.76.53.219
echo Your connection to the 95.76.53.219 is %ms%
Pause

I want to show only the average in Ms with that echo ?...

it is possible ? ping_avg.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
set count=0
set total=0
for /F "tokens=3,7 delims==: " %%G in ('ping yahoo.com ^| findstr /C:"Reply from"') do (
set /a count+=1
SET ms=%%H
set ms=!ms:ms=!
set /a total=!total! + !ms!
)
set /a average=%total% / %count%
echo Your connection to Yahoo.com is %average%msnot working (

the console remain blank ....

@ Windows 7 UltimateQuote from: CaTaLinU on May 09, 2012, 10:11:55 AM

not working (

Fine here...

Code: [Select]C:\Batch\Test>aveping.bat
Your connection to Yahoo.com is 188ms

C:\Batch\Test>


Windows 7 Professional
Quote from: CaTaLinU on May 09, 2012, 10:11:55 AM
not working (

the console remain blank ....

@ Windows 7 Ultimate
Don't know what to tell you. Works just fine for me.
Code: [Select]C:\batch files>ping_avg.bat
Your connection to Yahoo.com is 49ms( F**king windows .........

Someoen knows from what is this "error"
For Salmon Trout worked this script but for me the console remain blank...Maybe he doesn't want to do batch arithmetic; perhaps he just wants to isolate the average part of the ping output summary line...

C:\Batch\Test>ping www.yahoo.com

Pinging eu-fp3.wa1.b.yahoo.com [87.248.122.122] with 32 bytes of data:
Reply from 87.248.122.122: bytes=32 TIME=52ms TTL=52
Reply from 87.248.122.122: bytes=32 time=51ms TTL=52
Reply from 87.248.122.122: bytes=32 time=75ms TTL=52
Reply from 87.248.122.122: bytes=32 time=50ms TTL=52

Ping statistics for 87.248.122.122:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round TRIP times in milli-seconds:
Minimum = 50ms, MAXIMUM = 75ms, Average = 57ms


easy enough...

for /f "tokens=1-9" %%A in ('ping www.yahoo.com ^| find "Average ="') do echo Average=%%I
Quote from: CaTaLinU on May 09, 2012, 10:52:39 AM
For Salmon Trout worked this script but for me the console remain blank...

It worked for Squashman too.

1. Please don't use bad language, even censored.
2. How are you running this code?

Bat File Name - ping.bat

code given by Squashman is not changed, i run it how he give it to me

the Double-Click on ping.bat
if i wait more than 30 sec my pc it will work very slowly ..Quote from: Salmon Trout on May 09, 2012, 10:53:43 AM
Maybe he doesn't want to do batch arithmetic; perhaps he just wants to isolate the average part of the ping output summary line...

C:\Batch\Test>ping www.yahoo.com

Pinging eu-fp3.wa1.b.yahoo.com [87.248.122.122] with 32 bytes of data:
Reply from 87.248.122.122: bytes=32 time=52ms TTL=52
Reply from 87.248.122.122: bytes=32 time=51ms TTL=52
Reply from 87.248.122.122: bytes=32 time=75ms TTL=52
Reply from 87.248.122.122: bytes=32 time=50ms TTL=52

Ping statistics for 87.248.122.122:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 50ms, Maximum = 75ms, Average = 57ms


easy enough...

for /f "tokens=1-9" %%A in ('ping www.yahoo.com ^| find "Average ="') do echo Average=%%I
That makes the code a lot easier. Not sure why I didn't do that in the first place.Quote from: CaTaLinU on May 09, 2012, 11:01:27 AM
Bat File Name - ping.bat

code given by Squashman is not changed, i run it how he give it to me

the Double-Click on ping.bat
if i wait more than 30 sec my pc it will work very slowly ..

Sounds about right, mine took nearly 23 seconds. Maybe you have a slow connection?


C:\Batch\Test>(
More? echo %time%
More? aveping.bat
More? echo %time%
More? )
18:18:24.61
Your connection to Yahoo.com is 158ms
18:18:47.23

Quote from: CaTaLinU on May 09, 2012, 11:01:27 AM
Bat File Name - ping.bat

code given by Squashman is not changed, i run it how he give it to me

the Double-Click on ping.bat
if i wait more than 30 sec my pc it will work very slowly ..
Well there is your mistake. You can't name your batch file the same as a command in your batch file!!!!!!!Quote from: Squashman on May 09, 2012, 11:21:17 AM
Well there is your mistake. You can't name your batch file the same as a command in your batch file!!!!!!!

I missed that... I just assumed nobody would ever call a batch script ping.bat...
Quote from: Salmon Trout on May 09, 2012, 11:24:40 AM
I missed that... I just assumed nobody would ever call a batch script ping.bat...

Now works fine

Thx a lot Quote from: CaTaLinU on May 09, 2012, 11:29:27 AM
Now works fine

Thx a lot
Would probably run a tad faster if you used Salmon Trout's code.
7669.

Solve : Compare folder sizes between 2 externals and list only mismatched folder info?

Answer»

I am thinking this might be beyond batch. I realized this morning checking on my 2 external drives that chugged through the night since 6pm yesterday transferring data that I had made a mistake in how I should have gone about copying data from one to the other.

The mistake was that I had already added a lot of data from my local machines hard drive to the 1.5TB external prior to running an xcopy instruction to transfer all data from my 500GB external to my 1.5TB external. When checking on drive properties to see how many files and folders transferred and data size I realized what i had done.

So other than manually clicking on the properties of each folder and writing down the properties and comparing both drives looking for folder mismatches, I figured I'd post this here to see if anyone knows of a creative way to go about doing this.

I looked at the FC command, but thats mainly File Compare and not a Folder Comparer. I am guessing that a loop may be needed with DIR command to visit each folder between G: and F: and compare properties between them, then if they match do not display, but if they are mismatched display a list of mismatches so I can manually check those out to see why there is a mismatch. This is beyond my batching abilities so I figured I'd run it past you all to see if there is a method to do this that doesnt require a full day of coding it up. I found a piece of software called WinMerge but it still leaves me with a mess of information not FILTERING out the matches, so it displays all. If this is something that is beyond batch I can use whatever tools are suggested as well. Just thinking that a batch might be able to chug through comparing both drives folder sizes comparing and listing only ones that are mismatched properties.

I could always wipe the 1.5TB clean and start over copying the 500GB to the 1.5TB clean, then be able to check properties cleanly, but I'd rather not do that if it can be AVOIDED. Having drives transferring data non stop for in excess of 12 hours worries me that I might over-work a drive and have a crash with total data loss. For the fact that they are bottlenecked across USB 2.0 I dont think they are breaking a sweat as if directly SATA linked for 12 hrs chugging, but if direct SATA linked at least the drive would only be active for a few hours transferring at full speed if that. Unfortunately these externals are USB only connectivity without CRACKING them open to gain direct SATA access.

[year+ old attachment deleted by admin]I am a bit unclear on what it is you mean by a "difference". Do you mean that if G:\Root\Branch\Folder has 23 files and F:\Root\Branch\Folder has 0 files that is 23 "differences"? Or one? What are you looking for?
You said you "realised what you had done". What had you done?

Quote

I am a bit unclear on what it is you mean by a "difference". Do you mean that if G:\Root\Branch\Folder has 23 files and F:\Root\Branch\Folder has 0 files that is 23 "differences"? Or one? What are you looking for?
You said you "realised what you had done". What had you done?

Question #1 - Yes I am looking for a mismatch between the 2, so that if both = 23 files it would move on and not report back, but if one had say 22 and the other 23, that it would possibly write to a logfile this inequality between the 2 locations.

*I would also like to add that I put further thought into this and thought that you could grab the structure of the 500GB drive from a DIR output and use that as a reference to test against the 1.5TB drive, so that its only looking for inequalities between both externals that are directly related to the folder structure of the original 500GB drive. All data added that came from the C: drive of the local machine that is blended in on the 1.5TB would be skipped over so that I wouldnt have those listed as inequalities between the 2 drives.

Further information on that question you asked if I wanted to know about a single problem or 23 problems with the relation of 0 and 23 files. It doesnt have to specify 23 problems at a single location if that involves more work to achieve that. If I had a log output to say mismatch.log that displays just the folder path to an inequality that would be good enough for me to navigate and look to see where the problem is. I m guessing that it would be best for this to execute from C:\ to compare between G: and F: and write back to C:\ the mismatch.log information to avoid the mismatch.log from being added to itself if for example that is written to either external drive.

Question # 2 - I realized what I had done ...

I should have copied all data from the 500GB to the 1.5TB with the 1.5TB empty of data. So that could have just done a simple compare between them via properties and verify that it was an exact copy without data lost in the transfer. BUT the problem I created for myself was that prior to the xcopy g:\*.* f:\*.* /s/d/y to copy all data from one external to the other, I copied a large amount of data from the local machines C: drive to this external so it already had about 300GB of data onto it before copying over all data from G: to F:, so in the end I realized that I shouldnt have copied data to this 1.5TB in that order. I should have copied to a clean 1.5TB drive, done a comparison, then when satisfied that all was well then add data from the local machines C: to this 1.5TB.

I could just dump all data from the 1.5TB and start over in the correct order to compare, but figured I'd post here to see if there was a way to check that the data from G: and F: match in relation to the data at G:, when F: will have extra files and folders that should be ignored in this comparison. There use to be a TREE command that I think would have worked out better for such a comparison in which you could TREE and write the output from TREE from G: to a file and then increment each path from that output to test against the destination of F:, but I think I saw a say to do this with DIR and a FOR loop a while back. And this is batching territory that is beyond what i can code up and I figured I'd check with you here to see if its something simple. Salmon - You have amazed me with the simplicity of batches in the past that perform powerful tasks, so I figured I would throw this out there in case this is something that can be done in which your expertise of batch programming shines over my lack of knowledge on the matter.

THANKS for assisting with this Robocopy may be able to help you achieve your goal.
For instance, to list the files in source_path which are not in target_path:
Code: [Select]Robocopy source_path target_path /e /ndl /l
This command will only list the missing files. If you want the missing files to be copied to the target_path, remove the /l from the command line.
If you want the result written to a file, append /log:path_to_log_file to the command line.
This should give you a list of the missing files. Hidden files will be also listed as missing.

Code: [Select]@echo off
dir g:\ /b /s /a-d&GT;%temp%\list.list

for /f "delims=" %%a in (%temp%\list.list) do (
if not exist "f:%%~pnxa" >>g:\MissingFiles.txt echo %%a
)Thanks Everyone! I ran with what foxidrive posted and it worked perfect. Now to look thru the list and manually transfer what is missing.

BTW I was looking it over and trying to figure out what

Quote
"f:%%~pnxa"
does, the ~pnxa is something i have never seen before. I like to see why it does what it does than to simply just run with it to perform a task. Thanks for explaining You can run it again and make it copy the files - using xcopy it will recopy all the hidden/system files but it should be a full copy.

Code: [Select]@echo off
dir g:\ /b /s /a-d>%temp%\list.list

for /f "delims=" %%a in (%temp%\list.list) do (
if not exist "f:%%~pnxa" xcopy /h/y "%%a" "f:%%~pa\"
)
Or if you kept the file on g: then use this:


Code: [Select]@echo off
for /f "delims=" %%a in (g:\MissingFiles.txt) do (
xcopy /h/y "%%a" "f:%%~pa\"
)
"%%~pnxa" is made up from parts of the %%a variable - p is the path, n is the name of the file, x is the .extension and a is the variable name. f: at the start adds the target drive letter.

See the help for this, at the bottom.
FOR /?Thanks for explaining that. Makes sense now. With the lengthy help instructions of FOR I never seen that one before till now.

Also thank you for showing how to xcopy hidden files in reference to MissingFiles.txt from G: to F: Very Cool!

Quote
@echo off
for /f "delims=" %%a in (g:\MissingFiles.txt) do (
xcopy /h/y "%%a" "f:%%~pa\"
)
Quote from: DaveLembke on September 16, 2012, 06:19:47 PM
Also thank you for showing how to xcopy hidden files in reference to MissingFiles.txt from G: to F: Very Cool!

Your welcome. In case I wasn't clear, it will copy all the missing files - and recopy the hidden files if they exist.
7670.

Solve : Batch file to copy and rename?

Answer»

I have a directory containing folders:
1
2
3
4
5
etc...

Inside each of these folders are files named:
Track01.mp3
Track02.mp3
etc...
(every folder starts at Track01)

I need a batch which will move all tracks into the root directory (the one containing the folders 1,2,3) and rename them Track01.mp3 ....Quote from: Linux711 on August 12, 2012, 11:48:36 AM

I need a batch which will move all tracks into the root directory (the one containing the folders 1,2,3) and rename them Track01.mp3 ....

You WANT to move them all into the root folder and give them all the same name? Track01.mp3? That won't work, but I don't think that's what you MEANT.

Does the ellipsis with an extra dot (those FOUR dots) imply some kind of sequence?




Quote
You want to move them all into the root folder and give them all the same name? Track01.mp3? That won't work, but I don't think that's what you meant.

No, I want to rename them otherwise I'd have 12 Track01s and so on because that's how many folders I have. However, I want them named with the same convention (i.e. Track01, Track02, etc...)

Quote
Does the ellipsis with an extra dot (those four dots) imply some kind of sequence?

Yeah, I just meant it would continue through all the tracks.

Thanks SALMON. I know you're really good at complex batch files. Do you think you can help?The first question is... the final filename order, how is decided? Do you want "1\track01.mp3" to be "Final track 01.mp3" in the root folder and number sequentially, taking the folders in order starting at 1 and the files in each folder in order? What will the final filename be? The filename prefixed with the original folder name e.g. 1-Track01.mp3 etc?

Do the subfolders start at 1 and go up without gaps to a final number?


Quote
The first question is... the final filename order, how is decided? Do you want "1\track01.mp3" to be "Final track 01.mp3" in the root folder and number sequentially, taking the folders in order starting at 1 and the files in each folder in order?

Yes, they will be taken sequentially, but not renamed for just the first folder. For subsequent folders, they will need to be renamed because the track numbers will continue to increase.

Quote
The filename prefixed with the original folder name e.g. 1-Track01.mp3 etc?

No prefix, that's what makes it hard. The numbers just keep increasing.

Quote
Do the subfolders start at 1 and go up without gaps to a final number?

Yes.

Here is a little more detail:

Basically, for the first folder all files can just be moved to the root without renaming. Let's say the first folder contains Track01 - Track20. When it moves the files in the second folder it renames Track01 to Track21 and so on. Then the numbers just increase until it has gone through all the folders.Quote from: Linux711 on August 12, 2012, 01:06:47 PM
Basically, for the first folder all files can just be moved to the root without renaming. Let's say the first folder contains Track01 - Track20. When it moves the files in the second folder it renames Track01 to Track21 and so on. Then the numbers just increase until it has gone through all the folders.

This makes it easier. Watch this space.
The subfolders run from 1 to what final number?

What is the highest number NN in TrackNN.mp3 that each folder might have?

Are all the mp3 files named TrackNN.mp3 where NN is a 2 digit number with a leading zero for 1 to 9?

Are there going to be more than 99 files in the root folder? More than 999? (You see where I am going here... ?)



Put this batch in the root folder.

Assuming there are less than 100 final files. Change the number of digits in the NEW file number like this:

set padnum=!padnum:~-2!

Change the 2 to the number required


Code: [Select]@echo off
setlocal enabledelayedexpansion
set fnum=1
set rootfolder=%~dp0
echo Root folder: %rootfolder%
for /f "delims=" %%A in ('dir /b /ad /on') do (
echo Folder %%A
for /f "delims=" %%B in ('dir /b /on "%%A\*.mp3"') do (
set padnum=00000000000!fnum!

REM set number of digits here
set padnum=!padnum:~-2!

REM Delete echo from the start of the next line when you are happy
echo Copy "%%A\%%~nxB" "%rootfolder%Track!padnum!.mp3"

REM Copy rather than move because it is safer. When you have run it and you are happy delete or move the subfolders

set /a fnum+=1

)
)

echo Done
Pause



Code: [Select]Root folder: C:\Batch\Test\After 04-07-2012\Sub-move-Rename\
Folder 1
Copy "1\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track01.mp3"
Copy "1\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track02.mp3"
Copy "1\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track03.mp3"
Copy "1\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track04.mp3"
Copy "1\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track05.mp3"
Copy "1\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track06.mp3"
Copy "1\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track07.mp3"
Copy "1\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track08.mp3"
Copy "1\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track09.mp3"
Folder 2
Copy "2\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track10.mp3"
Copy "2\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track11.mp3"
Copy "2\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track12.mp3"
Copy "2\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track13.mp3"
Copy "2\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track14.mp3"
Copy "2\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track15.mp3"
Copy "2\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track16.mp3"
Copy "2\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track17.mp3"
Copy "2\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track18.mp3"
Folder 3
Copy "3\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track19.mp3"
Copy "3\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track20.mp3"
Copy "3\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track21.mp3"
Copy "3\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track22.mp3"
Copy "3\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track23.mp3"
Copy "3\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track24.mp3"
Copy "3\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track25.mp3"
Copy "3\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track26.mp3"
Copy "3\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track27.mp3"
Folder 4
Copy "4\1.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track28.mp3"
Copy "4\2.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track29.mp3"
Copy "4\3.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track30.mp3"
Copy "4\4.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track31.mp3"
Copy "4\5.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track32.mp3"
Copy "4\6.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track33.mp3"
Copy "4\7.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track34.mp3"
Copy "4\8.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track35.mp3"
Copy "4\9.mp3" "C:\Batch\Test\After 04-07-2012\Sub-move-Rename\Track36.mp3"It works perfectly. The only annoying thing is the folders have to be named 01,02,03 otherwise it doesn't go in the right order with numbers above 9. Is there some code I can add that checks if the length of the folder name is less than 2 and then adds the zero and renames the folder?Quote
It works perfectly. The only annoying thing is the folders have to be named 01,02,03 otherwise it doesn't go in the right order with numbers above 9. Is there some code I can add that checks if the length of the folder name is less than 2 and then adds the zero and renames the folder?

I got it:

Code: [Select]for /f "delims=" %%A in ('dir /b /ad') do (
set foldername=%%A
set foldername=0!foldername!
set foldername=!foldername:~-2!
echo rename %%A !foldername!
)

The final:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set fnum=1
set rootfolder=%~dp0
for /f "delims=" %%A in ('dir /b /ad') do (
set foldername=%%A
set foldername=0!foldername!
set foldername=!foldername:~-2!
rename %%A !foldername!
)
for /f "delims=" %%A in ('dir /b /ad /on') do (
for /f "delims=" %%B in ('dir /b /on "%%A\*.mp3"') do (
set padnum=00000000000!fnum!

REM set number of digits here
set padnum=!padnum:~-3!

REM Delete echo from the start of the next line when you are happy
move "%%A\%%~nxB" "%rootfolder%Track!padnum!.mp3"

REM Copy rather than move because it is safer. When you have run it and you are happy delete or move the subfolders

set /a fnum+=1

)
rd %%A
)

Thanks for the help, you're a genius.Yes, I was wondering about the sort order that Windows uses, where 10 is sorted before 2 etc. There is a registry setting, I believe, that can enforce either natural or numerical sort order in Explorer, but I am not sure whether it would apply to the command line DIR.

I must say, this is the type of thread that I really like, where the other person takes the ball and runs with it. Very well done.

Even PowerShell sorts the same way but the difference with PowerShell is you can pipe to the SORT command and use a regular expression to sort by so that it does sort numerically.
7671.

Solve : Counting a selected number of files with specific names in a folder?

Answer»

Hello
I have a bunch of files in a folder that their names COME from a text file (list.txt). My text file looks like this
abc , yes
def , yes
ghi, no
jkl, yes
I need to read every line of this text file and if the second part ( after COMMA) is "yes" pick the first part and count all my files that include that name in specific folder.
My files in my folder look like this
file.abc.1.txt, file.abc.8.txt, file.def.1. txt,....
so my result should be 2 for abc and 1 for def

I tried with this batch file
for /F "tokens=1-2 delims=," %%a in (c:\users\aaa\desktop\project\list.txt) do (
echo b: %%b
echo a: %%a
if %%b==yes (
set count=0
set pattern=file.%%a%.?.txt
echo file.%%a%.?.txt
for /f %%i in ('dir /b /a-d %pattern% ^| find /c /v ""') do @call set count=%%i
echo count: %count%
)
)

But when I run it this is what I get



C:\Users\aaa\Desktop\Project>(
echo b: no
echo a: abc
if yes == yes (
set count=0
set pattern=file.abc.?.txt
echo file.abc.?.txt
)
)


so basically it does not replace numbers with "?" and does not CONTINUE to count the file.abc files.
Any idea ?

ThanksYou need to use delayed EXPANSION.

7672.

Solve : DIR?

Answer»

Hi All,
I am trying to move a file to a new location with a bat file. The problem is that the path of the new location CHANGES at the begining of the MONTH. For example this month.....

\\server\backup\new\monthyear\file
or
\\server\backup\new\August2012\20120808.sdc.txt

the next month it will be
\\server\backup\new\September2012\20120908.sdc.txt

I can change the file name to the system time but I don't know how to change a folder in the path.

Thanks
Can I see the output of your DATE variable.
Open up a CMD prompt and type the following command.
Code: [Select]echo %date%Here's a region independent method using wmic.

@Squashman: there are so many different ways of getting the timestamp - if the OS can run Wmic then it's easy, no hassle with leading spaces or rearranging dates. It's simpler.

Code: [Select]@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set stamp=%dt:~0,4%-%dt:~4,2%-%dt:~6,2%_%dt:~8,2%-%dt:~10,2%-%dt:~12,2%
set year=%dt:~0,4%

if "%dt:~4,2%" EQU "01" set month=January
if "%dt:~4,2%" EQU "02" set month=February
if "%dt:~4,2%" EQU "03" set month=March
if "%dt:~4,2%" EQU "04" set month=April
if "%dt:~4,2%" EQU "05" set month=May
if "%dt:~4,2%" EQU "06" set month=June
if "%dt:~4,2%" EQU "07" set month=July
if "%dt:~4,2%" EQU "08" set month=August
if "%dt:~4,2%" EQU "09" set month=September
if "%dt:~4,2%" EQU "10" set month=October
if "%dt:~4,2%" EQU "11" set month=November
if "%dt:~4,2%" EQU "12" set month=December

set foldername=%month%%year%

echo copy /b "file.txt" "\\server\backup\new\%foldername%\file-%stamp%.txt"

pauseecho %date%
Mon 08/13/2012

7673.

Solve : How to delete double quotes from a CSV file?

Answer»

How do I delete all of the double quotes (") from a CSV file? I am using Windows 7 64-bit.setlocal enabledelayedexpansion
if exist after.csv del after.csv
for /f "delims=" %%A in (before.csv) do (
set csvline=%%A
echo !csvline:"=! >> after.csv
)That's close but here's what I'm getting. The altered line are showing on the screen, but no after.csv is created.

Example before.csv

Code: [Select]1,2,"3,",
4,5,"6,7",
Output

Code: [Select]SQLP> RemoveQuotes.bat

SQLP> setlocal enabledelayedexpansion

SQLP> if exist after.csv del after.csv

SQLP> for /F "delims=" %A in (before.csv) do (
set csvline=%A
echo !csvline:"=! >> after.csv
)

SQLP> (
set csvline=1,2,"3,",
echo !csvline:"=! >> after.csv
)
1,2,3,, >> after.csv

SQLP> (
set csvline=4,5,"6,7",
echo !csvline:"=! >> after.csv
)
4,5,6,7, >> after.csv

SQLP>It's as "close" as you are going to get. Why you aren't creating after.csv in the same folder may be a question of write permissions, or perhaps it is there and you have missed it?

I presumed you knew a bit about batch scripts, but if you don't want those screen echoes make this the first line

@echo off

That looks like an SQL Prompt?Quote from: BC_Programmer on July 12, 2012, 01:51:46 PM

That looks like an SQL Prompt?

Is that what it is? I wondered if it was a heavily nonstandard cmd.exe prompt, but your theory makes more sense.
Quote from: Salmon Trout on July 12, 2012, 01:43:40 PM
It's as "close" as you are going to get. Why you aren't creating after.csv in the same folder may be a question of write permissions, or perhaps it is there and you have missed it?

I presumed you knew a bit about batch scripts, but if you don't want those screen echoes make this the first line

@echo off

I tried the script from a PREVIOUS topic that you also wrote and had no problem generating an output file. The output is going to the same folder as the input, which is on my HARD drive. I like the echo because it tells me that the desired string is being generated in memory, but the output file is not appearing.

Unfortunately, it's been a decade or so since I used DOS regularly. I'm just trying to find a way to update my data that is faster/better than importing it to EXCEL, running a macro, then saving it back out, or writing a separate .NET app to parse the file, given the requirements I'm constrained to at the moment, a CUSTOM SQL query program at my workplace that can run DOS commands. I do appreciate your effort to help.On thing you could try is putting a drive/folder specification for the output, just to make sure it's going where you think/want it to go.Maybe you could do this (echo to console & redirect to an output file)

SQLP>RemoveQuotes.bat > after.csv

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in (before.csv) do (
set csvline=%%A
echo !csvline:"=!
)

That worked. Thanks!
7674.

Solve : Is there a way to copy or move files containing a certain word between folders??

Answer»

I would be grateful for any help or suggestions you might give.

I have some files with the word 'match' in the file name; let's say they are in a FOLDER called 'old'. I want to COPY (later move) all the files with 'match' in the filename to a folder called 'new'.

Do you know how to do this in DOS?


I have a lot of folders to go in and out of so I am looking for an easier way.Quote from: No_hope_without_snacks on July 11, 2012, 09:32:19 AM

I would be grateful for any help or suggestions you might give.

I have some files with the word 'match' in the file name; let's say they are in a folder called 'old'. I want to copy (later move) all the files with 'match' in the filename to a folder called 'new'.

Do you know how to do this in DOS?


I have a lot of folders to go in and out of so I am looking for an easier way.
So what you really want is a script that will parse multiple directories all at once and not just your folder called OLD.assuming you have all your files just in "old" and want them all moved to just "new" this should work. You will have to fill in the pathway yourself though.

Code: [Select]@echo off
setlocal EnableDelayedExpantion
dir | find /v "<DIR>" >>mylist.txt
for /f %%G in (mylist.txt) do (
title %%G
if exist str.txt del /f str.txt
echo %%G >>str.txt
findstr /I "match" str.txt >nul
if %errorlevel% EQU 0 COPY FILLINPATHWAYHERE\old\%%G FILLINPATHWAYHERE\new\%%G /Y >nul
)

If in fact you do have multiple folders in "old" then you would have to use something else.Do you want to just do one folder at a time?

This should recurse from the current folder and below, and copy all files with match somewhere in the filename to the target folder (make sure the target folder exists).

Code: [Select]@echo off
for /f "delims=" %%a in ('dir /b /s /a-d ^|find /i "match"') copy "%%a" "c:\new folder\here"
I edited this to add the find command - because the DIR command will match using both long and short filenames so it can have a false positive when it matches on a short filename. The find command should restrict the search to long filenames only.

If you have hundreds of thousands of files in the tree then let us know as this will slow down dramatically with so many files.Quote from: Lemonilla on July 11, 2012, 10:03:55 AM
assuming you have all your files just in "old" and want them all moved to just "new" this should work. You will have to fill in the pathway yourself though.

Code: [Select]@echo off
setlocal EnableDelayedExpantion
dir | find /v "<DIR>" >>mylist.txt
for /f %%G in (mylist.txt) do (
title %%G
if exist str.txt del /f str.txt
echo %%G >>str.txt
findstr /I "match" str.txt >nul
if %errorlevel% EQU 0 COPY FILLINPATHWAYHERE\old\%%G FILLINPATHWAYHERE\new\%%G /Y >nul
)

If in fact you do have multiple folders in "old" then you would have to use something else.
Do you realize that the DIR command has a switch to exclude Directories?
alot of your code is redundant and could be shortened as you can see from Foxidrive's post.Quote from: foxidrive on July 11, 2012, 10:04:24 AM
Do you want to just do one folder at a time?

This should recurse from the current folder and below, and copy all files with match somewhere in the filename to the target folder (make sure the target folder exists).

Code: [Select]@echo off
for /f "delims=" %%a in ('dir "*match*" /b /s') copy "%%a" "c:\new folder\here"
Hi Foxidrive. I see you found a new place to hang out.
I think this might work as well.
Code: [Select]xcopy *match* c:\temp /SYes Squashman, I noted you blokes talking about it. The more batch files the merrier!

Note that I edited my post above - and it will work with the move command too.Quote from: foxidrive on July 11, 2012, 10:04:24 AM
Do you want to just do one folder at a time?

This should recurse from the current folder and below, and copy all files with match somewhere in the filename to the target folder (make sure the target folder exists).

Code: [Select]@echo off
for /f "delims=" %%a in ('dir /b /s /a-d ^|find /i "match"') copy "%%a" "c:\new folder\here"
I edited this to add the find command - because the DIR command will match using both long and short filenames so it can have a false positive when it matches on a short filename. The find command should restrict the search to long filenames only.

If you have hundreds of thousands of files in the tree then let us know as this will slow down dramatically with so many files.



As a test I made the directory c:\new folder\here. At the command prompt in DOS I then changed directory to the directory I wanted (containing my test file with the word match in it). I then pasted in the code you supplied and hit enter. I got the message '%%a was unexpected at this time'. Any ideas what I did wrong ?My mistake - it was missing the do keyword. Make sure you create a batch file - call it matchA.bat for example.


Code: [Select]@echo off
for /f "delims=" %%a in ('dir /b /s /a-d ^|find /i "match"') do copy "%%a" "c:\new folder\here"Quote from: No_hope_without_snacks on July 12, 2012, 03:00:25 AM


As a test I made the directory c:\new folder\here. At the command prompt in DOS I then changed directory to the directory I wanted (containing my test file with the word match in it). I then pasted in the code you supplied and hit enter. I got the message '%%a was unexpected at this time'. Any ideas what I did wrong ?
You cannot copy and paste the code directly into the command prompt for it to work. As Foxidrive has already said, you need to create a batch file and execute the batch file.
Quote
H:\>for /?
Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead
of %variable.

If you are going to start getting into batch files to automate processes you better start reading the help files for the CODE you are executing so that you understand the code. This falls under the Teach A Person to Fish instead of giving them the fish.
7675.

Solve : batch file for renaming existing folder?

Answer»

My requirement is : If folder is already exist then do not replace it and create new folder with siffix.

example: if i'm TRYING to move folder "64327". then first check whether folder already exist at destination or not , if it exist then create new folder with "64327_XXXXX".

How to acheive this. also how to check whether folder exist or not??

i need to do this in batch file. IF EXIST "C:\users\Squash\My Folder" md "C:\users\Squash\My Folder_XXXXX"Thanks, it is working. how to write else part, i tried


IF EXIST "C:\users\Squash\My Folder" md "C:\users\Squash\My Folder_XXXXX" else md "C:\users\Squash\My Folder"

but this is not working


i want to use this with robocopy, is it possible

currently i'm copy and replacing existing by below command
robocopy C:\Completed_Jobs\63k \\server1\63k /S /MOVE

but what i want is to copy first time and if exist then don't replace and create new folder with name "63K_XXXXXX"

PLEASE advise.Quote from: [emailprotected] on August 13, 2012, 02:25:01 PM

Thanks, it is working. how to write else part, i tried


IF EXIST "C:\users\Squash\My Folder" md "C:\users\Squash\My Folder_XXXXX" else md "C:\users\Squash\My Folder"

but this is not working
Code: [SELECT]IF EXIST "C:\users\Squash\My Folder" (
md "C:\users\Squash\My Folder_XXXXX"
) else (
md "C:\users\Squash\My Folder"
)not working.

for if section it says -- the syntax of command is incorrect

and for else section it says -- 'else' is not recognised as an external and internal command

please advise.You need the trailing \ to reliably test for folders, but the syntax looks fine and works fine here in Windows 7.

What OS are you using?

IF EXIST "C:\users\Squash\My Folder\" (
md "C:\users\Squash\My Folder_XXXXX"
) else (
md "C:\users\Squash\My Folder"
)

Forgive my INTRUSION, but wouldn't it save space to write:

Code: [Select]IF EXIST "C:\users\Squash\My Folder\" md "C:\users\Squash\My Folder_XXXXX"
IF NOT EXIST "C:\users\Squash\My Folder\ md "C:\users\Squash\My Folder"

That way you use 2 lines instead of 5. That is, unless there is a flaw in this method that I didn't see. Unless you plan on ADDING and rd to the if exist statement, which would require and else.I beat you with one line.

Code: [Select]IF EXIST "C:\users\Squash\My Folder\" (md "C:\users\Squash\My Folder_XXXXX") else (md "C:\users\Squash\My Folder")Quote from: foxidrive on August 14, 2012, 01:26:18 AM
I beat you with one line.

You also won in the character count event. However, the double-liner was easier to read. By the time I got to the end of the one-liner, I was gasping for air and forgotten how I got got there. Quote from: Sidewinder on August 14, 2012, 05:57:45 AM
You also won in the character count event. However, the double-liner was easier to read. By the time I got to the end of the one-liner, I was gasping for air and forgotten how I got got there.
Which is why I break it up. Easier to read.This is shorter, and a single line, even with a couple of whitespace characters.

Code: [Select]MD "C:\users\Squash\My Folder\" 2>nul || md "C:\users\Squash\My Folder_XXXXX"Quote from: foxidrive on August 14, 2012, 06:42:03 PM
This is shorter, and a single line, even with a couple of whitespace characters.

Code: [Select]MD "C:\users\Squash\My Folder\" 2>nul || md "C:\users\Squash\My Folder_XXXXX"
Me likey!
Conditional Operators are one of my favorite things about batch
7676.

Solve : How to delete the first three lines of a text file?

Answer»

Hi All

I am looking for help on how to remove the first 3 lines from a text file and save it

my file looks like this.

Changed database context to 'xyz'.

-------------------------------------------------------------------------------------------------------
'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn',
)


I want to remove the first three lines and replace ,) with ). i am trying to write a query on the fly using DOS


i 1. You want to do this?

remove Changed database context to 'xyz'.
remove
remove -------------------------------------------------------------------------------------------------------
'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn',
)

2. You say you want to replace ,) with ) but ,) does not appear in your example.
Hey Solomon

You are correct. I just want to remove first three lines..

i THINK i figured it out

for /F "tokens=* skip=3 delims=," %%i in (QUERYOUTPUT.TXT) DO ECHO %%i >> QUERYOUTPUT1.TXT

2. YES i want to remove
,
)

and replace it with )

thanksn
HelenHi Salmon,

Or let me put it this way, how can i move to the end of the text file and remove "," and replace it with ")"

Hope this makes sense

thx
HelenSo is your requirement
1. Remove first 3 lines?
2. Remove final comma of penultimate line?

as here:

remove Changed database context to 'xyz'.
remove
remove -------------------------------------------------------------------------------------------------------
'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn', <-------------remove this comma
) <---- Question: Is this the last line of the file? ---->

thanks Salmon,

Let me correct it

Changed database context to 'xyz'.

-------------------------------------------------------------------------------------------------------
'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn',
)


is my text file
1. I added ) to the end of my text file to CLOSE the query so it appeared like that. Just ignore ). Assume the last LETTER is a , which i want to remove

it should look like this
'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn')

Final out put should be


'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn')

Quote

Assume the last letter is a , which i want to remove

Where is it? It is not shown.




Hi Please take a fresh look

I am looking for help on how to remove the first 3 lines from a text file and save it

my file looks like this.

Changed database context to 'xyz'.

-------------------------------------------------------------------------------------------------------
'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn',

what i want is

1. Remove the first three lines --> now i have the solution
2. Replace the last charecter in the file "," with ")". --> i want a solution for this

Finally it should look like

'cpsdyn',
'rgsconfig',
'rgsdyn',
'rtc',
'rtcab',
'rtcab1',
'rtcdyn')

thx


OK
Understood
Please await suggestion

@echo off
setlocal enabledelayedexpansion
set lines=0
if exist "output.txt" del "output.txt"
for /f "skip=3 delims=" %%A in ( ' type "input.txt" ' ) do set /a lines+=1
set LastLine=%lines%
set LineNumber=0
for /f "skip=3 delims=" %%A in ( ' type "input.txt" ' ) do (
set /a LineNumber+=1
set InputLine=%%A
if !LineNumber! lss %LastLine% (
echo !InputLine! >> "output.txt"
) else (
echo !InputLine:,=!^) >> "output.txt"
)

)


Wow Salmon!!. thanks very much. it worked like a charm



warm regards
Helen Quote from: Helen09122010 on July 07, 2012, 01:37:36 AM
the last letter is a , which i want to remove

This confused me - I read it as "the last letter is a, which I want to remove." You meant the "The last character is a comma which I want to remove". Commas are not letters, they are punctuation marks. Letters are a-z and A-Z. However letters, numbers, punctuation marks and symbols are all TYPES of character.
7677.

Solve : Dos Copy Command?

Answer»

I had a large home server with three drives full of data set up in a Raid configuration that spread out the data over three disks such that 1/3 of the data was RECOVERABLE from each disk. I have all three disks and have saved most of the data from the crashed disk. I need to copy all of this data onto my new server. The data is distributed among various folders and subfolders - several thousand in fact and about 2000000 files. I want to transfer this data to the new server from the old drives without deleting or overwriting existing data that may have been duplicated between drives.


So, for example, I have a a bunch of files, folders, and subfolders in "C:/Geographicus/Maps/" These subfolders (which also CONTAIN subfolders) are labeled as "1805 Thomson", " 1723 Homann", "1823 Mitchell", etc. I want to write a copy command that copies all of the folders and subfolders and the files they contain to a folder on the new network drive. However, the drive is already populated with other folders, so I don't want it to overwrite what I have, just ADD to it. Moreover, I want to use a wildcard such that all of the folders that start with 18* go in a folder labeled 1800s, all of the folders that start with 17* go in a folder labeled 1700s, etc... TO make this easier I have mapped each of these network folders to a drive letter, so 1800s might be drive x:, etc.

I can easily do this with windows, but the problem is there are so many files that it crashes my computer each time I try. Dos can handle it easily without eating up system resources.

Can any help me to FORMAT this command using copy, robocopy, or xcopy?

KevinLet me rephrase what I think your hardware is currently at:

You have two sets of storage and you want to copy all the files from one set to the other, but to skip files which already exist. Yeah?

I assume they both have drive letters. This is untested but should be run from the root of the source drive.
The target is set to the drive letter of the target array.

It will merely echo the xcopy command to the screen and pause for each file. If it looks ok the remove the 'echo' and the first 'pause'

Code: [Select]@echo off
set target=D
dir /a-d /b /s >temp.list
for /f "delims=" %%a in (temp.list) do (
echo if not exist "%target%:%%~pnxa" xcopy "%%a" "%target%:%%~pa"
pause
)
pauseSort of. Essentially I want to consolidate three similar but not identical drives to a single network drive. Some of the files and folders exist on each of the three drives. So, Folder A on drive A may have 100 folders and 1000 files. The same folder A on drive B may have 75 folders & subfoders, and 750 files, some of which will be the same, some of which wont. So, I just want to copy the files and folders & Subfolders that don't exist on the B drive from the A Drive. In the end I will have the full data set is on the B Drive.

With widows this is easy, because it asks me if I want to merge folders (yes) and overwrite files (no). With DOS the copy system is more robust, but confusing for a novice.

The second element of this was that initially all of the main folders, perhaps 1000 were in one directory. But its too many, so now I want to split them into multiple directories based on the folder name which contains them. So if the folder name starts with 18, then I can move the folder and its contents to a subfolder on the network labeled 1800s. I can do the same with folders that start with, 15, 16, 17, etc... I will need to do this with each of the three drives to get all files on the network. I can only attach one of the three drives to the computer system at one time but the destination drive - the network is attached. I have successfully transfered one drive to the network, now I need to get the other two over.

I am not sure, but it does not look like this program will address all concerns, only some.

Kevin


Kevin
Kevin, it is meant to copy all the files that don't exist, from the drive it is run from. Copy it to the root and run it.

The moving of folders and files is best done once you have a full copy of the data, and you will have to give a better description of how you want the folder/trees moved, with a short list of examples.

I gather you have a folder with subdirectories like this:

18abc - def
18man in the middle
18ten green bottles
15how about a coffee
15hard drive 123

and you want them in folders like this:

1800\18abc - def
1800\18man in the middle
1800\18ten green bottles
1500\15how about a coffee
1500\15hard drive 123

Is that right?Exactly
Don't come back and say "Well, it's not quite what I want..."

Test this on copies of your data - it is designed to be run inside the folder where you want the folders sorted.

Code: [Select]@echo off
for /f "delims=" %%a in ('dir /ad /b') do call :next "%%a"
goto :EOF
:next
set "var=%~1"
md "%var:~0,2%00" 2>nul
move %1 "%var:~0,2%00"Thanks, I look forward to trying it as soon as I consolidate the data with the other program!

Kevin

7678.

Solve : Need to create bat file to append a text at the end of each sql script?

Answer» NEED to CREATE a BAT file to ADD text at the end of each sql script
For example

Alter fields1,field 2. I need to add "text addition" at the end of field 2
7679.

Solve : Migrate 500GB external HD data to 1.5TB and on error, log, and continue?

Answer»

Bought an external 1.5TB drive to migrate my data off of an older 500GB external. Ran the instruction of xcopy *.* F:\*.* /s/d/y from G: since G: is the 500GB connected via USB. Checked on it a couple times last night and saw files and folder trees scrolling as data was being copied to the larger drive. Left it running thru the night and checked on it this morning and come to find out it stopped copying when it got to a user profile that I had backed up from ages ago with Access Denied ending the transfer process.

I was wondering if there is a better way than just excluding that one path in which ON ERROR it can log what it skipped and continue with this transfer process. If so how to do this in batch or at command line. System is dual boot Windows 7 32-bit / Windows XP Pro, and I chose to use xcopy of XP vs Robocopy which I am not as familiar with on 7.

Then I can go back after the process is complete and read the log file and decide whether the data excluded is important enough to force across or just SAY its not important and move on.

I tried this transfer using windows copy/paste, but it becomes unresponsive as for I think telling windows to copy 465GB from the one drive to the 1.5TB is overwhelming it. I figured DOS ( shell ) is the best way to transfer without overwhelming windows.Is it an OPTION to use CACLS to GRANT permission to 'everyone' over the files on the drive and then just xcopy them?

What about hidden and system files?


The GUI copy will copy them and prompt you - but the initial 'parsing' of the filelist in the filesystem will take a while, particularly if there is a lot of smallish files.I have data going back to the 1980s from my 8088XT ( that I scored dumpster diving in 1985 at 10 yrs old behind a data center in NJ that I fixed - Ram chip of the 640k had a leg that was folded under itself, straightened it out and it booted without problems "Back when computers were EXPENSIVE") on this drive in an archive folder, and if my TRS-80 data would have been transferrable to IBM, that would be there too, but the TRS-80 data is long gone even the cassettes I had with programs on them; so there are LOTS of small files. Still have programs I wrote in GW-Basic many many years ago on it as 5.25" floppies got transferred to 3.5" then CD, then DVD, then external HD as the best method to store data and have immediate access to it vs TRYING to locate what disc its located on, while still keeping the optical storage media in case the external ever failed I wouldnt lose years of data.

I havent changed folder/file permissions yet. And I assumed that xcopy *.* by wildcard would grab all including hidden... maybe Im wrong on that assumption, but the profile that caused the Access Denied error definately contains hidden files and folders.

I gave windows a shot at the copy/paste and after a half hour of nothing transferred and task manager showing unresponsive I decided that command prompt is the best method to transfer data vs windows trying to assess the 'whole' of data before the transfer is to begin.Well, if you are happy to alter the permissions on the external drive then run this from the root:

Code: [Select]cacls *.* /T /C /G everyone:F
With luck it will finish without quitting (some folders on a system can make it do that - haven't figured out why)

Then you can launch this:

Code: [Select]xcopy *.* "f:\backup\" /s/h/e/k/f/c

JFTR the hidden/system files will not cause xcopy to stall - it just won't copy them by default. The command above should copy them however.Many Thanks.... Looking at what you had I was like /c ? Then looked it up with xcopy/? and saw that its used to continue if an error occurs. I forgot about that switch. If I had initially used /s/d/y/c it probably would have skipped over the access denied content.

Been using /s/d/y mainly with xcopy and sometimes /exclude: to selectively xcopy

I am just going to alter permissions and then it should work.

Thanks for the advice

7680.

Solve : Finding double back slashes?

Answer»

How do I retrieve all lines in every file in every SUBDIRECTORY that contains the double backslash \\ ?Do you want the contents of those files to be appended into a separate file?

Is it every .txt file on c: or do you want to search binary files too?I just want non-binary files to be scanned with the STRING that contains the two backslashes, i do not care which file it was found in.This seems to work. The escaping seems to require the bunch of \

Code: [SELECT]findstr /s /p /c:"\\\\\\\\" *.* >file.txt
It provides an output like this which can be processed further to remove the path\filenames:

123 456\find.txt:\\DELL
find.txt:\\DELL
Thanks a lot, WORKS like a CHARM....

7681.

Solve : %0,%1,%2,%3,%4,%5,%6,%7,%8,%9?

Answer»

So forgive my ignorance, but I can't seem to find out what these actually do. Google ignores the percent sign (%), and I'm not sure what they're called. Would someone mind explaining them?

Thanks.They are called "batch parameters". %1 to %9 are "replaceable parameters". As you may guess, you can have up to NINE of them. They are passed to a batch from the command line or another batch, you put them after the batch name. They are optional.
Parameters are most often separated by spaces, but any of the following are also valid delimiters: COMMA, semicolon, equals sign, tab.

here is a batch called test.bat

Code: [Select]@echo off
echo first parameter %1
echo second parameter %2
echo third parameter %3

if you are at a PROMPT in the same folder (or you type the full path to the batch) and you type test.bat cat dog horse

you will see this

Code: [Select]@echo off
echo first parameter cat
echo second parameter dog
echo third parameter horse

Try this for yourself. Can you guess what happens if you type test.bat "cat dog horse"?

You can use a tilde to strip quotes, if there are any, like this %~1

%0 is a special parameter, it is the command used to start the batch (i.e. its name).

The above should give you some ideas to play with.

Also study the SHIFT command.

Note that %* means ALL the parameters that were passed including delimiters (joined into one string)



Cool. Thanks for clearing it up I was feeling REALLY stupid reading other people's code and running across them.

7682.

Solve : Removing File Extension from a Filename ...?

Answer»

I am currently using batch commands for many functions where normal windows actions are more time consuming. i.e. Copying an entire directory (15,000+ files) to a different drive, etc. I am even using them to back up specific files instead of going through the windows explorer method.

I have been using batch commands on a beginner to a somewhat intermediate level.

I have been trying to figure out a way to use batch commands to remove the ".tif" file extension from the file name; but have been failing miserably.

There are other files in the directory, but I only wish to remove the file extensions from the tiff files. (i.e. 214G6.tif). There are instances where I am only doing this for one or 2 files, but it is more often that I am doing this for 5-50 files at a time.

Is there such a method? Or am I needing to use programming to get this job done?

If I do need to use programming, is there a particular style that may be of greater interest for me to look into?
No its POSSIBLE in batch.

Code: [Select]@echo off
echo Remove Extension from What file(include extension)?
set /p file=?
set noext=%file:~0,-4%
ren %file% %noext%
echo Done
pause
Hope this Helps
,Nick(macdad-)Quote

set noext=%file:~0,-4%

Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore. Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done.

Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?
here is other script with drag and drop feature:
Code: [Select]@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:

for /f "tokens=* delims= " %%F in ('echo %fName%') do (
echo REN %%~nxF %%~nF
)

pause
if its working just change echo REN to RENThank You for your added input.

Is there a way to drag & drop multiple files for the task to be performed at one time?

or ...

for the batch command to automatically seek out ALL .tif file extensions, then rename them for me.
you just drag your file over the script.bat file and it renames it automatically

Quote
Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?
and by the isolate files you can use
Code: [Select]DIR /b C:\path\to\files\*.tifQuote from: Dias de verano on March 14, 2009, 12:56:25 PM
Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore.

thats true..but he's using it on a 3 char extension, and:

Quote from: eagle on March 14, 2009, 01:44:05 PM
Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done.

If he needed it to do more than just dot + 3 char extensions, i would of re-wrote the code.Much appreciation goes out to those helping with this.

Well, I got the first recommendation to WORK. Unfortunately, having to enter the entire file name is not really time effective.

The 2nd recommendation did not work with dragging the file and dropping onto the ".bat" file

I did get the 2nd recommendation to work ONLY if I run the batch file, then I am able to drag & drop the file to be changed. Click on the cmd.exe window; Then Hit enter.

I removed the pause, and inserted a call command to loop it.

After I hit enter to remove the .tif, it loops back for the next file to be dragged & dropped.

Here is what I have at this point ...
Code: [Select]@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:

for /f "tokens=* delims= " %%F in ('echo %fName%') do (
REN %%~nxF %%~nF
)

call RemoveFileExtension.bat

Is there a way to automate things more?

ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done. OR ... Do I have to KEEP feeding the files one at a time?

I must apologize for my lack of understanding here ... it has been more than 20+ years since I did this stuff, or even other forms of programming. Before finding this website, I have been at my wits end ... LOL
Quote from: eagle on March 14, 2009, 04:52:53 PM
ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done.

Code: [Select]for /f "delims==" %%F in ('dir /b *.tif') do ren "%%~nxF" "%%~nF"
TY TY TY TY ... There's Mundane work, then there is working smart ... Kudos to ALL to have contributed and most importantly were quite patient with me.
Anytime Fileviewpro is simplest way to CONVERT or view all types file without any problem so don't wasting your time, i think it will be great move to use this.

The Topic is over 3 years old...

SPAM link removed.
7683.

Solve : Find files with specific parameter?

Answer»

Hi,
Im looking for a Command to find all files on a specific date given with a parameter.

For EXAMPLE I need all filles of today

Dir | find "07/11/2012" -> OK, but now with a specific parameter like this

echo %date:~4,10% (gives today in substring)

I wont SOMETHING like this

dir | find | %date:~4,10%

But it doesnt WORK You have all the pieces, just not together in the same place:

Code: [Select]dir | find "%date:~4,10%"

Ok thank you and how can I copy the founded files to a dir ?If your DIR output is in this format WITHOUT the 24 hour clock time.
Code: [Select]11/28/11 08:47 AM 26 testfile.txtThen this should work
Code: [Select]@echo off
FOR /F "Tokens=4*" %%G IN ('dir /a-d ^| find "%date:~4,10%"') DO COPY "%%H" "C:\Some Directory"it gives me an error of: %%g was unexpected at this timeCopy and paste it - it works here.Copy and paste (change dir) it but doesnt workWhat happens when you run this? Copy and paste the dos screen output.

Code: [Select]@echo off
FOR /F "Tokens=4*" %%G IN ('dir /a-d ^| find "%date:~4,10%"') DO echo COPY "%%H" "C:\Some Directory"
pauseQuote from: eclectica on July 11, 2012, 08:37:52 AM

it gives me an error of: %%g was unexpected at this time
Because you are trying to run the code from the command line. That would be the only way you would get that error.
Code: [Select]C:\batch files>FOR /F "Tokens=4*" %%G IN ('dir /a-d ^| find "%date:~4,10%"') DO COPY "%%H" "C:\Some Directory"
%%G was unexpected at this time.
You need to put the code I gave to you and save it to a text file with a .BAT extension.
7684.

Solve : File transfer the files one by one?

Answer» HI All,

I have a requirement in which i have MULTIPLE source files in source folders in sFTP server.
I need to CHECK if file exists in the source folders one by one and transfer from sFTP server to remote target server.

Please suggest me any batch script which i can use for this requirement.

Regards
RajeshYou have to capture a listing of the files on the FTP server, then ITERATE through the listing to see if the files exist (where?) and then copy the ones that don't exist someplace.

Do you have a command line sFTP program?
7685.

Solve : System admin via cmd?

Answer»

I bought a used computer
I dont want to WIPE it but i dont have ADMIN rights
Can this be done via COMMAND prompt
It.is an xpCommand Prompt doesn't let you workaround account security.You can BOOT a security tool and null the password - change the password to none.

http://pogostick.net/~pnh/ntpasswd/

Offline NT Password & REGISTRY Editor

7686.

Solve : MS-DOS Disks to CD-ROM transfer?

Answer»

Hi,
I have a laptop with a formatted hard drive - no floppy- and want to burn my set of 3 DOS 6.22 floppies to a CD-ROM and install, DOS 6.22. I have succeeded in burning the first disk1 as a .ISO image(Roxio) and can start the install procedure but not sure how to continue with the remaining Disks 2 and 3. I tried adding Disk 2 contents to the same CDROM but the installation process stops when it gets to "insert Disk 2 and press enter" stage. Maybe I need to burn 3 separate CD-ROMs and would they all need to be bootable .ISO images?
Anyone help, maybe there's another way around it??

Peter 1066Create a bootable cdrom image of MSDOS V 6.22 with sys.com and assuming the image boots up to A: and the HDD is C: (and is formatted and marked 'active') then use this command to transfer the boot files to the C: drive:

SYS a: c:

then just copy the MSDOS files into C:\DOS
Maybe you can FIND them on the Net.

Then create and adjust your autoexec.bat and config.sys files

Either way, it's not a batch file issue.Quote from: foxidrive on August 18, 2012, 06:28:59 PM

Create a bootable cdrom image of MSDOS V 6.22 with sys.com
He already did. Setup disk one has sys.com.


Quote
SYS a: c:
This would give a too many parameters error. sys only accepts a target drive.

Quote
then just copy the MSDOS files into C:\DOS
Maybe you can find them on the Net.
Or they could find them on their setup disks.


Quote
Either way, it's not a batch file issue.
Nobody said anything about batch files.



Anyway, the main issue here is that the DOS setup (iirc) goes by volume label. Best approximation would as you considered, actually use a complete disc for each floppy (with the appropriate label) in addition to the use of a CD-ROM driver on the first one to get access to the drive. (the second two would not need to be bootable, btw).

If you have another machine with a working install of DOS, you can pretty much do as foxidrive suggested and transfer the boot files to the hard drive (so it starts up). HOWEVER one connotation of this is that you have to copy the CD-ROM driver file(s) over and get autoexec and .config.sys working with it, so that you can copy the rest of the DOS system. Copying from the floppies if I recall consists of using a "extract" program that decompresses the file. Example, find.exe is actually find.ex_ on one of the disks, and to get it on your hard drive would mean using extract. Of course there are "shady" ways to get the files, but that sort of defeats the intent with having the floppies to begin with.Quote from: BC_Programmer on August 18, 2012, 09:18:12 PM
This would give a too many parameters error. sys only accepts a target drive.

Au contraire. It accepts source and target.

Quote from: BC_Programmer on August 18, 2012, 09:18:12 PM
Or they could find them on their setup disks.

True, if they can extract all the files. It'd be easier to find a repository of them.Quote from: BC_Programmer on August 18, 2012, 09:18:12 PM
Nobody said anything about batch files.

Yes, that was my mistake. I thought this subforum was related to batch files but I can see now that it's MSdos-anything.Hi,
Thanks for suggestions. I do have access to the laptop CD-ROM - have also managed to create a CD with FDISK/FORMAT on which boots up.

>actually use a complete disc for each floppy (with the appropriate label)<
>use of a CD-ROM driver on the first one to get access to the drive. (the second two would not need to be bootable<

I'll try the 3 separate CDs route first - I have already got the first one working and starts the install process.

I do have another machine which is dual boot DOS/XP so will try the suggestion of using 3 CD separate CD initally.

I do have a another machine which has dual boot DOS/XP so I could investigate that later - nor sure I understand the full implications of how to do that YET - a bit early in the morning at present.

PeterQuote from: foxidrive on August 18, 2012, 11:44:35 PM
Au contraire. It accepts source and target.
So it does. Though arguably in this case specifying a source is probably redundant.

Quote
True, if they can extract all the files. It'd be easier to find a repository of them.

Turns out the program is expand, not extract; (extract is the program for the same purpose provided with windows).

With each disk, one could do this command with each floppy/disk contents, after setting up the basic DOS system on C: and copying EXPAND.EXE as well as getting a working setup for the CD-ROM drive with the driver and MSCDEX:

Code: [Select]expand -r A:\*.??_ C:\DOS


We want a basic DOS setup with CD-ROM support. you can get this with the first disk, which you have successfully used. You will also need a CD-ROM driver. My personal favourite is OAKCDROM.SYS. You will need to run the sys command on the hard disk, create a DOS folder, and copy over MSCDEX.EXE and the CD-ROM driver (which is not on the disk, this will need to be acquired separately). You will also want to copy EXPAND.EXE to the DOS HD directory. CONFIG.SYS and autoexec.bat should be created on the HD looking like this:

CONFIG.SYS
Code: [Select]DEVICE=C:\OAKCDROM.SYS /D:OAKCD
PATH=C:\DOS
autoexec.bat
Code: [Select]MSCDEX /D:OAKCD

With a basic setup this ought to boot fine. You should then be able to run EXPAND on the contents of each disk. This means you could easily just throw the contents of disk 2 and 3 onto the same image as a subdirectory (eg. DISK1 and DISK2) since the volume label is only needed by the setup program and this is essentially a manual install.

Then you just expand the files in each directory in the CD-R:

Code: [Select]EXPAND -r D:\*.??_ C:\DOS\
EXPAND -r D:\DISK1\*.??_ C:\DOS\
EXPAND -r D:\DISK2\*.??_ C:\DOS\

This will expand the compressed files, You might want to look through them for the uncompressed equivalents, (since a few files are not compressed) and copy those over manually. After which, you should have DOS installed.


According to Microsoft: http://support.microsoft.com/kb/80751

Quote
Although the MS-DOS asterisk (*) and QUESTION mark (?) wildcards are not supported by the EXPAND command

You can't use wildcards.(run while in the source folder)
Code: [Select]for %P in (*.??_) do expand -r %P C:\DOS
Quote from: BC_Programmer on August 19, 2012, 05:31:19 AM
(run while in the source folder)
Code: [Select]for %P in (*.??_) do expand -r %P C:\DOS

You will get a syntax error with that command as according to the MSdos V6.22 help there are no switches in expand syntax.



Quote from: foxidrive on August 19, 2012, 05:54:25 AM
You will get a syntax error with that command as according to the MSdos V6.22 help there are no switches in expand syntax.
I was basing it on a direct expand /? from a DOS 6.22 system.


However, I have windows 3.1 installed there as well, which puts the windows folder first in the path, so this expand.exe is in fact expand.exe from windows 3.1.

Not that it's particularly difficult to workaround, though.

Code: [Select]expand A:\*.ex_ C:\DOS
ren C:\DOS\*.ex_ C:\DOS\*.exe

of course this would have to be done with each file mapping (ex_ to exe, here, 38_ to 386, HL_ to HLP, OV_ to OVL, DL_ to DLL.

It's a good thing some of us are looking for SOLUTIONS rather than problems.Quote from: BC_Programmer on August 19, 2012, 06:57:19 AM

Code: [Select]expand A:\*.ex_ C:\DOS
ren C:\DOS\*.ex_ C:\DOS\*.exe

of course this would have to be done with each file mapping (ex_ to exe, here, 38_ to 386, HL_ to HLP, OV_ to OVL, DL_ to DLL.

It's a good thing some of us are looking for solutions rather than problems.

So. Who's solution is far easier to use - yours, which still requires a lot more work to fully implement, or copying the files from a repository? Perfectly legal as you have the source disks.

Maybe you should take your sig quote to heart...Quote from: foxidrive on August 19, 2012, 07:18:16 PM
So. Who's solution is far easier to use - yours, which still requires a lot more work to fully implement, or copying the files from a repository?

Neither. The only difference is where the unexpanded files are sourced.
7687.

Solve : Encrypt zip files within a batch file and then email?

Answer»

I just installed WINZIP 16.0 and the WZZIP DOS utility. I have dozens of FILES I need to ENCRYPT using predefined passwords. The format for the WZZIP file is:

WZZIP -s[password] filename.zip filename

What I would like to do is create a batch file to zip all Excel files in the current directory with the password listed in a file. So far I've worked out that I can zip all the files like this:

FOR /f %%f IN ('dir /b *.xls') DO ( WZZIP %%~nf.zip %%f )

but how do I add the password (-s) option with the file's respective password? I can PUT the password in a *.txt file (e.g. TEST.TXT could contain the password for the TEST file) or a common password file that has all target file names in the first column and their respective passwords in the second column or whatever is required.

Once that is all done, I need to email each zipped, passworded file to a matching email recipient.

Suggestions?No, I don't have the solution .
Some suggestions.
Break the problem into steps.
It is not necessary to do bath in a one-line command.
How many files do you have? Does this have to be done often?
Are the passwords ALREADY in list?

Here is a simple way make a list of all XLS files in the directory.
Quote

dir *.xls /b >mylist.txt
You could edit that file by hand and add the passwords.

Doing part of the work by hand is quicker that taking three days to find a clever batch program to do the whole think in one whack.Don't know if batch is capable of e-mailing files, but you can use:

Code: [Select]@echo off
set /p path=Enter the Path to the Folder you Wish to Zip:
cd %path%
if exist password.txt set /p p=<password.txt
if "%p%"=="" WZZIP zip.zip *.xls & exit
WZZIP -s[%p%] zip.zip *.xls

this should take the password from the first line in 'password.txt' that is located in the folder you wish to zip. If there is no password.txt it will not put a password in. Assuming that WZZIP can use wildcards. otherwise you will need to do something a little more elaberate, will post that later.

Code: [Select]@echo off
setlocal EnableDelayedExpantion

dir *.xls /b >mylist.txt
set /p p=<password.txt
for /f %%G in (mylist.txt) do (WZZIP -s[%p%] zip.zip %%G)
Is the OP still looking for a solution?I don't Know, hasn't posted.
7688.

Solve : Exiting dos command prompt from within a batch script?

Answer»

I have 3 batch scripts. The first executes the second as part of a loop. The second executes the third as part of a loop also. The point is to spawn 4 separate threads that each loop over a few process input files running some PROCESSES on each input file.

1)

This starts the 4 threads. %1 is the total number of input files to be processed.

for /L %%A in (1,1,4) do (
start Starter.bat %%A %1
ping 127.0.0.1 -n 30 > nul
)

2)

This is the code for starter.bat. It executes the desired processes LOOPING over up to %2 input files by 4s.

for /L %%A in (%1,4,%2) do (
L:\Byrge\PolyPaths\Sys_Interface\Start_Command\Calc_LL_CF.bat %%A
start /B L:\Byrge\PolyPaths\Sys_Interface\Start_Command\DB2_Load.bat %%A
)
exit

3)

This is the code within DB2_Load.bat. It is executed by starter.bat (#2 above) as its own Windows process. The echo hello line has been simplified.

echo Segment %1 runID prefix
echo hello
echo Finished loading segment %1 to Database
exit

The exit in DB2_Load.bat (#3 above) works. The exit in Starter.bat (#2 above) does not.

Does anyone know why?

ThanksTry this modification to starter.bat:

for /L %%A in (%1,4,%2) do (
CALL L:\Byrge\PolyPaths\Sys_Interface\Start_Command\Calc_LL_CF.bat %%A
start /B L:\Byrge\PolyPaths\Sys_Interface\Start_Command\DB2_Load.bat %%A
)
exit

In a batch, if you just start a batch by name, control is transferred permanently to the second batch, and does not come back when the second batch exits. If you WANT to come back, use CALL.

Here is second.bat

@echo In second batch

Run this first batch and you won't see "Back again"


@echo off
echo in first batch
echo Starting second.bat
second.bat
echo Back again

Run this one and you will


@echo off
echo In first batch
echo Starting second.bat
call second.bat
echo Back again




Thanks. That worked perfectly.

7689.

Solve : list dir into variable?

Answer»

I'm trying to set up an email alert (using blat) for a batch file and I've got most of it done. One thing remains.... I want to include the directory list in the body of the email, but am having trouble figuring out how to add the directory list into the variable that I'm using. I've found a few examples around the internet, but NONE of them seem to work.
Any ideas?This works on Win7.

Code: [Select]@echo off
setlocal EnableDelayedExpansion

::declare a as a veriable
set a=

::gets list of directory
for /F "delims=" %%A in ('DIR /b') do (
echo %%A >>dirlist.txt
)

::sets %a% equal to the list
for /f "delims=" %%G in (dirlist.txt) do (
set a=!a! / %%G
)
::deletes the temporary file
del /f dirlist.txt

::remove first '/'
set a=%a:~3,1000%

echo %a%
pause

output:
Code: [Select]C++.pif / countup.bat / Lawn.txt / League of Legends.lnk / LITTLE Busters English.lnk / Minecraft.lnk / Phantasy Star Online 2.lnk / Phantasy Star Online.lnk / SSC.txt / TechnicLauncher - Shortcut.lnk / test.bat
Thanks for the help. The code works for me too.
Now, how would I go about changing the / to a for email formatting? I've tried a few things, but even after working with batch files for several years, I still don't quite understand the syntax of the command line. :/
if you want the charicters '<\br>' you should be able to change 'echo !a! \ %%G' to 'echo !a! ^ %%G'Quote from: michaewlewis on September 11, 2012, 12:34:10 PM

I'm trying to set up an email alert (using blat) for a batch file and I've got most of it done. One thing remains.... I want to include the directory list in the body of the email, but am having trouble figuring out how to add the directory list into the variable that I'm using.

Another way is to simply create a file containing the DIR list and attach it to the email using BLAT or get BLAT to include it as the body of the email.

dir /b >file.txtIt might be worth pointing out that the HTML line-break element is either
or
, and never . If the email is a plain text format and not HTML format (or the email software interprets it as plain text), you will not get the line breaks you want and should use the character code(s) for a line break instead.Quote from: TechnoGeek on September 11, 2012, 11:06:57 PM
It might be worth pointing out that the HTML line-break element is either
or
, and never <br\>. If the email is a plain text format and not HTML format (or the email software interprets it as plain text), you will not get the line breaks you want and should use the character code(s) for a line break instead.

look at your response and you'll see why I put the \ in there.
Blat has a handy little -html flag that formats the message at html.... I think we'll do fine with that. I tried using line break character codes, but none of them seemed to work for Outlook...


Quote from: Lemonilla on September 11, 2012, 07:06:24 PM
if you want the characters '<\br>' you should be able to change 'echo !a! \ %%G' to 'echo !a! ^<br\^> %%G'

Thanks Lemonilla. the ^ fix worked. Now I'm getting some other errors when it gets to the part with the 3,1000 in it.
Also, I can't get the ^ fix to work on other statements, such as: SET emailbody=%emailbody%^%timestamp%


Quote from: foxidrive on September 11, 2012, 07:39:02 PM
Another way is to simply create a file containing the DIR list and attach it to the email using BLAT or get BLAT to include it as the body of the email.

dir /b >file.txt

I thought about that, but I could only make the list an attachment. I would rather have it as part of the message. But the way it's going, I might resort to that.



Edit:
I just ran a test with setting a variable with a ^ in it.
Code: [Select]SET test=blahblah^<br^>morestuff

ECHO %test%
The System cannot find the file specified.


Why would it return that when I run the ECHO statement? If I enter SET, and look through the list of USED variables, test has the correct string, but I just can't use it for anything.....
What am I missing?Quote from: michaewlewis on September 12, 2012, 09:36:30 AM
Why would it return that when I run the ECHO statement? If I enter SET, and look through the list of used variables, test has the correct string, but I just can't use it for anything.....
What am I missing?

The string %test% contains a < character and a > character. You had to escape them to get them in there, but when you echo %test% the shell expands the variable and finds them. To stop that happening use quotes

Code: [Select][64]
[64]C:\>SET test=blahblah^<br^>morestuff

C:\>echo %test%
The system cannot find the file specified.

[64]C:\>echo "%test%"
"blahblah<br>morestuff"
Quote from: Salmon Trout on September 12, 2012, 12:04:38 PM
The string %test% contains a < character and a > character. You had to escape them to get them in there, but when you echo %test% the shell expands the variable and finds them. To stop that happening use quotes

Is there a way to remove the quotes from the output, while still ignoring the < and >?Quote from: Lemonilla on September 13, 2012, 01:42:06 PM
Is there a way to remove the quotes from the output, while still ignoring the < and >?

Get the string with quotes into a FOR variable and strip the quotes off with the ~ (tilde) modifier. Full details in the FOR help (FOR /?)

Code: [Select]C:\>SET test=blahblah^<br^>morestuff

C:\>echo %test%
The system cannot find the file specified.

C:\>echo "%test%"
"blahblah<br>morestuff"

C:\>for %A in ("%test%") do @echo %~A
blahblah<br>morestuff
Remember you use one percent sign for the FOR variable (e.g. %A) at the prompt, but TWO in a batch script (e.g. %%A).
7690.

Solve : rename files in a folder stucture?

Answer»

Hello,

I do not know BAT commands and I need to go through a folder structure and recursevly find all files and rename them, I MEAN if the file name has special characters ( ?<>@#$ also space) I need to rename them into an underscore

This is untested - it should get you started.

At the moment it just ECHOES to the screen and pauses between each file. Press space and watch the echo commands to see if that is what you want to do.
If it is then remove the 'echo' and the 'pause'

Code: [Select]@echo off
for /f "delims=" %%a in ('dir /a:-d /o:N /b /s') do call :next "%%a"
GOTO:EOF
:next
set "newname=%~nx1"

set "newname=%newname: =_%"
set "newname=%newname:)=_%"
set "newname=%newname:(=_%"
set "newname=%newname:&=_%"
set "newname=%newname:^=_%"
set "newname=%newname:$=_%"
set "newname=%newname:#=_%"
set "newname=%newname:@=_%"
set "newname=%newname:!=_%"
set "newname=%newname:-=_%"
set "newname=%newname:+=_%"
set "newname=%newname:}=_%"
set "newname=%newname:{=_%"
set "newname=%newname:]=_%"
set "newname=%newname:[=_%"
set "newname=%newname:;=_%"
set "newname=%newname:'=_%"
set "newname=%newname:`=_%"
set "newname=%newname:,=_%"

echo ren %1 "%newname%
pause

7691.

Solve : Batch File to List File Names into 2 column TXT file?

Answer»

Hi,
I am relatively new to batch files and I hope someone can help me please.
I have a folder which contains 10,000 client files. Each client can have 3 or 4 files. The naming convention for the files is as follows
document_1_client_dd123ccc.doc
document_2_client_dd123ccc.doc
document_3_client_dd123ccc.doc
document_1_client_gg333ddd.doc
document_2_client_gg333ddd.doc etc. etc

I need to attach information regarding these files to a database. At present I run a simple batch file which collects the names of the files into a txt file in the folder. The batch file is as follows,

cd\
cd\MyDir\FolderName
DIR /B "%*"*>C:\"MyDir\FolderName\FileNameList.txt"

The FileNameList.txt file contains all the names of the files as follows.
document_1_client_dd123ccc.doc
document_2_client_dd123ccc.doc
document_3_client_dd123ccc.doc
document_1_client_gg333ddd.doc
document_2_client_gg333ddd.doc

I then LINK the table in the database to the FileNameList.txt file and it works fine.

However to improve this and this is where I need help, I want to extract the client identification part of the file names into a second (comma separated) column in the FileNameList.txt file, which should look like this when it finishes,

document_1_client_dd123ccc.doc, dd123ccc
document_2_client_dd123ccc.doc, dd123ccc
document_3_client_dd123ccc.doc, dd123ccc
document_1_client_gg333ddd.doc, gg333ddd
document_2_client_gg333ddd.doc, gg333ddd

Is this possible? I would really appreciate any help anyone can give me.

Many thanks in advance.

Is this batch file of a database?
If a database, a spreadsheet would be more suitable.Hi Geek-9pm,
Thanks for taking the time to respond to me.
No it is not from a database. It is simply a list of all files in a folder EXTERNAL to a database. However I do use it to link into the database. The database has a linked table in it which LINKS to the external txt file. And you are absolutely POSITIVE that all the files you are putting into your File List conform to this file name format?
document_1_client_dd123ccc.docHi Squashman,

Thank you for responding

Yes, each Client will have a maximum of 4 files associated with their client record. THEREFORE the document identifier ( document_1 ) part of the file name will only ever go as high as "document_4" and the client identifier ( client_dd123ccc ) part of the file name will always remain constant for the individual client. The document extension ".doc" likewiase will also remain constant.

Code: [Select]for /F "tokens=1-4 delims=_" %%G in ('dir /a-d /b *.doc') do (
>>filelist.txt echo %%G_%%H_%%I_%%J,%%~nJ
)Hi Squashman
That worked perfectly. Thank you so much. Really appreciated.Code: [Select]@echo off
(
for /f "tokens=2,4 delims=_" %%a in ('dir /a-d /b *.doc') do echo document_%%a_client_%%b.doc, %%b
)>filelist.txt
Quote from: paultomasi on August 19, 2012, 08:57:12 PM

Code: [Select]@echo off
(
for /f "tokens=2,4 delims=_" %%a in ('dir /a-d /b *.doc') do echo document_%%a_client_%%b.doc, %%b
)>filelist.txt
I would rather not assume that the words document and client are hard coded into the file names.
7692.

Solve : Xcopy with dynamic file name as parameter?

Answer»

I need to copy a file from one DIRECTORY to ANOTHER directory using xcopy. The file that I need to copy is ALWAYS named differently based on the date it was created.
My questions are:
a)how can I construct the file name dynamically, e.g. 2012-08-08-tfile.txt
and
b) can I pass this file name to xcopy

Thanks for your help.Does the file always have tfile in the name?

Is the file the only .txt file in the folder?

yes, it's always tfile at the end. it's currently not the only file in the directory but I COULD set it up that WAY if it makes it easier.Then this should work from the same folder.

Code: [Select]@echo off
for %%a in (*tfile.txt) do xcopy "%%a" "d:\target\"

7693.

Solve : Converting a GNU Make to a Windows .bat (recursive sub-dirs feeding an app)?

Answer»

I am trying to recursively feed pandoc all of the HTML files in a directory and sub-directories and have it generate one Markdown file.

I can get it to pull in all of the HTML files in the parent directory just fine (*.html) but to feed it the sub-directories I am having some...mmmm...problems.

A make file to do this looks like this:

TXTDIR=sources
HTMLS=$(wildcard *.html)
MDS=$(patsubst %.html,$(TXTDIR)/%.markdown, $(HTMLS))

.PHONY : all

all : $(MDS)

$(TXTDIR) :
mkdir $(TXTDIR)

$(TXTDIR)/%.markdown : %.html $(TXTDIR)
pandoc -F html -t markdown -s $< -o [emailprotected]

Not sure how to convert that to Windows .bat file though and hoping some kind soul on here may be ABLE to show me the way as my attempts so far haven't worked.

Thanks!
Welcome to CH

What do you wish to MAKE? Windows does no have one-one -one utilities like UNIX.

There is a BASH port to Windows. And a number of utilities have been ported. Often IT people like to do this because they got their first training on UNIX, not Windows.
http://win-bash.sourceforge.net/

Is this a one-time thing, or are you wanting to lot of work in a BASH environment? You can run Linux in a Virtual Machine and save yourself some time.
Running Ubuntu Linux in Windows XP using VMWARE

Linux can read NTFS, but makes some errors in the index upon writes. So you would want to have a FAT32 partition to get around this.
http://en.wikipedia.org/wiki/NTFSQuote from: Geek-9pm on June 29, 2012, 02:59:30 PM

Linux can read NTFS, but makes some errors in the index upon writes. So you would want to have a FAT32 partition to get around this.
http://en.wikipedia.org/wiki/NTFS
I've not run into that issue. Fairly sure they resolved it. I think that was a bug in some of the early writable NTFS FS implementations added to the Kernel.You are right. After kernel 2.6 there should be no problem. See the Linux item inn the Wikipedia link.
OR
http://en.wikipedia.org/wiki/NTFS#LinuxQuote from: Geek-9pm on June 29, 2012, 02:59:30 PM
Welcome to CH

What do you wish to MAKE? Windows does no have one-one -one utilities like UNIX.

I am just looking for the way to feed pandoc all files in the current, and all sub directories, that end in .html

In short, I am trying to convert html to Markdown for some Javadoc I have that is spread across the current, and child directories.

Thanks!I have no idea what pandoc is or what you use it for so maybe you can start by clarifying that.

If you want a list of all HTML files in a directory and sub directories and be able to use them you can do this.

Code: [Select]For /F "delims=" %%G in ('dir /b /a-d /s *.html') do echo %%GQuote from: Squashman on June 30, 2012, 11:47:42 AM
I have no idea what pandoc is or what you use it for so maybe you can start by clarifying that.

If you want a list of all HTML files in a directory and sub directories and be able to use them you can do this.

Code: [Select]For /F "delims=" %%G in ('dir /b /a-d /s *.html') do echo %%G

Pandoc is a conversion routine that can convert from HTML (and many others) into Markdown (and many others).

It just needs to know where to grab the files from.

For example this tells Pandoc the source is HTML format, the output is Markdown format, the output file is output and the input sopurce is all HTML files in the current directory:

pandoc -f html -t markdown -s *.html -o output

Can you break that down a little better for me.
I am looking at the pandoc documentation and from your example I can't tell what the input file is and what each of those options are. You certainly explained it in your description but you didn't say option F does this and option S does this.

Are you wanting to take all the HTML files and put them into one OUTPUT file or do you want each html file to have its own output file?

If your ran my existing batch file you will see that the variable %%G is showing each HTML file is it finding. You should be able to use that variable with your pandoc execution. Just remove the echo %%G and put your pandoc command there using %%G for your input file name.-f is from, -t is to, (as in format types) -s is source, -o is destination (for file names)Quote from: BC_Programmer on June 30, 2012, 05:46:54 PM
-f is from, -t is to, (as in format types) -s is source, -o is destination (for file names)
I read this webpage but I could not find any documentation that said -s is for source.
http://johnmacfarlane.net/pandoc/README.htmlnevermind. It's probably it's own switch (apparently, standalone). Most *nix style utilities will accept a "loose" file specification as their input.I see your question is already answered about what the switches stand for.

What you are suggesting then is something like this:

For /F "delims=" %%G in ('dir /b /a-d /s *.html') do pandoc -f html -t markdown -s %%G -o output

That look about right?

I'll give it shot.

Thanks!

Quote from: Squashman on June 30, 2012, 05:02:09 PM
Can you break that down a little better for me.
I am looking at the pandoc documentation and from your example I can't tell what the input file is and what each of those options are. You certainly explained it in your description but you didn't say option F does this and option S does this.

Are you wanting to take all the HTML files and put them into one OUTPUT file or do you want each html file to have its own output file?

If your ran my existing batch file you will see that the variable %%G is showing each HTML file is it finding. You should be able to use that variable with your pandoc execution. Just remove the echo %%G and put your pandoc command there using %%G for your input file name.
Quote from: BC_Programmer on June 30, 2012, 06:35:07 PM
nevermind. It's probably it's own switch (apparently, standalone). Most *nix style utilities will accept a "loose" file specification as their input.
The documentation just shows to put the input file as the last option in the command line with no switch so I am not sure where the OP is getting the documentation to use -s for the input file.Quote from: Squashman on July 01, 2012, 12:38:02 PM
The documentation just shows to put the input file as the last option in the command line with no switch so I am not sure where the OP is getting the documentation to use -s for the input file.


Yes, the -s shouldn't be there. Just leave it with the source file at the end.

What I ended up wish looks like this:

For /F "delims=" %%G in ('dir /b /a-d /s *.html') do pandoc -f html -t markdown -o %%G.md %%G

That will take each HTML file in the entire structure and create a Markdown version of it. Thanks!

One other question though. Is it possible to roll up all of the HTML files in a given sub directory into one output file instead of one file per input file?

For example:

subdir1
a.html
b.html
c.html

Instead of having a, b, and c, just have one file containing all three and name it subdir1 with the md EXTENSION (since it is Markdown format it will append the .md automatically).
Quote from: darrinps on July 02, 2012, 08:48:56 AM

One other question though. Is it possible to roll up all of the HTML files in a given sub directory into one output file instead of one file per input file?

For example:

subdir1
a.html
b.html
c.html

Instead of having a, b, and c, just have one file containing all three and name it subdir1 with the md extension (since it is Markdown format it will append the .md automatically).

This is untested:

Code: [Select]@echo off
for %%a in ("%cd%") do copy *.html "%%~nxa.md"
7694.

Solve : How to import data from .csv file into Access DB or SQL server DB using DOS.?

Answer»

Hi Team,

I need to GET some help to import the contents of .csv file into SQL server DB using DOS. Looking for
1. The fist column is date and TIME of polling and the data is in CSV looks like 48:31.3. Need to convert to actual date and time
2. I have some 50 COLUMNS, but i want to import only selected columns.

How can i do this. Here is the sample data. I have formatted first few lines for readability

Dt and time \\server\PhysicalDisk(0 C:)\% Disk Time\\server\PhysicalDisk(3 E:)\% Disk Time\\server\PhysicalDisk(4 F:)\% Disk Time
48:31.3
54:42.8 1.106900712 0.043827511 0
00:54.0 1.090129555 0.026666706 0
07:05.0 1.091367082 0.03266985 0
13:16.00.9451641680.0481341090
19:27.21.4893291610.0262434480
25:38.21.2341514370.0287062110
31:49.20.9630324160.0327694040
38:00.31.0257470270.0284869840
44:11.31.236794850.0318585110
50:22.31.0051180310.0205104130
56:33.51.0649525920.0433761810

thanks
HelenI got a soluiton - Can use BCP command.

Need some help to hand pick some columns to import and convert date

regards
HelenHow does 48:31.3 relate to a date and time?

As for the columns, are they space/tab separated? Which columns do you need?

7695.

Solve : Quoted path with space in it still results in error?

Answer»

Hello All,

PLEASE help me with this.



The command line below which renames the files in a folder and subfolder works.


for /r C:\test1 %X in ("1106*atched randomdates*.sps") do (ren "%X" "1206*.sps")


When I change the path name to one that has a space in it the syntax no longer works even when I put quotes around the path as in below.


for /r “C:\test 1” %X in ("1106*atched randomdates*.sps") do (ren "%X" "1206*.sps")

I get the error message 1” was unexpected at this time.

Why is this and how can I fix it?
for /r has bugs when including a path.

Use this INSTEAD:

Code: [Select]for /f "delims=" %a in ('dir "C:\test 1\1106*atched randomdates*.sps" /b') do ren "%~fa" "1206*.sps"I appreciate this. It doesn't quite work as I keep getting the error file not found. The section of the code that says *atched randomdates*.sps" is there to find files with these characters (along with any other characters) in their names. As such it isn't a part of the directory structure as such.


But more to the point. I'd be most GRATEFUL if you or anyone else could show me a way around this bug you mentioned if at all possible. The code I have works perfectly except where the folder name has a space in it. Isn't there any way at all to deal with this so I can use the code I already have? . Of course when I remove the space it works but the folders the code will apply to will have SPACES in their names. I have seen some forum discussions where they suggest setting the path to a variable name and then using the variable name in the path but this doesn't work either. For example,

set The_Path = C:\test 1

for /r "The_Path" %X in ("1106*atched candidates*.sps") do (ren "%X" "1206*.sps")



can this idea be built upon and made workable? Or any other solution provided please?


I was not aware that for /r had bugs, but you can quote the quote and my testing shows that it works:

Code: [Select]for /r """C:\test 1""" %X in ("1106*atched randomdates*.sps") do (ren "%X" "1206*.sps")

Quote from: No_hope_without_snacks on August 21, 2012, 09:51:09 AM

I appreciate this. It doesn't quite work as I keep getting the error file not found. The section of the code that says *atched randomdates*.sps" is there to find files with these characters (along with any other characters) in their names. As such it isn't a part of the directory structure as such.

It's part of the file system. I forgot to add /s after the /b
That recurses through folders.
7696.

Solve : Determining the length of an environment variable?

Answer»

I am TRYING to determine the LENGTH of an environment variable. I tried this:

Code: [Select]SET IN=%1
FOR /L %%I IN (1000,-1,1) IF "%IN:~!I!,1%"=="" SET LEN=!I!
echo "Length="%LEN%
with delayed environment substritution, but it did not work.

Thanks in advance for any help you may provide.Code: [Select]@echo off
>temp.file echo "%~1"
FOR %%a IN (temp.file) do set /a len=%%~za-4
echo "Length=%LEN%"
del temp.file
pauseUsing your technique:

Code: [Select]@echo off
setlocal EnableDelayedExpansion
SET var=%1
FOR /L %%a IN (1,1,1000) do (IF "!var:~%%a,1!"=="" SET LEN=%%a&goto :next)
:next
echo "Length=%LEN%"
pauseOr...

Code: [Select]@echo off
setlocal enabledelayedexpansion

set Var=%*

:: Note: %* is used if the variable may contain spaces.

:loop
set /A cnt+=1
if not "!Var:~%cnt%,1!"=="" goto loop

echo.Var contains %cnt% characters.
Or...

Code: [Select]@echo off
echo wscript.echo len(wscript.arguments(0)) > showlen.vbs
for /f "delims=" %%A in ('cscript //nologo showlen.vbs "%*"') do set vlen=%%A
del showlen.vbs
echo Length: %vlen% characters
One line, no vbs (as LONG as you can write in the same FOLDER)
Code: [Select]ECHO %envar%>x & FOR %%A IN (x) DO SET /A strlength=%%~zA - 2 & del x

7697.

Solve : Compressing Multiple Files with 7zip via CMD?

Answer»

I am trying to COMPRESS over 100 files to 7z in 7zip. However, I have to select each files to compress them.

As you can tell, this will be a very long process so I was HOPING to compress them all at once. 7zip seems to not have this option which is rather annoying.

However, I have found this command prompt CODE which compresses folders into .7z. The code is this -

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\"

Now, how I do use this code to compress files, not folders?

The code is actually saved in a bat file where when opened, it will do its job.

ThanksCode: [Select]@echo off
for %%X in (*.*) do "c:\Program Files\7-Zip\7z.exe" a "%%~nX.7z" "%%X"

If you start them all at the same time (which can be done) you MAY run out of resources, but the above should process an ENTIRE folder.

7698.

Solve : Big banks using DOS?

Answer»

Hi,
I have just been to my bank - one of Australia's largest. The manager showed me his screen. It is in DOS. He says they run 7 systems, but a lot of what they do is still in DOS. How do they cope with networks and interface with other systems? Surely this can not be NTVDM.
GeofflAre you sure it is MS-DOS and not the NT family (NT, XP, Vista, W7, W8) command line interface? Having said that, if these are MS-DOS applications running under Windows there are proprietary and free add-ons that ALLOW them to access networks.
The manager has spent 20 years working for this bank. He told me that the bank did not want to pay for all their systems to be rewritten at once. This system is to open new accounts (I would think an important part of their business). I do believe that PUSHD works ACROSS networks if you SET them up correctly.


EDIT: What program allows (easyer) networking? Might want to look at that.What is PUSHD ?Quote from: geoffl on August 22, 2012, 03:48:00 AM

What is PUSHD ?

It's a command to change the current directory.


Not really sure what it has to do with this, particularly because it's not on DOS systems (rather being a part of the NT command interpreter)

Quote
This system is to open new accounts (I would think an important part of their business).

This is precisely why they are still using the DOS implementation. By updating the software and system, they have everything to lose, and nothing to gain; First, new systems are prone to problems both technologically (migrating old databases,adapting defunct database formats, conversions,ETC) as well as employee-wise, since they would need to retrain their staff to use the new system, and mistakes and problems that crop up as a result of that need to be DEALT with as well. This is no different for things like cash registers, which are equally important for the business of a retail store. Many of them use DOS-based software as well- because it works.

usually the way it works in these places is they keep using the software until it no longer meets their needs; either they have new business requirements and cannot change the program because they don't have any of the original devs, don't actually own the software, or a myriad of other things. Once that happens, they then move forward. For example, grocery stores in my area predominantly used a DOS-based system, but I noticed that with the introduction of the Harmonized Sales Tax, many of them migrated to Windows-Based POS terminals, which leads me to believe the original software was not flexible enough for adding HST to sales, or something to that effect.
7699.

Solve : Does %1 have limitation on certain characters?

Answer»

That looks just LIKE what I was looking for.
Need to try it out. It will take a little while.
Thanks a lotCorrection (important!)

I forgot to make the all occurences of var delayed-expansion ( !var! ) in each line in the loop


for %%A in (\^" equal and comma semi space) do (
set var=%%A
if !var!==\" set url=!url:!var!=!
if !var!==equal set url=!url:!var!==!
if !var!==and set url=!url:!var!=^&!
if !var!==comma set url=!url:!var!=^,!
if !var!==semi set url=!url:!var!=^;!
if !var!==space set url=!url:!var!=^ !
)

I get an error:
'The syntax of the command is incorrect.'
I copied and pasted.
Can you see something wrong in the code?
ThanksCode: [Select]
@echo off
setlocal enabledelayedexpansion
set url=\"equalandcommaspacesemisemisemi\"
set ReplaceList=equal and comma semi space

echo Start
echo url %url%
echo.

echo Remove first two characters
set url=%url:~2%
echo url %url%
echo.

echo Remove final two characters
set url=%url:~0,-2%
echo url %url%
echo.

echo.
echo In loop...
for %%A in (%ReplaceList%) do (
set search=%%A
if "!search!"=="equal" set repl==
if "!search!"=="and" set "repl=^&"
if "!search!"=="comma" set repl=,
if "!search!"=="space" set "repl= "
if "!search!"=="semi" set repl=;
for %%b in ("!search!") do for %%c in ("!repl!") do SET "url=!url:%%~b=%%~c!"
echo url !url!
)

echo.
echo Finished loop
echo url %url%


Code: [Select]Start
url \"equalandcommaspacesemisemisemi\"

Remove first two characters
url equalandcommaspacesemisemisemi\"

Remove final two characters
url equalandcommaspacesemisemisemi


In loop...
url =andcommaspacesemisemisemi
url =^&commaspacesemisemisemi
url =^&,spacesemisemisemi
url =^&,space;;;
url =^&, ;;;

Finished loop
url =&, ;;;This works well.
Very tricky loop inside the main loop.
Just a minor thing, the line in the loop with "repl=^&", doesn't require the inverted commas or the '^'.
Also at the end the echo %url% requires to be echo !url! on my system.
With echo %url% I just get '='.
But, I now have it working.
Thanks a lot.
Quote from: Frank on July 07, 2012, 05:45:12 PM

Also at the end the echo %url% requires to be echo !url! on my system.
With echo %url% I just get '='.

That is because you changed set "repl=^&" to set repl=&. Quotes and caret are both necessary if you want to use %url% at the end. Batch scripting has special characters and & in a string is notorious. (Did you not see the output listing I made?)

Briefly, when the command interpreter encounters certain "special characters" it treats them as control characters unless you make special arrangements. Usually this means "escaping" them. The caret (^) is the escape used for most special characters but some are differently escaped.

For example (you can try stuff like this out at the prompt)

A single ampersand is the command separator so an unescaped one means "everything after me is a new command" e.g. cls & dir & echo hello world

1. Ampersand (&) unescaped, setting the variable fails

Code: [Select]c:\>set string=cats & dogs
'dogs' is not recognized as an internal or external command,
operable program or batch file.

c:\>

2. Escaped in the SET statement, so that works...

Code: [Select]c:\>set string=cats ^& dogs

c:\>

but LOOK what happens when we try to expand the variable

Code: [Select]c:\>echo %string%
cats
'dogs' is not recognized as an internal or external command,
operable program or batch file.

c:\>


3. We both escape the & with a caret and enclose the assignment portion of the SET statement with quotes

The assignment works...

Code: [Select]c:\>set "string=cats ^& dogs"

c:\>

So does the expansion...

Code: [Select]c:\>echo %string%
cats & dogs

c:\>

Excellent page at http://www.robvanderwoude.com/escapechars.php where I got this table:


Escape Characters

Character to be Escape Remark
to be escaped sequence

% %% May not always be required in doublequoted strings, just try
^ ^^ May not always be required in doublequoted strings, but it won't hurt
& ^&
< ^<
> ^>
| ^|
' ^' Required only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used
` ^` Required only in the FOR /F "subject" (i.e. between the parenthesis), if backq is used
, ^, Required only in the FOR /F "subject" (i.e. between the parenthesis), even in doublequoted strings
; ^;
= ^=
( ^(
) ^)
! ^^! Required only when delayed variable expansion is active
\ \\ Required only in the regex pattern of FINDSTR
[ \[
] \]
" \"



Yes I noticed the '^' in your output listing. Not understanding the significance of the &, I thought it was a mistake. That's why I mentioned it.

Your explanation and description clears it up. I bookmarked the link you supplied. Without experts such as yourself, there would be no point in posting in forums such this.
I have learned a lot and have it all working now.
Thank you very much.I am working on a method where you use a table of replace pairs e.g. [equals =] [and &] [comma ,] which would remove the IF tests from the loop and make modification easier.
Quote from: Frank on July 08, 2012, 02:01:06 AM
I thought it was a mistake.

In general, I test scripts before posting them. That does not mean I don't make mistakes!
Note: whichever scheme you use, you will find that if you use simple replacement tokens such as and for &, comma for , etc you may break urls because for example sand will become s& and commander will become either ,nder or comm&er (depending on the order you do the replacement) and so on. This may not matter but if it does I'd use tokens you will never find in the range of urls you expect to process e.g. $$$$$$$and$$$$$$$ or replaceAND or whatever.


Code: [Select]
@echo off
setlocal enabledelayedexpansion
set url=\"equalandcommaspacesemisemisemi\"
set ReplaceList=equal and comma semi space

set url=\"http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\"

REM Alternative ways of building replace table string
REM set ReplaceTable="equal:=" "and:^&" "comma:," "semi:;" "space: "

set ReplaceTable=
set ReplaceTable=%ReplaceTable% "equal:="
set ReplaceTable=%ReplaceTable% "and:^&"
set ReplaceTable=%ReplaceTable% "comma:,"
set ReplaceTable=%ReplaceTable% "semi:;"
set ReplaceTable=%ReplaceTable% "space: "

echo Start
echo url %url%
echo.

echo Remove first two characters
set url=%url:~2%
echo url %url%
echo.

echo Remove final two characters
set url=%url:~0,-2%
echo url %url%
echo.

echo In loop...
for %%A in (%ReplaceTable%) do (
set "ReplacePair=%%~A"
for /f "tokens=1,2 delims=:" %%B in ('echo !ReplacePair!') do (
set "search=%%B"
set "repl=%%C"
For %%D in ("!search!") do (
for %%E in ("!repl!") do (
SET "url=!url:%%~D=%%~E!"
)
)
echo url !url!
)
)
echo.

echo Finished loop

echo unquoted url !url!

REM quotes will shield the & from the command interpreter
echo quoted url "%url%"




Code: [Select]Start
url \"http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\"

Remove first two characters
url http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\"

Remove final two characters
url http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1

In loop...
url http://www.tek-tips.com/threadminder.cfm?pid=287andpage=1
url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1
url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1
url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1
url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1

Finished loop
unquoted url http://www.tek-tips.com/threadminder.cfm?pid=287&page=1
quoted url "http://www.tek-tips.com/threadminder.cfm?pid=287&page=1"

WOW, you've been busy.
This is great. Just tried it.
Thanks again.Tidied up and some (hopefully) clarifying comments...

Code: [Select]
@echo off
REM you need this
setlocal enabledelayedexpansion

set url=\"http://www.tek-tips.com/threadminder.cfm?pidequal287andpageequal1\"

REM Alternative ways of building replace table string
REM (1) all in one line
REM set ReplaceTable="equal:=" "and:^&" "comma:," "semi:;" "space: "

REM (2) Start with blank string and append elements one by one (note SPACES)
set ReplaceTable=
set ReplaceTable=%ReplaceTable% "equal:="
set ReplaceTable=%ReplaceTable% "and:^&"
set ReplaceTable=%ReplaceTable% "comma:,"
set ReplaceTable=%ReplaceTable% "semi:;"
set ReplaceTable=%ReplaceTable% "space: "

echo Start
echo url %url%
echo.

echo Remove first two characters which are \"
set url=%url:~2%
echo url %url%
echo.

echo Remove final two characters which are \"
set url=%url:~0,-2%
echo url %url%
echo.

echo In loop...
REM read each element of replace table; the spaces betwen the elements are the delimiters
for %%A in (%ReplaceTable%) do (

REM remove quotes using ~ variable MODIFIER
set "ReplacePair=%%~A"

REM Split pair into 2 tokens at : character (arbitrarily chosen)
for /f "tokens=1,2 delims=:" %%B in ('echo !ReplacePair!') do (

REM Prepare string substitution
REM Search is first (explicit) loop variable %%B
set "search=%%B"

REM Replace is second (implicit) loop variable %%C
set "repl=%%C"

REM This is a trick to use variables in string substitution
For %%D in ("!search!") do (
for %%E in ("!repl!") do (

REM Execute string substitution
SET "url=!url:%%~D=%%~E!"

)
)

echo url !url!

)
)
echo.

echo Finished loop

REM Delayed expansion or quotes will shield the & from the command interpreter
echo unquoted url !url!
echo quoted url "%url%"

This will make it a little easier to figure out how it works.
Great
7700.

Solve : Send email after completion of batch file execution?

Answer»

is there any way to send an email after completion of the batch file execution?Try this:

Code: [Select]::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: defaults
set [emailprotected]
set [emailprotected]
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=mail.server.com.au
set Auth=user
set Pass=pass
set fileattach=

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

call :createVBS "email-bat.vbs"

call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
DEL "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
goto :EOF

:createVBS
set "vbsfile=%~1"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = objArgs(0)
echo >>"%vbsfile%" objEmail.To = objArgs(1)
echo >>"%vbsfile%" objEmail.Subject = objArgs(2)
echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
remdon't know why, but your code didn't work for me Foxidrive. If it doesn't end up working for you rkp, here's one you could try. Only got it to work for gmail so far though (must have a gmail account to send from)

Code: [Select]
'Usage: cscript sendemail.vbs <email_[emailprotected]> "<subject_line>" "<email_body>" "<optional:email_attachment_path>"
'Ex. No attach: cscript sendemail.vbs [emailprotected] "test subject line" "test email body"
'Ex. W/ attach: cscript sendemail.vbs [emailprotected] "test subject line" "test email body" "c:\scripts\log.txt"

'***********
'****CONFIGURE THE FROM EMAIL ADDRESS AND PASSWORD

Const fromEmail = "[emailprotected]"
Const password = "xxxxxxxxxx"

'****END OF CONFIGURATION
'***********

Dim emailObj, emailConfig
Set emailObj = CreateObject("CDO.Message")
emailObj.From = fromEmail
emailObj.To = WScript.Arguments.Item(0)
emailObj.Subject = WScript.Arguments.Item(1)
emailObj.TextBody = WScript.Arguments.Item(2)

If WScript.Arguments.Count > 3 Then
emailObj.AddAttachment WScript.Arguments.Item(3)
End If

Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = fromEmail
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
emailConfig.Fields.Update

emailObj.Send

Set emailobj = nothing
Set emailConfig = nothing
you'll want to SAVE this as a mail.vbs

then using your batch file navigate to it and use the command:
Code: [Select]mail <[emailprotected]> "<subject>" "<body>"
or
Code: [Select]mail <[emailprotected]> "<subject>" "<body>" "<path:\\attachment>"

if those don't work, you could try the more wordy version
Code: [Select]cscript sendemail.vbs <[emailprotected]> "<subject>" "<body>" "<path:\\attachment>"

if you put mail.vbs in your system32 folder (you may not want to) you can do this without navigating to it's locationLemonilla,
Foxidrive's code WORKS just fine. You just need to tweak it for your smtp servers settings.This might be an alternative to CDO which has been deprecated on newer Window versions. If you can, try downloading Blat which can be run STANDALONE or part of a batch file.

If you have access to Powershell, a cmdlet specific for this purpose is available (Send-MailMessage) or it can be scripted with the SMTP client object.

Greetings all,

I have had success testing foxidrive's code on yahoo.com, gmail.com
and earthlink.net using XP SP3 and Win 7 Home Edition

rkp, should you wish to enhance the capabilities of foxidrive's
code, for example to have more than one line of text in the
'body' of the email, then I would suggest a review of Timo Salmi's code
which can be found at: www.netikka.net/tsneti/info/tscmd.php

Have a look at item number 188.

Best wishes!Quote from: Ocalabob on August 24, 2012, 06:31:44 PM

rkp, should you wish to enhance the capabilities of foxidrive's
code, for example to have more than one line of text in the
'body' of the email, then I would suggest a review of Timo Salmi's code
which can be found at: www.netikka.net/tsneti/info/tscmd.php

Have a look at item number 188.

Best wishes!

Thanks Ocalabob, and I confirm that there are other good solutions at Timo's link.