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.

6801.

Solve : xcopy and rd command limitation?

Answer» XCOPY

in folder C:\test I have 50 folders from Folder1 to Folder50

I want to copy few folders with same name in C:\test2

Code: [Select]xcopy C:\test\Folder3 C:\test2 /y /s /e
xcopy C:\test\Folder8 C:\test2 /y /s /e
xcopy C:\test\Folder12 C:\test2 /y /s /e
it is copying EVERYTHING from Folder3, Folder8 & Folder12 to C:\test2 instead Copying each folder itself.

I want to copy those folders with everything inside these to C:\test2
how to do it? is there any other command should be used ?

RD

Same case (vise versa) with RD command

Code: [Select]RD /S /Q C:\test\Folder4
RD /S /Q C:\test\Folder6
RD /S /Q C:\test\Folder15
I want to delete all files and folders inside above folders but don't want to delete folders.

I have searched for these answers so much, but no solution found.Testing the issue there are two problems. The target folders NEED a \ at the end, and those same folders have to be specified.

I tested this on drive d:

Code: [Select]@echo off
set drv=d:
xcopy %drv%\test\Folder3 %drv%\test2\Folder3\ /y /s /e
xcopy %drv%\test\Folder8 %drv%\test2\Folder8\ /y /s /e
xcopy %drv%\test\Folder12 %drv%\test2\Folder12\ /y /s /e
pause

Here is one way to solve the RD folder issue. There are other ways.

Code: [Select]@echo off
for %%a in (Folder4 Folder6 Folder15) do (
RD /S /Q C:\test\%%a
MD C:\test\%%a
)
thanks foxidrive xcopy method you told is more than perfect.
for single or perticular folders it's ok
I want to mix with FOR command
say if we have to find a folder(s) named "tobecopied" to destnation folder
we can make list as you told in previous post
how it will pick folder name itself.

Quote from: foxidrive on July 13, 2013, 04:01:43 AM

Here is one way to solve the RD folder issue. There are other ways.

Code: [Select]@echo off
for %%a in (Folder4 Folder6 Folder15) do (
RD /S /Q C:\test\%%a
MD C:\test\%%a
)

regading above method, it removing and creating it again,

not the perfect solution, but anyway it will serve purpose very well.

same case as xcopy, to get list from FOR command and removing those folders having "Check" name in it.

I was WONDERING to get 2 things done with one shot.

I hope I have EXPLAINED very well, if it's not clear, please reply, I will explain with example.

thanksQuote from: novice84 on July 13, 2013, 06:55:45 PM
for single or perticular folders it's ok
I want to mix with FOR command
say if we have to find a folder(s) named "tobecopied" to destnation folder
we can make list as you told in previous post
how it will pick folder name itself.

That would depend if the folder to be copied is in the current folder, or if it is somewhere in a folder tree.
The simplest code is different for the two cases.


Quote from:
regading above method, it removing and creating it again,
same case as xcopy, to get list from FOR command and removing those folders having "Check" name in it.

Do you want to copy a set of folders with "Check" in the name, and then remove all files/folders from them but leave the Check folders? Are they in one folder or are they in a directory tree? Where are they being copied to?

Please explain the task a little more clearly.Quote from: foxidrive on July 13, 2013, 08:17:23 PM
That would depend if the folder to be copied is in the current folder, or if it is somewhere in a folder tree.
The simplest code is different for the two cases.

Please forgive my lack of knowledge, I thought it would be simple with just PUSHD command to change path in any case.

well, I have both cases, one to copy from same drive from one location to other, and another case to copy from different drive to C:\somewhere. I prefer to do this now from one drive to another e.g.

find folder having name(s) "*ToBeCopied" from C:\reports to D:\archieve\test
difficult part could be to find it under directory tree in subfolders keeping the same name

Quote from: foxidrive on July 13, 2013, 08:17:23 PM
Do you want to copy a set of folders with "Check" in the name, and then remove all files/folders from them but leave the Check folders? Are they in one folder or are they in a directory tree? Where are they being copied to?

yes you understood correctly. I prefer to leave original folder tree as it is. Just copy folders to Archieve folder on different drive (in case I need to trace back past history), and delete contents from inside of source folders, leaving folders behind.

what I am doing at the moment, I am getting list of folder with For command, which I need to copy/remove inside content.
Then copying each folder manually DELETING contents from source folders after that.My question was: are there folders in a tree that have to be copied? and I think from previous posts and your comments that the answer is yes.

Try this:

Code: [Select]@echo off
set "target=D:\archieve\test"
set "source=C:\results"
set "text=ToBeCopied"
setlocal enabledelayedexpansion
pushd "%source%"
for /f "delims=" %%a in ('dir /b /s /a:d ') do (
set "folder=%%~nxa"
if not "!folder:%text%=!"=="!folder!" (
xcopy "%%a\*.*" "%target%%%~pnxa\" /s/h/e/k/f/c
pushd "%%a"
rd /s /q "%%a" 2>nul
popd
)
)
popd
6802.

Solve : help with how to make cdrom on windows 3.1?

Answer»

hi every ONE, I need some help, I have a an old computer and its runing windows 3.1, what I need help with making the cdrom work on windows3.1 oe make it on dosYou need a cdrom driver for MSDOS and some cdroms require a certain driver, instead of a generic drive.
In config.sys you add something like this with any switches you need.

device=c:\dos\atapi.sys

The drive has to be SET properly in hardware - with cable/chip select or master/slave jumpers.Quote from: andreamillspaugh on June 25, 2013, 09:36:31 PM

hi every one, I need some help, I have a an old computer and its runing windows 3.1, what I need help with making the cdrom work on windows3.1 oe make it on dos

With an IDE drive, you can use various generic drivers. One of the more common is OAKCDROM.SYS.

in config.sys, you need to load the driver:

Code: [Select]DEVICE=C:\DOS\OAKCDROM.SYS /D:OAKCD
(You can use DEVICEHIGH as well).

Then you need to use MSCDEX.EXE to associate and 'mount' the driver as a DISK drive:

Code: [Select]mscdex /D:OAKCD /L:E

Yes, that's good advice there, BC.
6803.

Solve : Problems with command line starting up?

Answer»

I recently got infected with a virus and since my antivirus failed, I had to manually clean up the entire thing. I've managed to restore everything except for a reference to the executable file that seems to pop up as soon as I run "cmd.exe". As soon as the COMMAND line is launched, I get an error message indicating that the file I had CLEANED up could not be found for running. I've tried going through the "cmd.exe" structure USING a hex editor but have failed to discover where these instructions have been appended. Could someone please help me here?

P.S. If this is the wrong place to post, I am absolutely SORRY and would like to be redirected to the right section.
Thank you.Search the registry. Better STILL, download autoruns.exe from Microsoft and examine all the entries for file not found and remove them.

6804.

Solve : New DOS user need help with copy command?

Answer»

How would you view only the .com files in the C:\windows\system32 directory?
How would you copy all the .com files in the C:\windows\system32 directory to a directory named JUNK?

I am new to computers and taking an intro class and not getting this. Would appreciate your assistance.It's nice to see someone learning, and to say so. Some people try to get homework done by subterfuge.

How would you view only the .com files in the C:\windows\system32 directory?

dir "C:\windows\system32\*.com" /b /a-d

The /b is optional (which returns only the brief names) and so is the /a-d (which is designed to eliminate any folders that end in .com)

Try the COMMAND to see how it looks with and without the /b in it. The /a-d is UNLIKELY to make a difference in this case, but you can add /p to make it pause on every screen full.

How would you copy all the .com files in the C:\windows\system32 directory to a directory named JUNK?

copy "C:\windows\system32\*.com" "c:\junk"

This assumes you have permissions to create a JUNK folder in the root of c: (and that it already exists)
Thank you very much for your assistance. I know see how it is done and feel more confident in my abilities. My lack of understanding was with the quotation marks. Thanks again for getting me on my way. You're welcome.

One point I should make clear is that while the quotation marks can always be used, but they are only needed when the path or filespec contains spaces and & characters (and when using environment variables that CONTAIN spaces and any other 'poison' characters).@foxidrive
Good job netting that QUESTION. I was concerned that Salmon Trout
might get hooked on the OP's thread. That's a pearl-er! If you see a shark LURKING around, don't let him put the bite on you for a few squid.

6805.

Solve : Need Batch file assistance?

Answer»

I am requesting ASSISTANCE with a batch file I can't SEEM to get working on XP or Windows 7. Below is the contents of the batch file. The main goal of the batch file is to delete some items from several different locations whether it be on Windows 7 or XP Pro.
On Windows XP, I get the following result when run from a command prompt:
"Windows XP or prior detected. and was unexpected at this time."
On Windows 7, I get the following result when run from a command prompt:
"Windows 7 detected. in was unexpected at this time."
Thanks for any assistance.

@echo off
IF EXIST "%userprofile%\APPDATA" (
ECHO Windows 7 Detected.
SET ProfileBase=%SystemDrive%\Users
SET AppDirL=APPDATA\Local
) ELSE (
ECHO Windows XP or prior detected.
SET ProfileBase=%SystemDrive%\Documents and Settings
SET AppDirR=All Users\Start Menu\Programs\Startup
)



IF EXIST "%userprofile%\APPDATA" (
FOR /R %ProfileBase%\%%G in (.) DO del "%%G\QuickMate.lnk"
FOR /R %ProfileBase%\%%G in (.) DO del "%%G\CX.ht"
) ELSE (
del "%ProfileBase%\%AppDirR%\QuickMate.lnk"
del "%ProfileBase%\%AppDirR%\CX.ht"
)


FOR /R %ProfileBase%\ %%G in (.) DO del "%%G\QuickMate.lnk"
FOR /R %ProfileBase%\ %%G in (.) DO del "%%G\CX.ht"

Insert a space before %%G

From the FOR help (type FOR /? at the prompt)

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

See the space before %variable? This is compulsory in all FOR variations.


I have not tried this on XP

On Windows 7 the modified script attempts to delete a shortcut called "QuickMate.lnk" from every FOLDER under every user's Appdata and you get hundreds or thousands of messages like these. It didn't get as far as trying to delete all the non-existent CX.ht files because I stopped it.

Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Device Metadata\dmrccache\en-US\b23e9717-e78f-4c14-97b3-6418c327b3b8\Wind
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\Feeds for United Kingdom~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\Microsoft Feeds~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\{5588ACFD-6436-411B-A5CE-666AE6A92D3D}~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\{5588ACFD-6436-411B-A5CE-666AE6A92D3D}~\WebSlices~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\2IA0GS01\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\51K0ZC2L\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\6BKUTNB7\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\BPE2BTL4\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\DBFSPX48\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\PO52DLB9\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\S9635VN1\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\Y96IAOW4\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\FORMS\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IME12\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IMJP12\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IMJP8_1\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IMJP9_0\QuickMate.lnk



Suggestion:

@echo off
IF EXIST "%userprofile%\APPDATA" (
ECHO Windows 7 Detected.
SET ProfileBase=%SystemDrive%\Users
SET AppDirL=APPDATA\Local
) ELSE (
ECHO Windows XP or prior detected.
SET ProfileBase=%SystemDrive%\Documents and Settings
SET AppDirR=All Users\Start Menu\Programs\Startup
)

Echo PERFORMING task (please wait)

IF EXIST "%userprofile%\APPDATA" (
FOR /R %ProfileBase%\ %%G in (.) DO if exist "%%G\QuickMate.lnk" del "%%G\QuickMate.lnk"
FOR /R %ProfileBase%\ %%G in (.) DO if exist "%%G\CX.ht" del "%%G\CX.ht"
) ELSE (
if exist "%ProfileBase%\%AppDirR%\QuickMate.lnk" del "%ProfileBase%\%AppDirR%\QuickMate.lnk"
if exist "%ProfileBase%\%AppDirR%\CX.ht" del "%ProfileBase%\%AppDirR%\CX.ht"
)

Echo Done

Pause

6806.

Solve : search and get the values into new text file?

Answer»

I'm trying to CAPTURE specfic strings from a text file and place them in an excel workbook. I NEED the payment and the chk number side by side so payment in column A and chk num that corresponds to the payment in column B if possbile if not a txt file will be ok. The code i m using now which is below just puts them in a new text file and its not excactly how i want to the file to output. This is what i need from the file.

1. payment total and the amount anything after in that line is not needed
2. CHECK/EFT NUMBER and chk noanything after in that line is not needed

ex.
payment total 21115.36
CHECK/EFT NUMBER: 0000011111111
Code: [Select]
find /i "CHECK/EFT NUMBER" "C:\test\New Folder\*.txt" >> "C:\test\New Folder\log.txt"

find /i "PAYMENT TOTAL:" "C:\test\New Folder\*.txt" >> "C:\test\New Folder\log.txt"




[recovering disk space, attachment deleted by admin]Code: [Select]@echo off

FOR /F "tokens=1-3 delims= " %%G in ('type pcplus.txt ^|findstr /C:"PAYMENT TOTAL:" /C:"CHECK/EFT NUMBER:"') DO (
IF "%%G"=="PAYMENT" >>log.txt set/p"=%%G %%H %%I "<nul
IF "%%G"=="CHECK/EFT" >>log.txt echo %%G %%H %%I
)
Output from the file you supplied.
Code: [Select]PAYMENT TOTAL: 21115.36 CHECK/EFT NUMBER: 0000011111111
PAYMENT TOTAL: 11189.01 CHECK/EFT NUMBER: 0000011111111
PAYMENT TOTAL: 16.18 CHECK/EFT NUMBER: 0000011111111
PAYMENT TOTAL: 1188.00 CHECK/EFT NUMBER: 0000011111111
PAYMENT TOTAL: 12130.17 CHECK/EFT NUMBER: 0000011111111
PAYMENT TOTAL: 2102.22 CHECK/EFT NUMBER: 0000011111111
great! thanks squashman. if possible can you explain what is occuring on these two lines after the >>log.txt for example whats removing the the data after the payment amount and how doesthe script know where the payment amount ends and to remove anything after it? also if possbile can the file be output like so...

Code: [Select]PAYMENT TOTAL: CHECK/EFT NUMBER:
21115.36 0000011111111
11189.01 0000011111111
16.18 0000011111111
1188.00 0000011111111
12130.17 0000011111111
2102.22 0000011111111


I Have the bottom portion using the below code im just trying to get the first row to show as above

Code: [Select]FOR /F "tokens=1-3 delims= " %%G in ('type pcplus.txt ^|findstr /C:"PAYMENT TOTAL:" /C:"CHECK/EFT NUMBER:"') DO (

IF "%%G"=="PAYMENT" >>log.txt set/p"=%%I "<nul
IF "%%G"=="CHECK/EFT" >>log.txt echo %%I

)



If you know that is what you want as the first line of your output file then hard code it before the for loop. K.I.S.S.thank again for the tip . Sorry but i realize im going to need a few more things from the file.
i'm trying to see how i can also capture
PAYMENT DATE:
RUN DATE:
also need the the ones i listed below but im note sure how i can go about capturing them since the names are always changing. But there always in the same position in the file
EMPIR
PAYERS CC
and also need CC separately. CC


Code: [Select]@echo off
Echo PAYMENT TOTAL: CHECK/EFT NUMBER: PAYMENT DATE: RUN DATE: PAYERS: PAYER: >>log.txt
FOR /F "tokens=1-3 delims= " %%G in ('type pcplus.txt ^|findstr /C:"PAYMENT DATE:" /C:"RUN DATE:" /C:"PAYMENT TOTAL:" /C:"CHECK/EFT NUMBER:"') DO (

IF "%%G"=="PAYMENT" >>log.txt set/p"=%%G %%H %%I "<nul
IF "%%G"=="CHECK/EFT" >>log.txt echo %%G %%H %%I

REM I tried the below but it does not work
IF "%%G"=="PAYMENT DATE:" >>log.txt echo %%G %%H %%I
IF "%%G"=="RUN DATE:" >>log.txt echo %%G %%H %%I
)
Quote from: daillest319 on June 25, 2013, 11:11:12 PM

thank again for the tip . Sorry but i realize im going to need a few more things from the file.
That has been a common theme on most of the forums i belong to lately.

Please explain in more detail what you all need. Please show me an example of a few transactions of input and what you want the output to look like.attached is a new sample. the output need to look like below but does not need all the spaces i placed bewteen each field. i just did that so it would be eaiser to read.

i need
PAYMENT TOTAL:
CHECK/EFT NUMBER:
PAYMENT DATE:
RUN DATE:
PAYERS: located underneath payment date
PAYER: located in the smae line as the GPO BOX
PAY: located underneath payment date the last two letters after the payer name
ex. EMPIRS CC = CC


Code: [Select]PAYMENT TOTAL: CHECK/EFT NUMBER: PAYMENT DATE: RUN DATE: PAYERS: PAYER: PAY:
21115.36 0000011331111 06/19/13 06/20/13 EMPIRS CC EMPIR CC
11189.01 0000011221111 06/19/13 06/20/13 HPPPPP HP HPPPP HP
16.18 0000011341111 06/18/13 06/20/13 APPPPA AP APPPP AP
1188.00 0000011441111 06/19/13 06/20/13 EMPIRS CC EMPIR CC
12130.17 0000011541111 06/17/13 06/20/13 EMPIRS CC EMPIR CC
2102.22 0000016411111 06/16/13 06/20/13 APPPPA AP APPPP AP


[recovering disk space, attachment deleted by admin]EDITED: This works with your sample text:

Code: [Select]@echo off
>"newfile.txt" echo PAYMENT TOTAL: CHECK/EFT NUMBER: PAYMENT DATE: RUN DATE: PAYERS: PAYER: PAY:
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4,12" %%a in (pcplus.txt) do (
if defined check_eft_number (
>>"newfile.txt" echo !payment_total! !check_eft_number! !payment_date! !run_date! !payers! !payer! !pay!
set payment_total=
set check_eft_number=
set payment_date=
set run_date=
set payers=
set payer=
set pay=
)
if "%%b"=="DATE:" set payment_date=%%c& set run_date=%%e
if "%%c"=="ELECTRONIC" set pay=%%b& set payers=%%a %%b
if "%%a"=="GPO" set payer=%%d
if "%%b"=="TOTAL:" set payment_total=%%c
if "%%b"=="NUMBER:" set check_eft_number=%%c

)



PAYMENT TOTAL: CHECK/EFT NUMBER: PAYMENT DATE: RUN DATE: PAYERS: PAYER: PAY:
21115.36 0000011331111 06/19/13 06/20/13 EMPIRS CC EMPIR CC
11189.01 0000011221111 06/19/13 06/20/13 HPPPPP HP HPPPP HP
16.18 0000011341111 06/18/13 06/20/13 APPPPA AP APPPP AP
1188.00 0000011441111 06/19/13 06/20/13 EMPIRS CC EMPIR CC
12130.17 0000011541111 06/17/13 06/20/13 EMPIRS CC EMPIR CC
2102.22 0000016411111 06/16/13 06/20/13 APPPPP AP APPPP AP

this works perfect foxidrive thank you so much. btw If you have any free time i would like to understand what occuring in the script if you can write notes to what each line is doing i would REALLY appericate it im just curious how it know where to grab certain string for example the string in the GPO line. thank you all again i really do appericate all the help i recieve in this forum.When you parse a file in a forINdo loop the default delimiter is tab and space. So for each line the spaces and tabs are removed and the remaining 'words' are attached to tokens.

You will see that I SPECIFIED tokens 1 to 4 and 12. If you COUNT the words in each line, which are each associated with %%a %%b %%c %%d %%e you can see that the if conditions are checking for a specific word on a specific spot on the line, and if that word is found then it sets a variable to the desired word.

When the last item in the set is found check_eft_number it echos all the stored variables on the next loop, and then resets them all to prepare for the next record.

So like very many batch files, it is tailored to the format of the text file.Quote from: daillest319 on June 26, 2013, 09:38:41 AM
this works perfect foxidrive thank you so much. btw If you have any free time i would like to understand what occuring in the script if you can write notes to what each line is doing i would really appericate it im just curious how it know where to grab certain string for example the string in the GPO line. thank you all again i really do appericate all the help i recieve in this forum.
If you turn ECHO ON and watch each line execute it will also help you understand what is going on.
And remember in the future to explain everything you need upfront otherwise the code has a tendency to change drastically when you change the parameters. That wastes everyone's time and remember the help is free around here.
6807.

Solve : copy and rename file with path name?

Answer»

Hi Foxidrive
sorry I didn't look at first sight and replied.
thanks for that, I checked it and changed it 3 different versions as per requirement before I saw you reply.
I have a question again
As I asked for advise before is there any such kind of thing if you don't KNOW DOS and C++ you can't leran/Understand VB very well (as my 2 friends advised)
my KNOWLEDGE of DOS is very of few basic commands which I learned 15 years before in school.
I want to learn VBA to automate few task in SOFTWARES like excel and many other applications which has customisation thru VBA so we can automate our daily tasks.
what's your advise as per your experience should I spend time learning DOS and C++ or VBA we can learn without learning these.I haven't used VBA so I can't GIVE an informed opinion.
another problem that I noticed was that you can't change drives with 'cd'

so change 'cd %1' to
Code: [Select]%~d1
cd %1

this should put you in the write directory. You can add 'cd' to a third line and it will echo the current directory for you to double check if you want.Quote from: Lemonilla on June 29, 2013, 08:34:25 AM

another problem that I noticed was that you can't change drives with 'cd'

You can use the cd command to change to a folder on another drive if you use the /d switch. I always use that switch after cd, it has no effect if the new folder is on the same drive.

you are in c:\test, you want to go to D:\pictures\holidays you do this: cd /d D:\pictures\holidays, it is the same as doing first D: and then cd pictures/holidays.
Quote from: Salmon Trout on June 29, 2013, 09:01:33 AM
I always use that switch after cd, it has no effect if the new folder is on the same drive.

That means, more clearly, the /d switch does no harm if the new folder is on the same drive. Quote from: Lemonilla on June 29, 2013, 08:34:25 AM
another problem that I noticed was that you can't change drives with 'cd'

so change 'cd %1' to
Code: [Select]%~d1
cd %1

this should put you in the write directory. You can add 'cd' to a third line and it will echo the current directory for you to double check if you want.
That was the point of my previous post and told you to read the help for that command. You were not using the correct syntax.Quote from: Squashman on June 29, 2013, 12:53:47 PM
That was the point of my previous post and told you to read the help for that command. You were not using the correct syntax.
My APOLOGIES, I missed your earlier post. Thank you for pointing it out, could come in handy.
6808.

Solve : DOS batch question on variable addition?

Answer»

Hi, is anyone here good at DOS scripts? I am new in dos script and having this simple script that adds the date but it doesn't work as I expected. Any help WOULD be greatly appreciated.

Here is the script,

@echo off

for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
(set dow=%%m)&(set %%i=%%n)&(set %%J=%%o)&(set yyyy=%%p)))
echo %dd%
for /l %%c in (1 1 3) do (
echo %%c
set /a var1 = %dd% + %%c%
echo %var1%
Set d=%yyyy%%mm%%var1%
echo %d%)

I expected that the variable %d% would be '20130710', then adds one (%%c as 1) to the %var1% would be %dd% + 1 = 11 (%dd% is 10 for today), and %d% would be '20130711', but %d% never change and stay as '20130710'. Anyone know why?

THANKS,
Alan110I think its related to that fact that you require:

setlocal EnableDelayedExpansion

Such as referenced at this site to allow to INCREMENT++ a variable. http://stackoverflow.com/questions/6097579/batch-variable-not-incrementingHere's a script to give you the date tomorrow, yesterday, in 2 weeks time, etc.

Code: [Select]:: Date foward & backward
@echo off
if "%~2"=="" (
echo to get todays date use call "%~n0" today 0
echo to get yesterdays date use call "%~n0" today -1
echo to get 25 days before 19441213 call "%~n0" 1944/12/13 -25
echo to get 1250 days in the future call "%~n0" today 1250
echo.
echo Add a third parameter if you want a separator in the date string
echo EG: to use - as in YYYY-MM-DD for today's date
echo call "%~n0" today 0 -
echo.
pause
goto :EOF)

set date1=%1
set qty=%2
set separator=%~3
if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set day=%result:~0,4%%separator%%result:~4,2%%separator%%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)
pause

6809.

Solve : Move program files folder in Windows 7 batch file?

Answer»

I am looking to create a batch file that can move the program files and program files (x86) folders to another LOCATION. I only intend on using this right after a fresh installation of win 7, so no programs are effected by the move. I know the basic process of doing this in command prompt, but I need to turn this into a batch.

Here are the commands I need to use in order:

ckill explorer.exe
sleep 3000
xcopy program files
xcopy program files (x86)
takeown /F * /r program files
cacls program files /t /G %username%:F
takeown /f * /r program files (x86)
cacls program files (x86) /t /g %username%:F
rd /s program files
rd /s program files (x86)
mklink /d program files [destination]
mklink /d program files (x86) [destination]
explorer.exe

(ckill and sleep are my own if you were wondering)

That's is the basic idea, but I'm really bad at writing batches. I can program pretty well in other languages, but I don't like dealing with the strange nuances of batch. I want to make the batch prompt for the destination program files and have me enter in the path. So I could enter D:\Programs and it would copy all the files to D:\Programs and D:\Programs (x86). I'm probably missing some attrib, quotes, etc. So if anyone can help me make this into a working batch, I'd appreciate it.

EDIT: Just realized I probably wasn't clear about how this "moves" the program files folder. It basically copies all the files to the destination and then creates a symlink Program Files and Program Files (x86), so when windows installs to C:\Program Files it is actually installing to another directory. This is different than simple shortcuts because it fools windows into thinking C:\Program Files is a real folder, when it's not.Move program files?
Sorry, I don't understand.
Have you tested this concept?
Did you see where somebody else did that?
Why do you want to do that?

Why use CKILL and SLEEP when Windows 7 has that capability?DO NOT RUN THIS

Look it over to see if it does what you want first. I would also advise you have someone else on this board look it over. I don't recognize a good deal of this stuff and could very easily mess SOMETHING up.

Code: [Select]@echo off
set /p destProgramFiles=Program Files Destination ^>
set /p destProgramFiles86=Program Files (x86) Destination ^>


REM I have not heard of ckill, so im going to assume it's the same as taskkill
taskkill /im "explorer.exe"
REM I havent used sleep before, but timeout measures in seconds
timeout /t 30
xcopy "%programfiles%" "%destProgramFiles%" || set error=1
xcopy "%programFiles(x86)%" "%destProgramFiles86%" || set error86=1

takeown /f * /r "%programFiles%"
cacls "%programFiles%" /t /g %username%:F

takeown /f * /r "%programFiles(x86)%"
cacls "%programFiles(x86%" /t /g %username%:F

if not %error% == 1 rd /s "%programFiles%"
if not %error86% == 1 rd /s "%programFiles(x86)%"

mklink /d "Program Files" "%destProgramFiles%"
mklink /d "Program Files (x86)" "%destProgramFiles86%"

explorer.exe
I like how xcopy isn't invoked recursively.Thanks for the code. I didn't know win 7 had the built in timeout feature. I did know about taskkill. However, the reason I didn't use it was because when it's used to terminate explorer, for some reason it allows explorer to start right back up again in about a second. I was using ckill because the problem does not occur with that program. Maybe there is a way to make taskkill work right?

The code looks pretty good except for the error BC mentioned and you forgot a space before (x86) in a few places. I've fixed up the code and I'll get it tested as soon as I have some time to set up a Win 7 VM. (I already have it moved on my Win 7 and I don't want to move it back and possibly mess things up.)

Quote

Move program files?
Sorry, I don't understand.
Have you tested this concept?
Did you see where somebody else did that?
Why do you want to do that?

Yes, I have it done manually on my Win 7 machine. Yes, I think I might have seen a tutorial on making directory symlinks before. I don't think most people use it for program files though, but it works great.

There are several reasons why I want to:
1. I like to keep my C: drive containing only the OS because I use it to boot from an SSD and want to conserve space on that drive.
2. If I EVER need to wipe my OS, I can just backup the software reg hive and then reload my OS and copy it back and not have to reinstall my programs (I've not needed to yet, but I think it should work.)
3. I like to keep my files organized on different partitions (mainly just for ease of access and asthetic reasons)

The reason I want to make a batch for it is just in case I build more systems for myself or other people. Whenever I build a system, I tend to put a small fast SSD as the OS drive and the data on a slow cheap normal hard drive with more capacity per $.Quote from: Linux711 on June 30, 2013, 07:26:11 PM
2. If I ever need to wipe my OS, I can just backup the software reg hive and then reload my OS and copy it back and not have to reinstall my programs (I've not needed to yet, but I think it should work.)

It only works if the programs don't load support DLLs and other files in system32 etc. I've done it and many programs do work, some don't.Quote from: foxidrive on July 01, 2013, 04:08:36 PM
It only works if the programs don't load support DLLs and other files in system32 etc. I've done it and many programs do work, some don't.
Yeah. Isn't that the point of the WINSXS folder.Quote from: Squashman on July 01, 2013, 07:04:06 PM
Yeah. Isn't that the point of the WINSXS folder.

I think you are right.
6810.

Solve : Copy the last modified file using batch File?

Answer»

Hi any one can help me on my problem??
when i run my batch file this ERROE comes out,

@ECHO off

setlocal
set srcDir=C:\Paul1\
set destDir=C:\Paul2\
set lastmod=
pushd "%srcDir%"
for /f "TOKENS=*" %%a in ('dir /b /od 2^>NUL') do SET lastmod=%%a
%%a was unexpected at this time.
if "%lastmod%"==""
The syntax of the command is INCORRECT.
echo Could not locate files.&goto :eof
copy "%lastmod%" "%destdir%"
The system cannot find the file specified.

kindly tell me whats wrong with it.

Advance Thanks!
Cheers!

PaulkanTry this - the errors didn't SEEM to all apply to your code.

Code: [Select]@echo off
setlocal
set "srcDir=C:\Paul1\"
set "destDir=C:\Paul2\"
set "lastmod="
pushd "%srcDir%"
for /f "delims=" %%a in ('dir /b /od /a-d 2^>NUL') do SET "lastmod=%%a"
if not defined lastmod (echo Could not locate files.&goto :eof)
copy "%lastmod%" "%destdir%"
popd

6811.

Solve : Solved: How to create a new file out of .bat :Solved?

Answer»

Dear Everyone.
This Forum Had Been Solved...
Thanks To everyone.
And A Special Thanks To......

DUSTY



****************************************************************************************************************
****************************************************************************************************************
****************************************************************************************************************

Hi there,
Do anyone know how to create a new file out of .bat
i MEAN the .bat file can create another new .bat file when you open it......

This is what i FOUND but it can only create one line.
Code: [Select]echo msg * Hello>hello.bat
Please help......echo command(s)>hello.bat
echo command(s)>>hello.bat
echo command(s)>>hello.bat
etc..
etc..

OR---

(
echo command(s)
echo command(s)
echo command(s)
)>>hello.bat

Quote from: Dusty on January 10, 2010, 09:50:03 PM

echo command(s)>hello.bat
echo command(s)>>hello.bat
echo command(s)>>hello.bat
etc..
etc..

OR---

(
echo command(s)
echo command(s)
echo command(s)
)>>hello.bat



Thanks that is really works.Just pointing out that MSG doesn't exist on all computers. So if what I'm fairly sure your trying to do is right, it won't work on all computers, and it won't look like a "critical message", etc. Isn't MSG that Carp found in oriental food ? ?Quote from: patio on January 12, 2010, 07:11:22 PM
Isn't MSG that Carp found in oriental food ? ?
Yep. it had been solved?
i though i can solve it.
6812.

Solve : path variable saving?

Answer»

Hello,

i can't execute system32 commands LIKE ping

when i type path in cmd i get this

PATH=C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system3
2;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShel
l\v1.0\;C:\Users\Meaw\AppData\Roaming\Dashlane\2.1.1.38487\bin\Firefox_Extension
\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components

i'd like to add c:\WINDOWS\system32

when i add it using the gui path variables then i reboot if i retry ping it doesn't work.

if i type path=c:\Windows\system32\ in cmd

then i type path

it gives me PATH=c:\Windows\System32\

then i CLOSE the cmd

i reopen it and it gives me the old path

how to save the path variable ?

Welcome to CH.
You can help others help you by including information about which Windows operation system you are now sing.
Is it Windows 7 64 bit?
You should b a able to use ping by using run and typing in CMD and hit enter.
That should give you a command box
It is already in your path.
Code: [SELECT]%SystemRoot%\system32SystemRoot should be already set to C:\Windows which makes that entry C:\Windows\system32Quote from: harlock59 on July 10, 2013, 01:03:03 PM

how to save the path variable ?

Change it in the control panel area for ALTERING the environment variables.
6813.

Solve : Parsing through a .doc file?

Answer»

I was wondering if there is a way to parse a .doc file and capture certain key elements and output them to a file? This is what I ATTEMPTED:

Code: [Select]::Creates the directory !Grants if it does not exist
if not exist !Read MKDIR !Read
pause

for %%I in (*Deployment*.doc) do (
find "OMG" %%I >> !Read/Reader.txt
pause
)
The .doc file, DeploymentPlan.doc, is as follows:

OMG WORKED
1
!! !
LOLOMG
OMGWTF

and the output is ATTACHED, when I copied it into this window it formats it differently to match what the .doc originally has, however when in the .txt it uses characters to represent what I now realizes are line breaks.

Thanks in advance.


[Saving space, attachment deleted by admin]you don't really read doc FILES like that. Use COM and vbscript. See here and here for 2 examples.Well can you execute a find on a word doc and have it produce expected results, not just all information within the doc?a word DOCUMENT is written in a binary format.

best way to do something like this is to use Word through OLE Automation.

6814.

Solve : Windows Start Up Bat File?

Answer»

Hello,

I need to guidance.

I want to create a a bat file that will install a program VIA a WINDOWS logon bat file.
runas /noprofile /user:(DOMAIN)\domain user "\\network path\directory\file.exe"

The problem I have is I do not want users to enter an admin password (users no not have admin rights)

Can this be done with a bat file ?

Thanks for the helpHello, and welcome to COMPUTER Hope!

From what I understand, you wish to run a remotely located file without requiring the user to enter a password to access it.
'runas' does not seem to allow for such a program. You might consider placing the file within a profile without a password, and then add instructions to simply press enter. You can suppress the output of 'runas' by adding "1>nul 2>&1" at the end.

EDIT: You could use 'start' instead, not sure if you can use that for remote work though.Sounds slightly NEFARIOUS to me...Why not use Group Policy? You are on a domain.

6815.

Solve : split output of commands?

Answer»

So I want to write all my input and output from cmd to both the screen and a file. Is this POSSIBLE?

Code: [Select]cmd 1>log 2>&1 1>[SCREEN] 2>[SCREEN]
In *nix type operating systems you have the TEE command, this is not available in Windows, but there are various workarounds, just look for Windows Tee susbtitutes on Google. Or look here...

http://stackoverflow.com/questions/796476/displaying-windows-command-prompt-output-and-redirecting-it-to-a-file


Thanks! Apparently 'tee' works, though it only sends the output. I'll KEEP LOOKING though.What do you mean by the "input"?
This:
Code: [Select]
C:\Users\Lemonilla>echo ok
ok


is RECORDED as:
Code: [Select]
C:\Users\Lemonilla>
ok
What HAPPENED to the echo OK command?

It sounds like you want to save the console buffer to a text file; this is quite hard to do in the normal cmd.exe console, but you can do it with alternative consoles like Alternatve Windows Console

http://sourceforge.net/projects/windowsconsole/?source=dlp

6816.

Solve : Batch not finding file when it should [Fixed]?

Answer»

Hi everyone. First post here, so I guess a quick introduction is in order. I'm Vincent, and I'm starting off learning how to make some (basic) .BAT files. I already know some C++ and Java and ActionScript etc., but I still haven't started DOS, heh.

Soooo anyways.

My first file is just trying to rename "first.txt" to "second.txt". However, I haven't GOTTEN that far because the batch file can't ever seem to find the file specified. It can find the folder the file is IN just fine, but it can't seem to find any file within that folder at all.

Code: [Select]@echo off
if exist "C:\Documents and Settings\Vincent\My Documents\first.txt" (
echo Yeah
) else (
echo No
)
pause
That results in "No." However, if I change the PATH to "C:\Documents and Settings\Vincent\My Documents", it ECHOS "Yes".

I'm confused. Thanks!
First things first. is there a file called first.txt and is it definitely located in the folder ""C:\Documents and Settings\Vincent\My Documents"? Not in a subfolder? if it is there, are you quite sure it is named exactly as you describe?

What is the result of this command

Code: [Select]DIR "C:\Documents and Settings\Vincent\My Documents\first.txt"







C:\Documents and Settings\Bill Richardson\My Documents>type second.bat
Code: [Select]@echo off

cd "C:\Documents and Settings\Bill Richardson\My Documents\"

dir first.txt

ren first.txt second.txt
type second.txt
OUTput:
C:\Documents and Settings\Bill Richardson\My Documents>second.bat
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\Documents and Settings\Bill Richardson\My Documents

01/14/2010 02:48 PM 8 first.txt
1 File(s) 8 bytes
0 Dir(s) 306,211,250,176 bytes free
hello

C:\Documents and Settings\Bill Richardson\My Documents>@Salmon: Yeah, I'm sure that there's "first.txt" spelled as it should be in the right folder. I also tried my batch with other files in the same folder and got the same confusing result. The result of your code is:

Code: [Select]Volume in C drive has no label.
Volume Serial Number is COA7-AD25

Directory of C:\Documents and Settings\Vincent\My Documents

File Not Found
@Bill: Running the code you typed (but with my name, obviously) gives me the same output but with two lines of "The system cannot find the file specified" at the end. I'm not quite sure what you're telling me to do though, with >type second.bat and such.

Am I correct in assuming that this situation indicates something's very wrong or, more probably, I'm making some really stupid mistake?

Once more, thank you.
For DIR-ing folders, add a \ at the end to make sure it goes IN the desired folder. For example:

"%userprofile%\My Documents\"
(C:\Documents and Settings\%username%\My Documents\"Quote

Am I correct in assuming that this situation indicates something's very wrong or, more probably, I'm making some really stupid mistake?

No, what is stupid is using Batch as a programming tool..
when you don't have too!


Quote from: Helpmeh on January 14, 2010, 03:20:14 PM
For DIR-ing folders, add a \ at the end to make sure it goes IN the desired folder. For example:

"%userprofile%\My Documents\"
(C:\Documents and Settings\%username%\My Documents\"

Whoops, duh. When I DIR the folder with a backslash I do get its contents in the output. It says that my "first.txt" file is actually "first.txt.txt", which I guess is because I saved the file as "first.txt". I wasn't aware that the batch file would automatically add on the file extension that's usually hidden from view. I think that's the problem all along; lol. Thank you!

Problem solved, I'm silly. Thanks for the quick response everyone. Quote
I wasn't aware that the batch file would automatically add on the file extension that's usually hidden from view.

The command line sees everything. In my opinion only newbies and grandmas hide file extensions. You can fix it in Explorer folder options.


I think I'll do that now, heh. Next time though speak up, my HEARING aid's busted. Also, your cookies are ready. Quote from: Vincenator on January 14, 2010, 04:12:21 PM
I think I'll do that now, heh. Next time though speak up, my hearing aid's busted. Also, your cookies are ready.
Chocolate chip?Of course, with love in every bite.Quote from: Vincenator on January 14, 2010, 10:45:30 PM
Of course, with love in every bite.
GRANDMA!
lol, I'm glad you figured it out. P
6817.

Solve : compact does not work?

Answer»

Thanks for taking the time to ready my question.

I want to compact Temp.xlsx using the compact command.

I'm trying this: compact /c "C:\Users\bmcintyr\Desktop\TEMP\Temp.xlsx"

The above line is the only line in my .bat file. The .bat file is located on my desktop

The only thing that happens is that the above line repeats over and over endlessly until I do a Ctrl + c.

I've searched on line and think I'm doing everythign correctly. Any help would be great.

Thanks,
Brad


Update: I opened a command prompt and pasted the line after the > and it RAN... I recevied this message:
"Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\bmcintyr>compact /c /s "C:\Users\bmcintyr\Desktop\TEMP\Temp.xlsx"

Compressing files in C:\Users\bmcintyr\Desktop\TEMP\

Temp.xlsx 12508 : 12288 = 1.0 to 1 [OK]

1 files within 1 DIRECTORIES were compressed.
12,508 total bytes of data are stored in 12,288 bytes.
The compression RATIO is 1.0 to 1.

C:\Users\bmcintyr>"

So nothing was compressed, and I don't see a second file in the TEMP folder.
Brad


[Win 7 SP1, 32 bit]No compression utility, including the windows Compact utility, can COMPRESS files much if they are already compressed. An xlsx file is already compressed - it is a Zip file in disguise. This is why the compacted size is only a tiny bit smaller than before. You actually achieved 220 bytes reduction in file size. That is all you can expect for this type of file. When you run Compact on a file, it compacts the file you named, it does not produce a new file in the same folder.


Quote from: mbrad on July 08, 2013, 09:49:24 AM

The only thing that happens is that the above line repeats over and over endlessly until I do a Ctrl + c.

You called the batch file compact. The batch file ran, looked for a filename called compact and found it in the current folder, so ran your bat again, and again, and again...

It's a trap we all fall into at some time.
6818.

Solve : skip specific folder in FOR Command?

Answer»

Quote from: Lemonilla on July 04, 2013, 09:20:14 AM

Quick question of my own (more addressed to others on the board), why would you not write it all in one place.

[...]

Is there any differences, or is it just a stylistic thing?

I wonder if some people prefer doing it the CALL way because they don't like DELAYED expansion for some reason.
Quote from: Lemonilla on July 04, 2013, 09:20:14 AM
Quick question of my own (more addressed to others on the board), why would you not write it all in one place.
Code: [Select]setlocal EnableDelayedExpansion
for /f "delims=" %%A in ('dir /b /a-d * ') do (
set "name=%%~nxA"
set "name=!name:old=old01!"
ren "%%~A" "!name!"
)
Is there any differences, or is it just a stylistic thing?

You lose the ! characters from the names. It matters for common things like movie names and music titles.Quote from: novice84 on July 04, 2013, 07:30:54 AM
1. but still question remains what if I put any other FOR command or any other command under this code for some different purpose, will it work ? & how it will work ? how separate next code from this.

This is a for loop and it calls a subroutine.
You can add commands to it but placement is important.

try it with the commands below and it might be clearer


@echo off
:: start here
pushd "C:\test\folder"
:: this for loop sends each filename to the subroutine
for /f "delims=" %%a in ('dir /b /a-d * ') do call :next "%%a"
popd
:: this is the end of the batch file on the goto :eof
echo Done
pause
goto :eof


:next
:: for each filename this subroutine is executed
echo The file being processed is "%~nx1"
set "name=%~nx1"
set "name=%name:old=old01%"
echo The file is being renamed from "%~1" to "%name%"
ren "%~1" "%name%"
:: you can add commands to change what it does or to do extra things
pause



Quote from:
3. another question what is
Code: [Select]goto :eofin the code. Even if I remove it, doesn't make any difference!!!!!???

It stops the subroutine being executed one final time, after all the filenames have been sent through the subroutine.

Thanks for your comments.questions related to original topic :
I am trying to make a list of folders having words in folder name "NEEDtoCheck"
It could be complete name of folder or part of folder name.

Code: [Select]dir /b /s /a:d | find /I "NEEDtoCheck" > list2.txt
above code works fine. But it also includes sub folders. e.g. list look like this :
C:\TEST FOLDER\old\this NEEDtoCheck
C:\TEST FOLDER\old\this NEEDtoCheck\too

second line is unwanted. how not to GET this ?

In another batch for some reason I could not get this code working.

Code: [Select]pushd "C:\TEST FOLDER"
for /D "delims=" %%B in ('dir /b /s /a:d ^| find /I "NEEDtoCheck" ') do echo Check %%~fB>> list2.txt
popd
pause
Thanks all in advanceQuote from: novice84 on July 06, 2013, 03:47:31 AM

I could not get this code working.

Code: [Select]for /D "delims=" %%B in

Study FOR documentation - type FOR /? at the prompt or else Google for Windows command line & batch syntax guides. You need to start doing this.

You are mixing FOR /D and FOR /F syntax. No "options" block allowed with /D switch. It will repeat the options block in an ERROR message, for example like this: "delims=" was unexpected at this time. (Didn't you see this?)

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

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]



Quote from: novice84 on July 06, 2013, 03:47:31 AM
Code: [Select]dir /b /s /a:d | find /I "NEEDtoCheck" > list2.txt
above code works fine. But it also includes sub folders.

If you study the DIR documentation, (type DIR /? at the prompt) and then look at the switches you are using, (/b /s /a:d) you will understand why sub directories are being listed, and what you need to change or remove. Don't be afraid of experimenting.

with all due respect Salmon Trout
For command I have not understood yet, as I have just started learning.
But I have done experiment with DIR command. Please see complete code (as it is in batch file) below again :

Code: [Select]pushd "C:\TEST FOLDER"
dir /b /s /a:d | find /I "NEEDtoCheck" > list2.txt
popd
and results example as below :
C:\TEST FOLDER\old\this NEEDtoCheck
C:\TEST FOLDER\old\this NEEDtoCheck\too
C:\TEST FOLDER\old\this NEEDtoCheckalso
C:\TEST FOLDER\old\this also NEEDtoCheck
C:\TEST FOLDER\old\this also NEEDtoCheck\too

there are no words "NEEDtoCheck" in "too" folder.

I put /S to search in subdirectories, if don't put it just search in C:\TEST FOLDER and no result as folder list I need exist in deep down in directories.

/a:d I have added to list only folders

I hope you will understand my QUESTIONI think there was some misunderstanding with your aim - your descriptions were a little unclear.

This seems to be what you are after and it should exclude all the folders that do not have NEEDtoCheck in them.

Code: [Select]@echo off
pushd "C:\TEST FOLDER"
for /f "delims=" %%a in ('dir /b /s /a:d') do (
echo "%%~nxa" | find /I "NEEDtoCheck" >> list2.txt
)
popd
THANKS FOXIDRIVE & Salmon Trout FOR YOUR HELP
IT'S NOT ONLY HELPED TO SAVE TIME BUT ALSO HELPED TO UNDERSTAND NEW THINGS.

Quote from: foxidrive on July 06, 2013, 10:38:56 PM
I think there was some misunderstanding with your aim - your descriptions were a little unclear.

You are right. Sometimes for a NOVICE it's not easy to explain and mix up & mess things.
sorry for confusion.

Quote from: Salmon Trout on July 06, 2013, 04:22:48 AM
It will repeat the options block in an error message, for example like this: "delims=" was unexpected at this time. (Didn't you see this?)

I tried to look what's happening but even without @echo off and putting pause at the end of code, screen just blink and I could not see what is error.Quote from: novice84 on July 07, 2013, 05:41:28 AM
I tried to look what's happening but even without @echo off and putting pause at the end of code, screen just blink and I could not see what is error.

If you start batch scripts from Windows Explorer by double clicking, if the script bombs out you may see nothing. To see error messages etc you can open a command prompt in the folder and start the batch script manually (by typing its name and then hitting ENTER)

6819.

Solve : Copying Files into a Unix enviroment with login?

Answer»

I am trying to figure out how to read a list of files to COPY and go through the directory and move those files into a Unix environment which has a login.

I know how to read the list and know how to copy files. I also do know the login information but would like it to prompt you to input the password for security reasons. My biggest issue is traversing to the unix environment. I tried a simple copy doing:

Code: [Select]copy test.txt <Unix Server>/<folder>
and as I expected it said "Incorrect syntax"

I appreciate your hlp.http://www.unix.com/unix-dummies-questions-answers/31386-copy-text-file-vi-editor-windows-clipboard.html

"From windows use command prompt and do telnet to the unix system.
your system."


C:\>telnet /?

telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]]
-a Attempt automatic logon. Same as -l option except uses
the currently logged on user's name.
-e Escape character to enter telnet client prompt.
-f File name for client side logging
-l Specifies the user name to log in with on the remote system.
Requires that the remote system support the TELNET ENVIRON option.
-t Specifies terminal type.
Supported term types are vt100, vt52, ansi and vtnt only.
host Specifies the hostname or IP address of the remote computer
to connect to.
port Specifies a port number or service name.

C:\>@bill, the telnet protocol is not meant for "transfer" or "copy" of files automatically. Also, Windows telnet client isn't capable for scripting either.
@OP, Use FTP, or the more secure SCP (part of SSH protocol). OR you can connect through samba and copy your files. Search the internet for these information.Yeah, I heard back from someone at WORK about it and they advised to use FTP. I haven't gotten a chance to try anything as I'm bogged down with work, however once I write them I'll update.Quote from: ghostdog74 on January 15, 2010, 10:26:56 AM

@bill, the telnet protocol is not meant for "transfer" or "copy" of files automatically. Also, Windows telnet client isn't capable for scripting either.
@OP, Use FTP, or the more secure SCP (part of SSH protocol). OR you can connect through samba and copy your files. Search the internet for these information.
[/color]


@ghostdog74:

The was no automatic condition by the Original Poster(OP),Grimbear13:

Grimbear13 wrote:
"I know how to read the list and know how to copy files.
I also do know the login information but would like it
to prompt you to input the password for security reasons."

Grimbear13 would like a prompt for the password. When we prompt a user and wait for a response, there is no automatic transfer at 3AM.

Ghostdog74 information might not work?
@OP, if you want to do basic file transfer, then it should be alright to use the windows FTP client. Turn on FTP daemon on your Unix machine and then transfer your files from windows. Of course you have to set your FTP configuration properly for security. Also, nowadays, SCP/SSH is used instead of FTP because its more secure. Set up passwordless SSH/SCP using key authentication. Then you WONT have to key in password everytime. Read the SCP/SSH documentation on how to set up key authentication. The last method, using samba, is another alternative. Its sort of like sharing Unix folders to the Windows world. (File sharing.) See the samba documentation for more. Its fairly easy to set up and once set up, you can use normal windows copy to copy your files to Unix. These are 3 methods i can think of, definitely not Telnet.
6820.

Solve : Is there a way to detect a carriage return from user input??

Answer»

Hello,

I was trying to create a simple batch file to lookup WHOIS information for website addresses.

Here's what I have so far.

@echo off

:INPUT1

cls
echo.
echo.
echo.
set/p "input1=> ENTER THE WEBSITE ADDRESS > "
whois %input1%
pause

:INPUT2

cls
echo.
echo.
echo.
set/p "input2=> WOULD YOU LIKE TO LOOK UP ANOTHER ADDRESS? (Y/N?) > "
if %input2%==Y goto INPUT1
if %input2%==y goto INPUT1
if %input2%==N goto END
if %input2%==n goto END
goto INPUT2

:END

exit

It works fine except for one thing. When it ASKS, "WOULD YOU LIKE TO LOOK UP ANOTHER ADDRESS? (Y/N?) >", if you hit the Enter/Return key it EXITS the program instead of being detected as an incorrect input, not (Y,y,N, or n), and sent back to INPUT2, to re-ask the question again.

If you hit another letter like G, it handles the error correctly, but it can't handle a carriage return.

How can I detect the carriage return as an error and send it back to re-ask the question again?Try this

Code: [Select]:INPUT2

cls
echo.
echo.
echo.


set input2=error


set/p "input2=> WOULD YOU LIKE TO LOOK UP ANOTHER ADDRESS? (Y/N?) > "
if %input2%==Y goto INPUT1
if %input2%==y goto INPUT1
if %input2%==N goto END
if %input2%==n goto END
goto INPUT2

:END
With the variable preset with a value, just pressing return should not change anything so will still hold "error" and be flagged as invalidYour program looks alright.
There is no test for CR m so it just loops again.
It only goes to the end if you hit N or n.
What does this mean?
Quote

If you hit another letter like G, it handles the error correctly, but it can't handle a carriage return.
Both are handled that same way.
Why do you say it does not handle the CR correctly?
G is not Y or y or N or n. And neither is CR.
Anything other than Y y N n loops in INPUT2.

Quote from: Geek-9pm on January 14, 2010, 12:46:32 PM
Your program looks alright.
There is no test for CR m so it just loops again.
It only goes to the end if you hit N or n.
What does this mean?Both are handled that same way.
Why do you say it does not handle the CR correctly?
G is not Y or y or N or n. And neither is CR.
Anything other than Y y N n loops in INPUT2.
EDIT: I stand corrected. CR retains the last value.If you have set /p answer=Prompt? and the user hits ENTER, the test "%answer%"=="" returns true
No, teh CR does not git a null.
gpl got it right.
You have to set the thing to a null before you make the test.
Only then CR will give null, because it already was null.Quote from: Geek-9pm on January 14, 2010, 03:23:34 PM
You have to set the thing to a null before you make the test.
Only then CR will give null, because it already was null.

You mean like this?

Code: [Select]@echo off
set answer=&set /p answer=Your input?
if "%answer%"=="" (
echo String: ENTER
) else (
echo String: %answer%
) But we need a loop to verify it.
set answer=&set /p does clear it to null, otherwise it would retain its prior value when the user hits return

Code: [Select]@ECHO QUIT or PARTY
@ECHO OFF
:PARTY1
set answer=&set /p answer=Your input ?

IF "%answer%"=="" (
echo ENTER
) ELSE (
echo %answer%
)
if "%answer%"=="PARTY" (
goto PARTY1
)

Thank You!@OP, don't have to make things so complicated. Use an infinity loop. something like this.
Code: [Select]:LOOP
1) ask for input
2) if input not "Y", "y","N","n" blah
-- goto LOOP
3) else breakHey guys,

Thanks for all of the replies and suggestions.

gpl's suggestion seemed the simplest to implement. I added the line below exactly where he said to, and the program works perfectly now, thanks to all of you, but special thanks to gpl.

Quote from: gpl on January 14, 2010, 12:40:50 PM

set input2=error

For anybody who is interested in creating a program to view website address information here is my final version.

You'll need to download the WHOIS utility from here

http://technet.microsoft.com/en-us/sysinternals/bb897435.aspx

Place the WHOIS.exe in the

C:\WINDOWS\system32

folder

Create a new .txt file on the desktop

Paste the code below into the .txt file


echo off


title WHOIS LOOKUP


::INPUT 1 SCREEN

:INPUT1

cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
set/p "input1=> ENTER THE WEBSITE ADDRESS > "


::LOOKUP SCREEN

:LOOKUP

cls
WHOIS %input1%
pause


::INPUT 2 SCREEN

:INPUT2

cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
set input2=error

set/p "input2=> WOULD YOU LIKE TO LOOK UP ANOTHER ADDRESS? (Y/N?) > "
if %input2%==Y goto YES
if %input2%==y goto YES
if %input2%==N goto END
if %input2%==n goto END
goto INPUT2


:YES

goto INPUT1


:END

exit


Change the .txt extention to .bat

Once you run it, you might want to change the command prompt properties to view it fullscreen.

Right-click on the blue title-bar at the top of the command prompt window, select Properties, then the Options tab.

Select the Window radial button.

Select the Layout tab.

Set the Screen Buffer Size: Width to 100, Height to 100.

Set the Window Size: Width to 125, Height to 54

Set the Window Position: Width to 0, Height to 0

Those settings seem to fit a 1024 x 768 screen well.

Here is an example of what is displayed if you look up www.yahoo.com


Whois v1.01 - Domain information lookup utility
Sysinternals - www.sysinternals.com
Copyright (C) 2005 Mark Russinovich

Connecting to COM.whois-servers.net...
Connecting to COM.whois-servers.net...
Connecting to whois.markmonitor.com...


MarkMonitor is the Global Leader in Enterprise Brand Protection.

Domain Management
MarkMonitor Brand ProtectionΓäó
AntiFraud Solutions
Corporate Consulting Services

Visit MarkMonitor at www.markmonitor.com
Contact us at 1 800 745 9229
In Europe, at +44 (0) 20 7840 1300


The Data in MarkMonitor.com's WHOIS database is provided by MarkMonitor.com
for information purposes, and to assist persons in obtaining information
about or related to a domain name registration record. MarkMonitor.com
does not guarantee its accuracy. By submitting a WHOIS query, you agree
that you will use this Data only for lawful purposes and that, under no
circumstances will you use this Data to: (1) allow, enable, or otherwise
support the transmission of mass unsolicited, commercial advertising or
solicitations via e-mail (spam); or (2) enable high volume, automated,
electronic processes that apply to MarkMonitor.com (or its systems).
MarkMonitor.com reserves the right to modify these terms at any time.
By submitting this query, you agree to abide by this policy.

Registrant:
Domain Administrator
Yahoo! Inc.
701 First Avenue
Sunnyvale CA 94089
US
[emailprotected] +1.4083493300 Fax: +1.4083493301

Domain Name: yahoo.com

Registrar Name: Markmonitor.com
Registrar Whois: whois.markmonitor.com
Registrar Homepage: http://www.markmonitor.com

Administrative Contact:
Domain Administrator
Yahoo! Inc.
701 First Avenue
Sunnyvale CA 94089
US
[emailprotected] +1.4083493300 Fax: +1.4083493301
Technical Contact, Zone Contact:
Domain Administrator
Yahoo! Inc.
701 First Avenue
Sunnyvale CA 94089
US
[emailprotected] +1.4083493300 Fax: +1.4083493301

Created on..............: 1995-01-18.
Expires on..............: 2012-01-18.
Record last updated on..: 2009-12-02.

Domain servers in listed order:

ns5.yahoo.com
ns3.yahoo.com
ns2.yahoo.com
ns1.yahoo.com
ns4.yahoo.com




MarkMonitor is the Global Leader in Enterprise Brand Protection.

Domain Management
MarkMonitor Brand ProtectionΓäó
AntiFraud Solutions
Corporate Consulting Services

Visit MarkMonitor at www.markmonitor.com
Contact us at 1 800 745 9229
In Europe, at +44 (0) 20 7840 1300
--

Press any key to continue . . .

Pretty cool huh?

Well thanks to everybody for the help, and I hope that my little program simplifies looking up website information with the WHOIS utility for somebody out there.
6821.

Solve : autoterminate bat file (FIXED)?

Answer»

Hello, I'm new here, I edited the following .bat file to opening bluray films as ISO FILES:

echo off
walle.iso
c:\arquiv~1\corel\dvd9\windvd.exe
exit

The .bat file is in the same directory that the Walle.iso file. Windvd will open and display ther bluray film without problems, but the msdos windows will stay open in the background, until Windvd is CLOSED. Is there a way to the .bat file open the ISO, open Winddvd and close itself imediatly? Best regards.what does the walle.iso line do?
The Walle.iso is only a link to a bluray film extracted from a disc. I have installed Virtual Clone Drive in my system. Clicking a .ISO file or having a ISO file listed in the BAT file automatically MOUNTS the bluray in the virtual CD drive, and WindDVD plays the movie. In that manner, I have a folder with links to .bat arquives that links to .ISO files . But would be better if the MSDOS window of the bat file autoterminate after opening WinDVD.Try this

Study the output of

Code: [Select]start /?
to understand more

Code: [Select]@echo off
walle.iso
start "" "c:\arquiv~1\corel\dvd9\windvd.exe"
exit



Ok, thanks, will try that.

6822.

Solve : Using ms-dos batch file to run programs in a window?

Answer»

Does anyone know how to use a MS-DOS batch file to run a GAME that is usually full screen in a window? I've SEEN it done with halo before so I know it's possible.

Midgetgretzkyuse the start command


start path_to_the_program_to_start

just put the command in a batch fileeasy,
start File_target

example:
start C:\"Documents and settings"\game.exeQuote from: louis123 on January 14, 2010, 08:13:42 PM

easy,
start File_target

example:
start C:\"Documents and settings"\game.exe
Not always that simple. (and that code won't WORK by the way)

Try
start /MAX Path_To_Program\Program.exe Quote from: Helpmeh on January 15, 2010, 01:20:11 PM

start /max Path_To_Program\Program.exe

Ah!! I forgot the /max!!! or /min......Quote from: Helpmeh on January 15, 2010, 01:20:11 PM
do you know why the old topic i had reply will be DIG up front every time?
I mean it suppost to be at it original place...
example,
topic a
topic b
topic c
(i reply the topic c...... and it will be dig up front)
topic c
topic a
topic b
Quote from: louis123 on January 17, 2010, 05:56:30 PM
do you know why the old topic i had reply will be dig up front every time?
I mean it suppost to be at it original place...
example,
topic a
topic b
topic c
(i reply the topic c...... and it will be dig up front)
topic c
topic a
topic b

The threads are in order of most recent reply (except the stickied threads).
6823.

Solve : Want To Create Shortcut with batch?

Answer»

hey guys...

Pls sum1 help me abt

How 2 create shortcut on desktop Using Batch FILE

i cud also prefer command line software with quiet mode

or

Directly with dos


i tried the command line

xcopy r11.exe %AllUsersProfile%\desktop\r11.lnk

wher am i going wrongyou can create shortcut with vbscript
Code: [Select]Set oWS = WScript.CreateObject("WScript.Shell")
shortCut = "C:\temp\myshortcut.lnk"
Set oLink = oWS.CreateShortcut(shortCut)
oLink.TargetPath = "C:\temp\test.bat"
oLink.WorkingDirectory = "C:\temp"
oLink.Save

Quote from: The_Game_Bane on December 11, 2009, 06:13:03 AM

hey guys...


How 2 create shortcuts on desktop Using Batch file


I tried the command line

xcopy r11.exe %AllUsersProfile%\desktop\

where am I going wrong.

You are right. The command line is the testing ground for batch.

Did the xcopy command work at the command line?:

xcopy r11.exe %AllUsersProfile%\desktop\

Place in batch file , mycopy.bat

C:\batch&GT;type mycopy.bat

xcopy r11.exe %AllUsersProfile%\desktop\

C:\batch> mycopy.bat
Quote from: billrich on December 11, 2009, 09:00:40 AM
You are right. The command line is the testing ground for batch.

Did the xcopy command work at the command line?:

xcopy r11.exe %AllUsersProfile%\desktop\

Place in batch file , mycopy.bat

C:\batch>type mycopy.bat

xcopy r11.exe %AllUsersProfile%\desktop\

C:\batch> mycopy.bat


No it didnt work it just creates a blank shortcut on desktop without any effect or iconIf the xcopy command does not work from the command line, the
xcopy command will not work inside a batch file.

The shortcut is an icon for the batch file.
___________

http://www.tnd.com/camosun/elex130/dosbatchtutor1.html


Making Batch Files


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

"A batch file is a normal text file, no programming involved. You type DOS commands into a text file, each one on a seperate line. Then, you give the text file a .bat EXTENSION instead of a .txt extension. Now, when you DOUBLE click the batch file(In Windows Explorer) or type its name at the DOS prompt, it will execute the commands.

First, we need to know some DOS commands. If you're a regular DOS user, you can skip this section and go to CREATING A BATCH PROGRAM. The main DOS commands we will use are copy, move, del, cls, and echo. The COPY command has this syntax: "

copy [source] [destination]

.
.
.
a shortcut is a LNK file, and is a completely separate file from it's target. Xcopy, copy, or any such command at the command line will copy the file, not create a shortcut to it.Quote from: billrich on December 11, 2009, 09:45:10 AM
If the xcopy command does not work from the command line, the
xcopy command will not work inside a batch file.
There was no issue with that, only an issue with the end-result.Quote from: Helpmeh on December 11, 2009, 04:59:10 PM
There was no issue with that, only an issue with the end-result.

I believe BC gave the perfect explanation of why The_Game_Bane 's method of creating a shortcut did not work.

The_Game_Bane was given detailed instructions of how to create shortcut for the batch file.

The following command did not work for The_Game_Bane from the command line or from a Batch file:

xcopy r11.exe %AllUsersProfile%\desktop\r11.lnk

What did work?

I don't know. No feedback.
Quote from: billrich on December 11, 2009, 05:40:37 PM
xcopy r11.exe %AllUsersProfile%\desktop\r11.lnk

this command copies r11.exe to the desktop and name it as r11.lnk, which is NOT a shortcut . Its the ORIGINAL file with a new name. That's how it "can't work" if what OP wants is a shortcut, with a LNK extension.


http://www.msfn.org/board/creating-shortcuts-installation-time-t29964.html&hl=creat+shortcut

Quote from: billrich on December 11, 2009, 06:49:46 PM

http://www.msfn.org/board/creating-shortcuts-installation-time-t29964.html&hl=creat+shortcut



From the linked page:
Code: [Select][Version]
Signature=$CHICAGO$

$CHICAGO$ refers to Win95. The OP has WinXP.

If it absolutely has to be batch, there is a batch program in the Windows NT Resource Kit which you can use. Look for Shortcut.exe.

Use shortcut /? from the command line for an explanaton of the switches needed.

Good luck. there is a software name as XXMKLINK

which gurantees to make shortcuts but i dont understand its switches


i cud also use that if i cud understoodhave you even tried the various solutions mentioned here? Quote from: ghostdog74 on December 11, 2009, 11:18:46 PM
have you even tried the various solutions mentioned here?

yes ive tried

but smthing or the other goes wrong with me
[I think ther solutions r correct, but im not able to apply them]
6824.

Solve : Hide .bat from User on Login?

Answer» QUOTE from: Helpmeh on January 17, 2010, 06:47:59 AM
That doesn't MEAN you DIG up DEAD topics.

so just put back the dead topic. Just IGNORE the topic and it will slip back down again.
6825.

Solve : Handling ! in filenames with SETLOCAL ENABLEDELAYEDEXPANSION?

Answer»

Hi there

I'm writing an incremental file BACKUP utility from the windows cmd prompt (XP Pro SP3) mostly for the fun of it (!) and am having trouble handling filenames containing the ! (exclamation point) character.
The ! seems to disappear from the filename before I can escape it, e.g.:
Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
echo.>"file^! a.txt"
for %%A in ("*.txt") do set MYFILE="%%~A"
set myfile=%myfile:!=^^!%
echo %myfile%
ENDLOCALIn the above example, the ! is visible in the set generated by the for statement, but is gone immediately afterwards.
- all PATHS and filenames are held in quoted vars e.g. set FNAME="c:\path\name.ext"
- I have tried escaping the ! with ^, ^^, and ^^^ without any success so far
- I need ENABLEDELAYEDEXPANSION for various bits of script throughout the cmd file

Any ideas?

Slainte

midders
P.S. alternatively; is it possible to turn ENABLEDELAYEDEXPANSION on and off without creating a new local environment? I've thought about just turning it on when it's needed and then using files to pass the vars back to the original environment, but it's a bit clunky and I was hoping to come up with a better solution.First off, in a for loop while delayed expansions are enabled, you need to replace the % (in regular variables) with !. Try using this code to escape the path.

Set myfile=!myfile:^!=^^^!!
Thanks for the response, but the line escaping the ! is not in the for loop, and AFAIK you can't use the :X= substitution syntax with for statement vars.

Also, the syntax you suggested (!myfile:^!=^^^!!) is invalid; it is treated by the shell as !myfile:^! and !=^^^! because the ! character takes precedence over everything else, even if it is escaped.Update:

I've implemented the file-based kludge that I referred to in my earlier post; i.e. SETLOCAL DISABLEDELAYEDEXPANSION globally and then use this sort of thing inside subroutines:
Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION
echo "!_TMPSTR:~%NSTART%,1!:!_TMPSTR:~%LEN_STUB%,%NCOUNT%!">"%TEMP%\cmdbak.var"
ENDLOCAL
set /p RETURN_VAR=<"%TEMP%\cmdbak.var"
del /f "%TEMP%\cmdbak.var">nul 2>nul
The result is that filenames with ! in them now work ok. However; filenames with % in them still fail. I've found that the special chars (!,%) are only retained in the unmodified for variable (%%A etc.), the moment that you assign it to another variable they are lost in translation.

I've found that I can use the same file-based kludge to preserve the special chars, but I'd still like to hear from anyone that has a better way.

Code: [Select]@SETLOCAL DISABLEDELAYEDEXPANSION ENABLEEXTENSIONS
echo.>"file%% a !b.txt"
for %%A in ("*.txt") do echo %%A>"%TEMP%\var.tmp"&call :FUNC_X "%TEMP%\var.tmp"
goto :FINISHED

:FUNC_X
set /p fname=<%1
echo %fname%
goto :EOF

:FINISHED
endlocal

6826.

Solve : Moving files based on their created date?

Answer»

Hi,

I wanted to move files from one folder to another folder based on their created "MONTH". using batch script...

For example, assume the following

Source folder - c:\New_folder
Dest folder - C:\dest

New_folder has few files that were created on January month and it has few files created on FEBRUARY month. I wanted to move files that were created on January month ONLY from source to destination?

Can you please help on this?

Thanks,

Thiru

What do you have so far ?Code: [Select]@echo off
dir /TC *.bat | findstr "2010"

rem dir /TC *.bat | findstr "01/"

rem dir /TC *.bat | findstr "01/" > mvdate.txt

dir /TC *.bat | findstr "2010" > mvdate.txt

for /f "tokens=5" %%i in (mvdate.txt) do echo %%i

for /f "tokens=5" %%i in (mvdate.txt) do copy %%i c:\dest\

rem for /f "tokens=5" %%i in (mvdate.txt) do mv %%i c:\dest\

dir c:\dest\
Output:
C:\>mvdate.bat
01/02/2010 11:09 AM 505 100files.bat
01/15/2010 10:35 AM 256 casp.bat
01/11/2010 12:47 PM 467 ckzero.bat
01/10/2010 11:59 AM 195 contin.bat
01/10/2010 01:40 PM 130 go2.bat
01/11/2010 01:03 PM 238 listdir.bat
01/08/2010 09:46 AM 288 listDirec_astxt.bat
01/11/2010 08:15 PM 510 mp.bat
01/18/2010 11:36 AM 295 mvdate.bat
01/10/2010 09:25 AM 249 namepic5.bat
01/02/2010 11:44 AM 160 namfiles.bat
01/10/2010 07:56 AM 252 partial.bat
01/10/2010 03:40 PM 350 shutter.bat
01/04/2010 05:17 PM 335 st10.bat
01/10/2010 02:00 PM 366 twit.bat
01/14/2010 03:50 PM 739 Vincenator.bat
01/12/2010 08:51 AM 34 xmail.bat
01/06/2010 03:40 PM 902 yesterday.bat
100files.bat
casp.bat
ckzero.bat
contin.bat
go2.bat
listdir.bat
listDirec_astxt.bat
mp.bat
mvdate.bat
namepic5.bat
namfiles.bat
partial.bat
shutter.bat
st10.bat
twit.bat
Vincenator.bat
xmail.bat
yesterday.bat
file(s) copied.

Volume Serial Number is F4A3-D6B3

Directory of c:\dest

01/18/2010 11:47 AM .
01/18/2010 11:47 AM ..
01/02/2010 12:05 PM 505 100files.bat
01/15/2010 10:40 AM 256 casp.bat
01/11/2010 12:55 PM 467 ckzero.bat
01/10/2010 12:09 PM 195 contin.bat
01/10/2010 01:41 PM 130 go2.bat
01/11/2010 01:11 PM 238 listdir.bat
01/08/2010 02:55 PM 288 listDirec_astxt.bat
01/11/2010 08:17 PM 510 mp.bat
01/18/2010 11:48 AM 295 mvdate.bat
01/10/2010 09:29 AM 249 namepic5.bat
01/02/2010 11:47 AM 160 namfiles.bat
01/10/2010 08:01 AM 252 partial.bat
01/10/2010 04:29 PM 350 shutter.bat
01/04/2010 05:18 PM 335 st10.bat
01/10/2010 02:15 PM 366 twit.bat
01/14/2010 04:11 PM 739 Vincenator.bat
01/12/2010 08:52 AM 34 xmail.bat
01/06/2010 03:40 PM 902 yesterday.bat
18 File(s) 6,271 bytes
2 Dir(s) 303,166,734,336 bytes free

C:\>What happens if the script is not run until 1 Feb, will it not also move files created in Feb?

Quote from: Dusty on January 18, 2010, 02:14:39 PM

What happens if the script is not run until 1 Feb, will it not also move files created in Feb?


dir /TC *.bat | findstr "01/"

(not tested yet. I'm not on my computer.)But 01/ could be the date day as in mm/dd/yyyy 02/01/2010.

Also what happens if the users date format is not mm/dd/yyyy but is in some other permissable format, say dd-mm-yyyy?

Quote from: Dusty on January 18, 2010, 06:10:18 PM
But 01/ could be the date day as in mm/dd/yyyy 02/01/2010.

Also what happens if the users date format is not mm/dd/yyyy but is in some other permissable format, say dd-mm-yyyy?

I'm not Thiru, the Original Poster. I cannot answer your questions.

Thiru, the Original Poster needs a new design and new solution.

Dusty please provide your solution.BillRichardson :

I'm not Thiru, the Original Poster. I cannot answer your questions.

Thiru, the Original Poster needs a new design and new solution.

Dusty please provide your solution.

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

Hi all,

Thanks to all for your reply.

I have "MM/DD/YYYY" date format in my system.

And as discussed below, we have confusion between MM and DD... "01" can be month and it can be also date in february month.. So I do not know how to filter...

can we use "/01/" as finding string. If it has "/" at both the ends (begining and end), it should be DD only... If it has "/" on the right side end ONLY, it should be MONTH..

Am I making sense?
Please correct if it is wrong!!

Thanks again. Quote from: thiru
can we use "/01/" as finding string. If it has "/" at both the ends (begining and end), it should be DD only... If it has "/" on the right side end ONLY, it should be MONTH..

Think about the actual dates 01/01/2010 and 02/01/2010 in the format mm/dd/yyyy. If /01/ is used as the search argument the day will be found but that's not what you want, if the search argument 01/ is used the month will be found in the first date but again the day will be found in the second date because 01/ exists in that date too as 02/01/2010.

What has to happen is that the month part of the date must be identified. I think this is achieved this in the following reply. Fingers crossed.Quote from: Billrich
Dusty please provide your solution.
Aw darnit, do I have to?? Bit of a rush on this one..

In the following script no allowance is made for paths/filenames containing spaces. The permitted date formats require the month component to be numeric, if the month is expressed as Jan Feb etc the script will fail. The script is not fully tested. If/when the user is satisfied with the script's performance the 4th and 5th lines should be Rem'd and Copy in the ultimate For loop CHANGED to Move.

Code: [Select]@echo off
cls
setlocal enabledelayedexpansion

if exist c:\dest\*.* echo y | del dest\*.* > nul
if exist c:\dest\ rd c:\dest\

:: Establish date format..
for /f "skip=1 tokens=1-4 delims=(/.-)" %%1 in ('echo. ^| date') do (
set first=%%2
set secnd=%%3
set third=%%4
)

:: Set month position in date format..
if /i %first% equ mm set month=1
if /i %secnd% equ mm set month=2
if /i %third% equ mm set month=3

:: Create output directory if not exist..
if not exist c:\dest\ md c:\dest\

:: Examine file date & copy/move those which fit criteria specified..
pushd c:\new_folder\
for /f %%A in ('dir /b /tc') do (
set datime=%%~tA
for /f "tokens=1-3* delims=/.- " %%1 in ("!datime!") do (
if %%%month% equ 1 copy %%A c:\dest\ > nul
)
)
popd
echo.&echo.

:: Display output files for checking purposes..
dir c:\dest\*.*

exit /b

Hope this helps.

Hi Dusty,

Yep. You are correct!!

01/01/2010 and 02/01/2010 are the dates that we took for example here.

Shall we use IF statement using "AND".... Like this find "01/" but NOT "/01/"..

Is this correct?

Thanks,
Thiru
Hi Thiru.

Go ahead and try what you suggest if you prefer to use Find which is not one of my FAVORITE tools.

Quote from: Dusty on January 19, 2010, 03:30:36 AM
Hi Thiru.

Go ahead and try what you suggest if you prefer to use Find which is not one of my favorite tools.




Dusty,

I'm a beginner for Batch Script. However I have used the code which you posted here. Is it working fine? I did not GET any output from it.

Please help me.

Thanks,
Thirulearn how to use vbscript, which is better at date processing and many other stuff.

Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
strDestination = objArgs(1)
Set objFolder =objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
strFileName = strFile.Name
strDate = strFile.DateLastModified
mth=Month(strDate)
' move files in January
If mth = 1 Then
WScript.Echo "copying .."&strFileName & " " & strDate
objFS.MoveFile strFileName , strDestination & "\" & strFileName
End If
Next


save as mymove.vbs and on command line

Code: [Select]c:\test> cscript //nologo mymove.vbs c:\test c:\destination
Thiru - yes, it's working for me. Hate to ask you, did you set up the input directory with files created in Jan?

Found a bug, the dir command in my original script is failing and defaulting to C:\ - code amended.
6827.

Solve : Visual Basic, convert number value to decimal?

Answer»

Quote from: BC_Programmer on JANUARY 19, 2010, 02:18:44 PM

yeah, SILLY me, since the POST title said "Visual Basic" I foolishly ASSUMED you were using "Visual Basic"
Of COURSE!
6828.

Solve : Batch File to open PDF9.0 Copy the content to clipborad open in mspaint n save?

Answer»

Hi all,
I need to create batch file to PERFOM below activity:
there is place where i will DUMP my pdf file (in version 9.0) ..say in D drive n TEST1 folder.
now when batch file runs...
1)Open the latest pdf file uploaded in folder TEST1
2)Copy the content to clip board
3)Paste it in mspaint
4)save it in .jpg format in other folder in D drive say TEST2


May be difficult... ,hope to see some solution ... not 100% but some thg which would help my requirement....

THANKS in advance to all,

Regards,
MANISHA This is not possible to do in a batch, however vbscript could do it by the use of sendkeys (probably) but IM sure that there are better solutions to pull out the content of a pdf out there

6829.

Solve : batch file to run with the program only opening once?

Answer»

Hello All, my name is todd and this is my first post besides my introduction. great resource here. My issue is that I have a .bat file that RUNS with a .lsp and a .scr file that I run with autocad to purge multiple drawings. It works great but the problem is that it opens autocad runs the routine and closes and then opens again on the next drawing. Is there a way that I can write it to only open autocad once and perform the tasks? An additional question #2 does the .bat , .scr, .lsp files need to be in the same folder that I am performing the processes on? I have TRIED calling to it from another folder location and it doesnt seem to be able to find the file? If it would be helpful I will attach the files that I have so that you can look at them. I appreciate all of your assistance in advance.The files don't have to be in the same location to work correctly.

What version of AutoCad are you using?im using autocad 2008. I am pretty sure I directed them to the correct file path. I copied it from the search window and placed "" around folders with spaces in them. Does it have a hard time searching through sub-folders?anyone??No It shouldn't have a problem going thru the sub-folders but seems that you can open multiple drawings in one window, from here it seems that the multiple file opening is different from previous versions.

Post your batch script you have so far.Quote from: todouble22 on January 07, 2010, 09:41:55 AM

An additional question #2 does the .bat , .scr, .lsp files need to be in the same folder that I am performing the processes on? I have tried calling to it from another folder location and it doesnt seem to be able to find the file?

If possible show the complete path to all .exe and data files in the batch files and other files. If that does not work show all paths in the system search path: Path. If that does not work reinstall the main programs. ( some of the paths to .exe and data files might be corrupt. ) good luck.Quote from: macdad- on January 08, 2010, 09:11:12 AM
No It shouldn't have a problem going thru the sub-folders but seems that you can open multiple drawings in one window, from here it seems that the multiple file opening is different from previous versions.

Post your batch script you have so far.
are you familiar with autocad at all? you want me to post the batch, script, and lisp files that I am using?Yes I am familiar with it.

And yes please post atleast the batch scriptQuote from: macdad- on January 13, 2010, 06:07:09 PM
Yes I am familiar with it.

And yes please post atleast the batch script
this is the batch file:
MD C:\TEST\DWG\NEWBORDER
For %%f in (C:\TEST\DWG\*.dwg) do start /wait C:\"Program Files"\Autodesk\"Acade 2008"\acad.exe "%%f" /b C:\TEST\tsi-D_borderrev.scrYour batch file looks right.

But it seems that you can't open a new drawing in ACad from command line(batch script).

Please post the Acad Script, from the Acad Script it seems that you can open up another drawing without closing the current Acad window all together.Quote from: macdad- on January 16, 2010, 11:10:38 AM
Your batch file looks right.

But it seems that you can't open a new drawing in ACad from command line(batch script).

Please post the Acad Script, from the Acad Script it seems that you can open up another drawing without closing the current Acad window all together.
The script is pretty extensive since it updates all the attributes in a title block but here it is:
Script:
;THIS SCRIPT WILL ZOOM TO EXTENTS AND CYCLE THROUGH THE ATTRIBUTES ONE AT A TIME WITH THE ABILITY TO CHANGE THEM BY THEIR LOCATION REGARDLESS OF
;WHAT IS THERE FOR TEXT AND MAKE THE REPLACEMENT AS TO WHAT IS PUT INTO THIS SCRIPT
;IT WILL THEN LOAD THE LISP AND SAVE THE UPDATED DRAWING INTO THE NEWBORDER FOLDER AND LEAVE THE ORIGINAL UNCHANGED
;WHEN RUN BY THE BATCH FILE AND INCLUDING THE LISP IT WILL UPDATE THE ATTRIBUTES AND SAVE THE UPDATED DRAWING INTO THE NEWBORDER FOLDER AND LEAVE
;THE ORIGINAL AS IT WAS
;THIS SCRIPT CAN BE MODIFIED TO ADD IN THE X FOR PRELIMINARY OR APPROVED FOR CONSTRUCTION AS WELL
;CREATED BY TODD PERKINS 2009
zoom
e
;THE FOLLOWING IS THE SEQUENCE OF EDITING THE ATTRIBUTES ONE AT A TIME THE COMMENTS ARE THE PROMPTS THAT COINCIDE WITH THE COMMAND
-attedit
;Edit attributes one at a time
y
;Enter block name specification
TSI-D
;Enter attribute TAG specification
TITLE1
;Enter attribute value specification THIS USES THE WILDCARD * TO MAKE IT VARIABLE TO WHAT IS THERE FOR TEXT AS THE ATTRIBUTE TO BE CHANGED
*
;Expects a point or Window/Last/Crossing/BOX/Fence/WPolygon/CPolygon
w
;0,0 SPECIFIES FIRST CORNER
0,0
;GETVAR SPECIFIES THE OPPOSITE CORNER
(getvar "limmax")
;Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next]
v
;Enter type of value modification [Change/Replace]
r
;Enter new attribute value
FIRST LINE OF TITLE
;AN ENTER IS PLACED HERE AND THEN REPEATS THE PROCESS TO EDIT THE REST OF THE ATTRIBUTES ONE AT A TIME

-attedit
y
TSI-D
TITLE2
*
w
0,0
(getvar "limmax")
v
r
SECOND LINE OF TITLE

-attedit
y
TSI-D
TITLE3
*
w
0,0
(getvar "limmax")
v
r
THIRD LINE OF TITLE

-attedit
y
TSI-D
SCALE
*
w
0,0
(getvar "limmax")
v
r
1:1

-attedit
y
TSI-D
DRAWN
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
DRAWDATE
*
w
0,0
(getvar "limmax")
v
r
00/00/00

-attedit
y
TSI-D
DESIGNED
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
DESDATE
*
w
0,0
(getvar "limmax")
v
r
00/00/00

-attedit
y
TSI-D
ENG1
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
ENG1DATE
*
w
0,0
(getvar "limmax")
v
r
00/00/00

-attedit
y
TSI-D
ENG2
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
ENG2DATE
*
w
0,0
(getvar "limmax")
v
r
00/00/00

-attedit
y
TSI-D
MGR
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
MGRDATE
*
w
0,0
(getvar "limmax")
v
r
00/00/00

-attedit
y
TSI-D
DWGNO
*
w
0,0
(getvar "limmax")
v
r
10000

-attedit
y
TSI-D
REVNO
*
w
0,0
(getvar "limmax")
v
r
A

-attedit
y
TSI-D
TSIJOB
*
w
0,0
(getvar "limmax")
v
r
10000

-attedit
y
TSI-D
TSICADD
*
w
0,0
(getvar "limmax")
v
r
10000

-attedit
y
TSI-D
REVNO1
*
w
0,0
(getvar "limmax")
v
r
1

-attedit
y
TSI-D
REVDATE
*
w
0,0
(getvar "limmax")
v
r
00/00/00

-attedit
y
TSI-D
REVDESC
*
w
0,0
(getvar "limmax")
v
r
FOR REVIEW

-attedit
y
TSI-D
REVBY
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
REVAPP
*
w
0,0
(getvar "limmax")
v
r
TJP

-attedit
y
TSI-D
REVNO2
*
w
0,0
(getvar "limmax")
v
r
A

-attedit
y
TSI-D
ISSUETO
*
w
0,0
(getvar "limmax")
v
r
CLIENT

-attedit
y
TSI-D
ISSUEFOR
*
w
0,0
(getvar "limmax")
v
r
REVIEW

;THIS IS TO PURGE AND REGENERATE THE DRAWING
-purge
a
*
n
regen
(load "C:\\TEST\\TBUPDATE.LSP")
TBUPDATE
QUIT
Y
** I think I can change the quit here to close but it hasnt worked in the past. As you can see the script file calls the lisp which saves the drawing to a new folder with the same drawing name. but here is the lisp file also.
l;THIS LISP IS CREATED TO UPDATE THE DRAWING IN THE SELECTED FILES IN THE SCRIPT AND SAVE THEM INTO THE NEWBORDER FOLDER WITH THE SAME NAME AND
;LEAVE THE ORIGINAL UNCHANGED
;CREATED BY TODD PERKINS 2009
(defun C:TBUPDATE(/ dn pa panbdn) ;THIS LINE DEFINES THE COMMAND TBUPDATE
(setq dn (getvar "dwgname")) ;THIS LINE GETS THE NAME OF THE CURRENT DRAWING FILE AND SAVES IT TO A VARIABLE NAMED dn
(setq pa (getvar "dwgprefix")) ;THIS LINE GETS THE PATH OF THE CURRENT DRAWING FILE AND SAVES IT TO THE VARIABLE NAMED pa
(setq panbdn (strcat pa "NEWBORDER\\" dn)) ;THIS LINE CREATES A NEW PATH BY ADDING NEWBORDER\\ TO THE EXISTING PATHS WHERE DRAWINGS ARE SAVED
(command "SAVE" panbdn) ;THIS LINE SAVES THE DRAWING IN THE NEWBORDER FOLDER USING THE SAME DRAWING NAME
) ;THIS LINE CLOSES THE OPENING PARENTHESIS IN THE FILEisp:

Alright here we go.

Now when you tried the Close command what did it do?
6830.

Solve : Batch or script to rename directories - Please help?

Answer»

Hi,
I need a script that rename directories from DD.MM.YY format to YY.MM.DD

or aa.bb.cc to cc.bb.aa

Can ANYONE help?

Many thanks



C:\batch>type dirname.bat

Code: [Select]@echo off

SET DD=%1
set MM=%2
set YY=%3
echo %DD%.%MM%.%YY%
md %DD%.%MM%.%YY%

ren %DD%.%MM%.%YY% %YY%.%MM%.%DD%

dir %YY%*
Run:


C:\batch>dirname.bat 19 01 10

Output:

19.01.10
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\batch

01/19/2010 10:12 PM 10.01.19
0 File(s) 0 bytes
1 Dir(s) 303,472,803,840 bytes free

C:\batch>Onimalu:

Are the existing directories you want to rename held in one parent directory or are there other directories within the parent?Thanks for reply directories are like this

1.2.09
12.5.09
6.8.09
2.11.09

and for better sorting I need
09.08.06
09.11.02
etc..

Quote from: Onimalu

directories are like this

1.2.09
12.5.09
6.8.09
2.11.09

What is the PATH to the directories you want to rename?this is not important
I can map it as I want for example D:\1.2.09\

Try this - not fully tested.

Code: [Select]@echo off
setlocal enabledelayedexpansion
cls

:: Syntax: Enter batch script filename followed by the year
:: e.g. script 09
:: script 10

for /F "tokens=1-3 delims=." %%1 in ('dir /ad /b d:\*.%1') do (
set mm=%%1
set dd=%%2
set yy=%%3
set infil=d:\!mm!.!dd!.!yy!
if !mm! lss 10 set mm=0!mm!
if !dd! lss 10 set dd=0!dd!
echo.&AMP;echo !infil! will be renamed to !yy!.!mm!.!dd!
rem ren !infil! !yy!.!mm!.!dd!

)

Thank you it works very well.
6831.

Solve : AT command to run task at every 4hrs?

Answer»

Dear Experts,
How to run the AT command to run task at every 4hrs,

i have written this,
D:\>at \\WCP7F0BCU22 16:50 /every:m,t,w,th,f,s,su d:\windows\calc.exe
which is running at specific time as 16:50hrs, i want this task to be run every 4hrs.

please ADVISE,
Thanks in advance.http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/at.mspx?mfr=true


"date : Specifies the date when you want to run the command. You can specify one or more days of the week (that is, type M,T,W,Th,F,S,Su) or one or more days of the month (that is, type 1 through 31). SEPARATE multiple date entries with commas."
Quote

i want this task to be run every 4hrs.

There are actually two task schedulers on your Win2003 machine. One is the AT command which runs at the NT command line. The other is a Windows version with a GUI.

The AT version doesn't SEEMS to have a parameter for a 4 hour interval between job executions , but the GUI does: Accessories==>SYSTEM Tools==>Scheduled Tasks==>Schedule==>Advanced==>Repeat Task where you can set the interval between runs in both minutes and hours.

Good luck.
6832.

Solve : Email through DOS prompt.?

Answer»

Hi,

Is it possible to send email to my company email-id from a batch job or through DOS. I dont wanna use any third party software.

Thanks.
-BobQuote from: bobcatalog on July 30, 2008, 12:01:51 PM

Hi,

Is it possible to send email to my company email-id from a batch job or through DOS. I dont wanna use any third party software.

Thanks.
-Bob

Are you really running DOS? If you have a Windows machine you can use VBScript or JSCRIPT. There is a 3rd party product called blat which is similar to the unix sendmail command. There is no native DOS support for email.

Hi Sidewinder,

Thanks for the info. btw do you have the code in vbscript for sending mail?

Thanks,
-BobQuote
btw do you have the code in vbscript for sending mail

Are you kidding? The snippet closet is bottomless. (hmmm, that wording may be a BIT awkward)

This is a basic shell to send email with VBScript. Check with your ISP for the actual value of the smtpserver, port and whether you need to use authentication (most of this information is available online). There are other PARAMETERS for attachments, etc.

Code: [Select]Set CDO = CreateObject("CDO.Message")
CDO.From =
CDO.To =
CDO.Subject = "Test Email"
CDO.Textbody = "Whassup?"
CDO.Configuration.Fields.Item("HTTP://schemas.microsoft.com/cdo/configuration/sendusing") =
CDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
CDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
CDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =
CDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
CDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =
CDO.Configuration.Fields.Update
CDO.Send

Save the file with a vbs extension and run from the command line as cscript scriptname.vbs



PS. There is a special PLACE in *censored* for spammers.
6833.

Solve : Batch file to execute a command in the most recent folder at a specific place?

Answer»

Hi All

I'm hoping someone can help me with the following, I'm currently running WINXP but will need to be compatible with WIN2000.

I'm trying to create a batch file that will execute a copy command of the most RECENT folder at a specific location.

i.e.
I have a folder structure where my production builds go (e:\workspace\2.6; 2.7; 2., within these folders a new build is populate to then simple called 2.6_test_1; 2; 3 ; 4 ETC... and there are only two 'builds' keep in each folder at any one time. I want to create a batch file that will determine which build is most recent (either by build number or date) and then executed a copy command from within that folder.

I really really hope this makes sense to someone other then me and if anyone can help it would be very much appreciated

regards
AJ
Quote

I really really hope this makes sense to someone other then me

Not so much. I figure your folder structure looks something like this:

Quote
workspace
|
|__2.6
| |__2.6_test_1
| |__2.6_test_2
| |__2.6_test_3
| |__2.6_test_4
|
|__2.7
| |__2.7_test_1
| |__2.7_test_2
| |__2.7_test_3
| |__2.7_test_4
|
|__2.8
| |__2.8_test_1
| |__2.8_test_2
| |__2.8_test_3
| |__2.8_test_4

Now please explain the source and target of this copy you want to do.

Quote
I want to create a batch file that will determine which build is most recent (either by build number or date)

This is where I get lost. If it's TRUE that build number 2.8_test_4 is more recent than 2.6_test_4, you could sort the folders descending by date, take the first folder in the list and sort the build files descending by date. The file at the top of the list would be the most recent build.

Hi Sidewinder

The folder structure does indeed look like that with possibly 4 or 5 builds added to each folder daily.

What i would like to be able to do is at any point in the day run a batch file that will go and pick up the 'newest' build from each folder and copy these to ANOTHER location, The copy part of the batch file isn't a problem but i need a way for the batch file to determine what the 'newest' build is in each folder regardless of what number that build might be.

I understand that this is quite TRICKY due to the way microsoft set there dates but I'm hoping there is a way i can get it to pick up the 'hightest' build number from each folder.

does that help any?

thanks again
aj

Quote
I understand that this is quite tricky due to the way microsoft set there dates

Actually not. The display dates are locally formated by the user. The dates are stored internally in Universal Time Coordinate (UTC) format.

Quote
What i would like to be able to do is at any point in the day run a batch file that will go and pick up the 'newest' build from each folder and copy these to another location

This may help:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%v in ('dir e:\workspace /b /a:d') do (
set first=Y
for /f "tokens=* delims=" %%x in ('dir e:\workspace\%%v /a:-d /b /o:-d') do (
if !first!==Y copy e:\workspace\%%v\%%x .....
set first=N
)
)

Based on your naming convention, be sure not to overwrite any files. The copy statement is incomplete, used for demo purposes.

6834.

Solve : would like to run program source inline?

Answer» HELLO,

i WOULD like to create a .bat file that would copy my source into a temporary file and then run that file.

for example:

right now if have C# program in a file called form.cs and if i run these commands in a .bat file it works fine:

csc form.cs
form
but what i would like to do is run the program the way i currently do it on UNIX, ie something like this:

cat > form.cs <<EOF
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;

namespace BindingSourceMultipleForms
{
public class MainForm : Form
{
public MainForm()
{
this.Load += new EventHandler(MainForm_Load);
}

private BindingSource bindingSource1;
private Button button1;

private void MainForm_Load(object sender, EventArgs e)
{
InitializeData();
}
EOF
form
-------------------------------------------

So i'm looking for the DOS command that will encapsulate the source and copy the inline source into a temporary file in essence, ie similar to the UNIX-EOF utility

Thanks very much for any pointers or ideas!
BobKYou could try this technique

1. delete form.cs if it exists
2. now can use the >> append redirection operator for each source line (simplifies things.)
3. if cannot do above, use > create file redirection operator for first line and >> thereafter

BUT - any source line with a & CHARACTER in will cause the command interpreter to bork!! (non-negotiable)

e.g. batch code

Code: [Select]if exist form.cs del form.cs

echo using System;>> form.cs
echo using System.drawing;>>form.cs

[...]

echo {>> form.cs
echo InitializeData();>>form.cs
echo } >> form.cs

csc form.cs
form.cs
Code: [Select]BUT - any source line with a & character in will cause the command interpreter to bork!! (non-negotiable)
so you say that we cant do echo & ?What do you think? (HINT: open a command window and try it.)
Quote
so you say that we cant do echo &

That's correct, but you can use the notation echo ^&. Any character that has meaning in a different context within the shell needs to be escaped with the caret (^). You can even escape the caret itself (^^). Should there be a lot of these characters, your code will look like chicken scratch by the time you're finished!

I asked this question in another post but never got a response. Why the batch wrapper? Why not just create form.cs in notepad and use as needed?

Adding needless complexities only leads to ERRORS. Sidewinder, you beat me to it regarding escaping the & with a caret. The ampersand (&) has been called the 'poison character' of NT scripting. I believe there are a few situations where escaping is not possible.Yeah, it get really weird with the percent symbol. Using the caret with the % yields nothing, but if you double up with %%, then the results are a single %.

Perhaps a KISS certificate should be required of everyone before getting close to a PC.



Quote from: Dias de verano on July 22, 2008, 09:54:18 AM
What do you think? (Hint: open a command window and try it.)

No, i know that i can echo it using ^ char but i was thinking you dont know that Sorry bout that
6835.

Solve : how decrement my var %day%?

Answer»

hello

i would like to know how can i decrement my VAR %day%
actually i have the day of today in this var and i would like the day before

set day =%DATE:~13,2% ----->today
set filename =%date:~5,4%%date:~10,2%%day%

what should i do to decrement %day% from one day

thanks in advanceTry this:

set /a day =%date:~13,2%-1

Are you SURE 13,2 is correct? Potential problem EXISTS on the first day of the month. Batch language does not do date arithmetic.

Hope this helps. o thanks but as u said there is still a problem with the first day of the month because there is no 0 of may or june

how do u SOLVE this type of problem usually???Personally I would use VB Script. It has great date handling functions and is a better solution on Windows machines. You can get more info on VB Script from:

http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

Good luck.

6836.

Solve : incremental backup?

Answer»

I want to write a batch file that will create incremental backups of any file i want and which will not delete the originaal file.Does anyone know the process for this please?You can USE either BACKUP or XCOPY.

This site is a GOOD primer on CREATING a batch backup file from scratch: http://www.allenware.com/icsw/icsw130.htm

Good LUCK. thanks i'll GO and check it out!!

6837.

Solve : COPY does not support wildcards or directory copies?

Answer»

Hi I have this issue which is making me pull my hair out! Can someone please save me from going bald!!!

In the beginning I switched my PC on and on start up I receive an error message box saying “Your system is beginning to dump” or something like that.

When I switched my PC off and switched it on again I was stuck in the DOS screen with a message saying:

NTLDR is missing
Press Ctrl+Alt+Del to restart

Not knowing what to do I turned to a forum like this one and was told to type the following command:

COPY ?:i386\ntldr c:\
COPY ?:i386\ntdetect.com c:\

Everything copied fine then when I restarted again I got another message in DOS saying: “NTLDR is compressed”. To overcome this I typed:

CD \
Attrib –c ntldr
Exit

This worked fine and my computer was restored!... For about 2 weeks! Then the NTLDR message happened again but this time it was not letting me get away with the above methods of recovery. Instead at the recovery consol when these commands are typed, I get a new message saying:

COPY does not support wildcards or directory copies

The question is, what do I do now? If anybody can TELL me as to why this is happening to my PC or even has the patients to answer my cry for help, I would be very grateful indeed!

To all you computer geniuses out there this maybe a piece of cake to solve but to me, im ready to throw my bloody computer in the river! So if possible can you please explain a solution in simple laymen’s terms as im a bit of an idiot when it comes to computers.

MANY MANY THANX! (“,)Welcome to the CH forums.

What a pity you didn't tell us what kind of pc we're dealing with, laptop, desktop and are you running XP or Win.2k.

Anyway, a possible reason why ntldr is going awol is because the Master File Table is so fragmented that files have been moved to a secondary MFT which is not searched at boot time. When was the last time you defragged your files? Another possible reason is that your hard drive is failing, hope your backup is up-to-date.

As to cure....

IF you have a floppy drive, on a healthy pc copy ntldr and ntdetect.com to a floppy disk then boot from that floppy disk in the broken system. This will use the boot files from the floppy and load Windows from your hard disk. You can then copy ntldr from the floppy to C:.

Or-

If you do not have a floppy drive goto this site and download the ISO file for "Boot CD - Windows XP Emergency Boot CD (XP SP2 Pro & XP SP2 Home". Burn the ISO file to cd then boot from the CD in the broken system. Note: If you are running Win.2k download the appropriate file for that OS.

Either of the above gives you a come-in-handy emergency boot disk which you can add to your software recovery tool kit.

Or-

Boot to Recovery Console again and ENTER the same copy command as you did before but this time do not use a wildcard (your last entry included a ?). This time enter copy X:\I386\ntldr C: - and - copy X:\I386\ntdetect.com C: where X: is the drive letter of your CDROM. Obviously your Windows cd must be in the cdrom.

Good luck.Thats perfect! I can now log back into my PC now.

Sorry it was a Asus Desktop PC

Although everything is back up and running i have encountered a new problem now. After COPYING your instructions, for some reason all my USB slots are no longer USB 2.0. Meaning that all my hardware will not work as i get a pop up message saying something like: your hardware can perform faster if you plug in to a USB 2.0 port.

Also my SD card slot is not reading any cards in insert

Any ideas?

Thanks (",)

PS: Oh and i cannot defragment my drives even though i have over 15% free space! i click the dive and then the defragment button and nothing happens Sounds like you have one very sick system or your hdd is waving goodbye.

Try running SFC /SCANNOW (have your system cd to hand) and reloading mobo drivers.

Quote

Oh and i cannot defragment my drives even though i have over 15% free space!

That's not very muchQuote from: Dias de verano on July 16, 2008, 06:15:34 AM
Quote
Oh and i cannot defragment my drives even though i have over 15% free space!

That's not very much

Thats a sure sign you need to do something about the space. You should get another drive or delete and clean off old files you don't want or need anymore.

Quoted:

"Try running SFC /SCANNOW (have your system cd to hand) and reloading mobo drivers"

How do i do this please?
Start>Run type sfc /scannow in the dialog box and hit ok. See here..

As for the motherboard drivers, I'm assuming you have your mobo driver cd available.Ok firstly i located my motherboard CD rom and installed the relevant drivers. The only one that didn't work was the USB 2.0 driver! Here's what happened:

i clicked on the install USB 2.0 option and a message box CAME up saying:

This program will install "SiS USB Enhanced Host Controller driver"
Do you want to continue?
Yes or No

I selected yes and then i get another box saying:

Sis USB 2.0 Host Controller uses the inbox driver in Service Pack 1.
Please upgrade to Windows XP Service Pack 1 and rescan for hardware changes in Device Manager

I thought had service Pack 2 before all this "bad luck" happened?

Secondly, i also tried the RUN solution you advised: sfc /scannow but a command box came up for a fraction of a millisecond then disappeared and nothing happened

I know you must be thinking why doesn't this guy just wipe his computer and start from fresh but the truth is, i cant. Not that i dont know how to but a case of most programs installed on my PC i can never get back again.

Thanks for your patients Quote
I thought had service Pack 2 before all this "bad luck" happened?

Well, we don't know what happened, so check what you have got by holding down the Win key and hitting Break to display your System Properties window, it will be shown in the General tab.

Quote
Secondly, i also tried the RUN solution you advised: sfc /scannow but a command box came up for a fraction of a millisecond then disappeared and nothing happened

That should happen, then a notification box should display as shown on the attached file.

If that doesn't appear then SFC cannot be run and it LOOKS like you will have to do a Repair install. But first you must try to backup your essential data/program files to cd/dvd/floppy/external drive, whatever you can access.

[recovering disk space -- attachment deleted by admin]Ok, i downloaded service pack 2 intalled it and everything went smootly. installed anitvirus and wiped all possible bugs and viruses. i managed to run disk fragmenter. no problem. reseted my computer and now i cannot go inside my C: drive or partitioned D: !!! I get a error box saying "C:/ Access Denied"Please do not double post.
6838.

Solve : Perform action on find?

Answer»

Ok, I need a bat file to do the following thing; he must find a certain string in a file (a *.CFG file) and perform an action (SET a var), how can I do that?

Thank youDepending on WHETHER you find what you're looking for you can TRY something like this:

find "arg" filename.ext
if %errorlevel%==0 set var=

Note: if you don't find arg then the errorlevel is 1

If you need a variable value from the file you're searching then you need to redirect the output of the FIND CMD and then use FOR loop logic.

The more complex the logic, the more useful VB Script becomes.

Hope this helps.

it worked, thank you

6839.

Solve : Copy with bach file help?

Answer»

Hello,

I'm tring to make a batch file to COPY all content within a folder to another. It works with files, but not with folders.

So my problem is: how can I make a batch file to copy all files *and* folders from folder X to folder Y. Could someone help me, please?

What I did:
--
@echo off
copy C:\Test\X\*.* D:\Test\Y
echo Done and Done!

--

Thanks!
Domingosi think it must look sth like this
* get folder, subfolder names and echo them to file
* use for command to make folders using OUTPUT file
* copy files

i might be wrong coz on new SP on Vista is robocopy commandLook into xcopy, that allows you to pass a switch to copy directories

From Command prompt, TYPE xcopy /?xcopy was exactly what I was searching for!!

Thanks!!!!!

Your WELCOME.

6840.

Solve : how to know free space on HD?

Answer»

Hi, I make a zip file of 1,5 Gb with a batch file but i need to know before if I have 1,5 Gb free space on HD.
How can I make by the batch command?
ThanksAnyone help me please... You didn't mention an OS, but you can give this a try:

@echo off
dir | find "bytes free" > dummy.txt
for /f "tokens=1-4" %%i in (dummy.txt) do (
if /i %%k GEQ "1,500,000,000" echo Enough Space
del dummy.txt
)

I arbitrarily used the echo statement. You can change it to launch your zip program.

Hope this helps. Thanks for a reply, I use XP pro ita, I substitute some parameters for italian OS but dont TELL me if i have Enough Space, I need to substitute "tokens=1-4"? Can you explane me the FOR cicle? Thanks

@echo off
dir | find "byte disponibili" > dummy.txt
for /f "tokens=1-4" %%i in (dummy.txt) do (
if /i %%k GEQ "1.500.000.000" echo Enough Space
del dummy.txt
)

The batch file every time tell me enough space
The FOR loop just reads the line of a DIRECTORY listing that was found; the one with how many bytes are free. We don't have to assign all four values delimited by spaces on that line, it's just easier when debugging.

@echo off
dir | find "byte disponibili" > dummy.txt
for /f "tokens=1-4" %%i in (dummy.txt) do (
if "%%k" GEQ "1.500.000.000" echo zip pgm goes here
del dummy.txt
)

I FORGOT the quotes around %%k. We have to do a string comparision because the bytes free is formated with dots.

Good luck. Thank you very much!!!
I found the compare signs: GTR, LSS, GEQ, EQU.
@echo off
dir | find "byte disponibili" > dummy.txt

for /f "tokens=1-4" %%i in (dummy.txt) do (
if /i "%%k" GTR "1.500.000.000" (
echo ok
echo "%%k"
del dummy.txt
) else (
echo KO
echo "%%k"
del dummy.txt )
)
I tried and work, but if I wont to compare with 15.000.000.000 why the results are ok and not ko? I need to change some parameters?The ELSE has to be on the same line as the command after the IF. I guess you can only do one command per IF statement. I made a small change to the earlier code snippet:

@echo off
dir | find "byte disponibili" > dummy.txt
for /f "tokens=1-4" %%i in (dummy.txt) do (
if "%%k" GEQ "1.500.000.000" echo zip pgm goes here
)
del dummy.txt

Maybe VB Script would be a better way to go with this.

Hope this helps. Thanks a lot for your help
I'm not able to make a VB script I can make in delphi but in dos is good because anyone can modify a script WITHOUT a source. The last pleasure....if you know a free programmer dos manual to download....
Thank you for help and sorry for my english ERROR I couldn't find any free downloads of a DOS manual (IBM and Microsoft are not known for their generosity). This site may help you out, but just searching for 'DOS Batch' will find all sorts of helpful hints. Of course if you have any problems, you can always post here. There are very knowledgable people in this forum.

http://www.robvanderwoude.com/

Good luck.

PS. My Italian is not so good either.

6841.

Solve : Search for files using command prompt?

Answer»

1. Is the batch file in the same folder as the smc file?

2. Change this line

for /f "TOKENS==" %%a in ('dir *.smc /a-d /b /s') do set var=%%a

3. Why are you doing COMP %%a? the variable %%a does not exist any more. (The loop is finished), and anyway, you have assigned its value to %var%.


oh, alright i solved it!

my code:
FOR /F "tokens=1*" %%G IN ('dir /b *.smc') DO Set smc=%%G
If [%smc%]==[] goto filenotfound
COMP %smc% valid.c1 /d

but now i have a question about the COMP, if there are MISMATCHES, how do i make is JUMP(goto) somewhere else?Quote from: kaiyoken on July 23, 2008, 02:33:26 PM

COMP %smc% valid.c1 /d

but now i have a question about the COMP, if there are mismatches, how do i make is jump(goto) somewhere else?

COMP %smc% valid.c1 /d || goto notsame

But why not use fc>nul (no messages or need to PRESS a key)

FC %smc% valid.c1 /d>nul || goto notsame

6842.

Solve : Need help with a batch job.?

Answer» HI,

Find out the date of job.txt.
If the date is yesterdays or TODAY’s date then it needs to tell the file is up to date.
if it is lesser than the yesterdays date it should send a mail to the user that it is not up to date.

for /F %a in ('dir /b job.txt') do echo %~ta gives the date of the file.

How to write the above conditions?

Thanks,
-BobHow do your file dates show up? Using your code I see file dates like this (non-US date format, non-US (24 hour) time format.

30/07/2008 20:37C:\>echo 07/11/2008 04:16 PM
07/11/2008 04:16 PM

I was just trying with that , you can ignore that.OK so you use US date format.

The idea is to get yesterday's date, and the filedate, into YYYYMMDD format, i.e. numbers where a later date is ALWAYS greater than an earlier one, then see if the filedate number is less than the yesterday's date number.


Code: [Select]@echo off
setlocal

REM Get yesterday's date into yyyymmdd format
call :get_date
REM Strip leading zeros from possible octals and decrement the day
set /a mm=1%mm%-100, dd=1%dd%-101
if %dd% NEQ 0 goto :add_zeros

REM Today is the 1st of the month - decREMent the month
REM and set leap year check (ignoring centuries)
set /a mm-=1,ly=yy%%4
REM If today is 1 Jan, set date to 31st Dec
if %mm% EQU 0 (set /a dd=31, mm=12, yy-=1) else (
REM Calculate days in last month (by Frank Westlake)
set /a "dd=5546>>mm&1,dd+=30"
REM Special case for February
if %mm% EQU 2 if %ly% EQU 0 (set dd=29) else (set dd=28)
)

:add_zeros
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%

set /a yestdate=%yy%%mm%%dd%

for /f %%a in ('dir /b job.txt') do set fd=%%~ta
REM get filedate into yyyymmdd format
REM This is for US date format i.e. mm/dd/yyyy
set mm=%fd:~0,2%
set dd=%fd:~3,2%
set yy=%fd:~6,4%
set /a filedate=%yy%%mm%%dd%

IF %filedate% LSS %yestdate% del jobs.txt
goto next

REM ------------------------------------------------------------------
:Get_Date
REM ------------------------------------------------------------------
REM Generic date parser
REM Sets %dd% (01-31), %mm% (01-12) & %yy% (4 digit)

if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
for /f "tokens=%toks% delims=.-/ " %%d in ('date/t') do (
set %%a=%%d
set %%b=%%e
set %%c=%%f
set toks=
)
)
if %yy% LSS 100 set yy=20%yy%
goto :eof

:next
Thanks for the script. Will check that and update you.

Looks like the script deletes the file, if its older than y'day ?
But INSTEAD i need to send an email to a person saying its an older file than y'day. can this be done ?

Appreciate your help.Substitute the command you would use to send the email for 'del jobs.txt'

Quote
IF %filedate% LSS %yestdate% del jobs.txt
6843.

Solve : The GNU MS-DOS????

Answer»

Quote

This is governed by statutory section 17 USC 302. According to this section, a work that is created (fixed in tangible FORM for the first time) on or after January 1, 1978 is ordinarily given a term enduring for the author's life, plus an additional 70 years after the author's death. In the case of "a joint work" prepared by two or more AUTHORS that was not a "work made for hire," the term lasts for 70 years after the last surviving author's death. For works made for hire, and for anonymous and pseudonymous works (unless the author's identity is revealed in Copyright Office RECORDS), the duration of copyright will be 95 years from publication or 120 years from creation, whichever is shorter.

Basically, the copyright still exists, and will exist long after most of us have died.

Since laws do change from time to time, different copyrights will expire at different times. Here's a good chart which explains:

http://www.copyright.cornell.edu/public_domain/thanks quaxoHelper hasn't been back.maybe another hit n run poster.Quaxo cited US law, and I want to point out that US law does not, and thankfully will not, apply outside the United States. HOWEVER, most countries have copyright laws of some sort.
Canada's for example, is nice and verbose.

http://www.cb-cda.gc.ca/info/act-e.html#rid-33810Quote from: macdad- on July 29, 2008, 06:16:32 AM
maybe another hit n run poster.

Sorry I've been gone for 3 days, but as i said in my first post, but the computer at home doesn't have internet connection, and so I'm USING a public computer at the local library.sorry for the false accusation
6844.

Solve : Copy files without copying directories??

Answer»

Here's what I want to do:

I want to copy audio FILES to a microsd card for use on my cellphone, however my cellphone does not SUPPORT subdirectories under the main x:\my_music FOLDER. It NEEDS all the mp3 files directly in the x:\my_music folder with no subdirectories for artist or album.

So I went into my media player and selected the songs that I wanted (about 100) and copied them to a c:\cellphone directory. When it copied, it copied the subfolders for artist and album so it looks like C:\cellphone\artist\album\song.mp3.

I need to get all of the mp3 files out of those subdirectories and into a single folder, and I don't want to do it drag and drop in windows because that would take forever.

How would I go about this?Say this is is where the music is: C:\cellphone\artist\album\
And you want it here: C:\cellphone\

I would go to C:\cellphone\ and press CTRL + F.
This will bring up the Search window. Search for all audio files in that directory and then copy and paste to C:\cellphone\d'oh .. didn't think of that. I don't think i've ever actually used the search feature in explorer.

thanks! Good Luck for /f %a in ('dir /s /b *.mp3') do copy %a x:\my_music /v /y

The /v is to verify and the /y is to by-pass overwrite prompt in the event of duplicate files. It can be ran from the command LINE if you create a batch file you would need to change %a to %%a

6845.

Solve : blinking screen?

Answer»

I USE Maxthink a DOS outliner for my writing. It WORKS just fine, EXCEPT on my new Lenovo, when I set the colors in the outliner to the combination I want, the screen blinks when I CHANGE to a FULL screen. I tried resetting the colors in the DOS prompt to see if that would improve things, but it did not. Any help would be appreciated.

Thanks.

6846.

Solve : cant set values inside a for loop??

Answer»

I make a script like this:

setlocal
setlocal enabledelayedexpansion
set /A j=0
for /L %%i in (501,1,600) do (
set /A j=%%i-500
echo %j%
)

but I always get echo 0.........
Why?
try this instead

setlocal
setlocal enabledelayedexpansion
set /A j=0
for /l %%i in (501,1,600) do (
CALL set /a j=%%i-500
call echo %%j%%
)
Thanks a LOT. That WORKS.

Basically, I just want to rename my files and try to make it general and easy.
very simple task, convert files names:

file501.xml
file502.xml
file503.xml
....
file599.xml

TO:
newfile1.xml //from file501.xml
newfile2.xml //from file502.xml
newfile3.xml .....
....
newfile99.xml //from file599.xml


Tried several SCRIPTS, none of them works....

Thanks a lot if you can help. I am pretty new for MS-DOS.

or you could use !j! since you have delayed expansion enabled. yes. Thanks.

just new here, need to read some basic stuffs first to move on....


Thanks.check help for set and for commands good reading

set /? > c:\setcmd.txt
for /? > c:\forcmd.txt

and read them

6847.

Solve : dos bat file?

Answer»

someone is shuting down my win xp pc with the remote shutdown program.
can i write a BAT file to imedialy stop the shutdown?
if so what would it look like?A .bat file cannot be triggered by an event so the SHORT answer is no(it would have to be a memory resident program to capture an event), however,

to do what you are saying, they need administrative rights to your COMPUTER so the first thing I SUGGEST you do is change all of the passwords on your computer and disable the guest account.

Second install and activate a firewall.
Third install and activate anti-virus software.
Fourth install and activate anti-malware(spyware and hijack) software.

6848.

Solve : Batch file to search for file and execute commands depending on outcome??

Answer»

Right, let me explain.

What I want to do, is create a BATCH file (MS-DOS) that basically searches in the directory the file is installed, INCLUDING all subfolders for a particular file, say EXAMPLE.TXT for the purposes of this. If it exists, I don't want anything to happen, and it should just skip the rest of the command to the end. If the file doesn't exist, I'd ideally want it to search for another file in the same directory, if this exists, it would need to copy another file from Location A to Location B, if this file as well doesn't exist, it would ideally want to pop up an error message reading, 'File XXX' doesn't exist.

I'm sorry for my ignorance, but I believe this is possible using the IF command, but am really quite new to MS-DOS and I really prefer learning from examples if anyone could be kind enough to show me a possible way.

Many Thanks

RichardThe logic will look like this

The && operator works like this

operation1 && operation2

Perform operation1 and (only) if it is successful, perform operation2


CODE: [Select]REM searches in the directory the file is installed,
REM including all subfolders for a particular file, say EXAMPLE.TXT
REM If it exists, I don't want anything to happen,
REM and it should just skip the rest of the command to the end.
dir /s /b "example.txt" && GOTO end

REM If the file doesn't exist, I'd ideally want it to search for another file in the same directory,
REM if this exists, it would need to copy another file from Location A to Location B,
IF exist "another.file" (
copy "LocationA:\yet another file" "LocationB"
goto end
)

REM if this file as well doesn't exist, it would ideally want to pop up
REM an error message reading, 'File XXX' doesn't exist.
echo MESSAGE: another.file does not exist

:end


this may work

for /f %%a in ('dir /s/b example.txt') do (
call :getdir %%a
set targetdir=%tempdir:~-11%
call :cpyfile %targetdir%
)
goto :eof

:cpyfile
for /f %%b in ('dir /s /b %* | find /v /i "secondfile") do copy %%b location2
goto :eof

:getdir
set tempdir=%*
goto :eoferobby, your code is a good answer to a different question, not the one ASKED!

6849.

Solve : 486 bad com port?

Answer»

This ought to tax the memory for you old guys!!

I have a 486/66 hz motherboard with 2 com ports that I'm running DOS 6.22 on. Yeah, I know it's a dinosaur, but I NEED it to for some DOS-based software.

Anyway, one of the com ports (com 1) has GONE bad, but I only need one!

I seem to remember a command that you can put in either the autoexec.bat or config.sys that will SWITCH com ports. It's something like:

Com 1 = Com 2
or
Com 2 = Com 1

but I can't remember the exact syntax or where to put it!

Help!! Remember the Com 1 is BAD and the COM 2 is GOOD!

Thanks! You could try the mode command.

Quote

This ought to tax the memory for you old guys!!

I'd stay up, but it's after supper and I really need some sleep.
6850.

Solve : can't really explain it in the title... plz help?

Answer»

how can do do something like this, EX.
i want a cmd to prompt a USER to lets say PING some ip, But i wanna it to just ask for the Ip, and then it self PUT ping IP.

explaining it better:
(DOS)
PLEASE write the IP u want to ping:
1.1.1.1

and then starts pinging it, so the user doesn't have to put: PING 1.1.1.1, just 1.1.1.1

thanks.Check the
Set /P command

Set /?set /p ipaddr=Please write the IP u want to ping:
ping %ipaddr%

That should workthank u guyz, u guys are geniuses