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.

3301.

Solve : Batch file to create backup for a week?

Answer»

I have a backup file which gets generated everyday with the same file name "contentstore.zip" and gets stored in a specific location C:\contentstore_backups. So each day, the previous copy of the file is overwritten.

I want to write a BAT file which renames the file contentstore.zip file to contentstore_currentdate.For instance, if today's date is 04/14/2009, then i want it to renamed as contentstore_20090414.
This way, we can prevent the new file from overwriting the old one.

However , after 7 days, I want the OLDEST file to get deleted , so that at a point I have only 7 backups in the folder "contentstore_backups".

Please help.Quote from: em on April 14, 2009, 08:49:36 AM

I want to write a BAT file which renames the file contentstore.zip file to contentstore_currentdate.For instance, if today's date is 04/14/2009, then i want it to renamed as contentstore_20090414.
use %date% or %time%. search the forum for examples on how to get date VALUES into variables.


Quote
However , after 7 days, I want the oldest file to get deleted , so that at a point I have only 7 backups in the folder "contentstore_backups".

Please help.
you can set scheduled tasks every 7 days to execute your batch file. use dir (and some of its OPTIONS) to list files according to time stamp. check the dir /? help for more info.
you want something like:

Code: [Select]for /f "delims=/ tokens=1-3" %%A in ('date /t') do (
ren C:\contentstore_backups\contentstore.zip contentstore_%%A%%B%%C.zip)

The deleting after a week is a little more tricky. You might want to look at VB for that, and to be fair if you're going to look at VB for that you may as well do the whole thing in VB...

FBThanks for the inputs. It really helped me with the first part of my problem--renaming of the file with the date in it

The second part was:
Now for instance, for the next seven days every day we get a new backup file:
contentstore_20090414 ----taken on 04/14/2009
contentstore_20090415 ----taken on 04/15/2009
contentstore_20090416 ----taken on 04/16/2009
contentstore_20090417 ----taken on 04/17/2009
contentstore_20090418 ----taken on 04/18/2009
contentstore_20090419 ----taken on 04/19/2009
contentstore_20090420 ----taken on 04/20/2009

On the 8Th day, when we get a new file "contentstore_20090421" on 04/21/2009, I want the oldest backup "contentstore_20090414" taken on 04/14/2009 to get deleted.
This ensures that I have only 7 backups at any given time.

Since the files are named in this format, can we not sort the filenames and delete the file with the SMALLEST name?

Quote from: em on April 14, 2009, 11:10:19 AM
Thanks for the inputs. It really helped me with the first part of my problem--renaming of the file with the date in it

The second part was:
Now for instance, for the next seven days every day we get a new backup file:
contentstore_20090414 ----taken on 04/14/2009
contentstore_20090415 ----taken on 04/15/2009
contentstore_20090416 ----taken on 04/16/2009
contentstore_20090417 ----taken on 04/17/2009
contentstore_20090418 ----taken on 04/18/2009
contentstore_20090419 ----taken on 04/19/2009
contentstore_20090420 ----taken on 04/20/2009

On the 8Th day, when we get a new file "contentstore_20090421" on 04/21/2009, I want the oldest backup "contentstore_20090414" taken on 04/14/2009 to get deleted.
This ensures that I have only 7 backups at any given time.

Since the files are named in this format, can we not sort the filenames and delete the file with the smallest name?


Hmmm... It looks possible with FOR...@OP, set a scheduled task to execute every 7 days. in your batch, you just specify dir ( with a for loop) to get the oldest file. check the dir/? for more info, or search the forum. (been posted many times).
Quote from: gh0std0g74 on April 14, 2009, 07:40:42 PM
@OP, set a scheduled task to execute every 7 days. in your batch, you just specify dir ( with a for loop) to get the oldest file. check the dir/? for more info, or search the forum. (been posted many times).

Ok, set a sheduled task for this:
Code: [Select]@echo off
dir /b /o:d C:\contentstore_backups > directory
set /p delzip=<directory
del C:\contentstore_backups\%delzip%
del directoryThat should do it.Code: [Select]@echo off
pushd C:\contentstore_backups || goto:eof
dir/b contentstore.zip || goto:eof

>$$$.vbs echo wsh.quit year(date)*10000+month(date)*100+day(date)
cscript//nologo $$$.vbs

ren contentstore.zip contentstore_%errorlevel%.zip
for /f "skip=7" %%a in ('dir/b/on contentstore_*.zip') do del %%a

del $$$.vbs
popd
untestedQuote from: Reno on April 15, 2009, 01:44:05 AM
Code: [Select]@echo off
pushd C:\contentstore_backups || goto:eof
dir/b contentstore.zip || goto:eof

>$$$.vbs echo wsh.quit year(date)*10000+month(date)*100+day(date)
cscript//nologo $$$.vbs

ren contentstore.zip contentstore_%errorlevel%.zip
for /f "skip=7" %%a in ('dir/b/on contentstore_*.zip') do del %%a

del $$$.vbs
popd
untested
Mine works for getting rid of the oldest one...as long as there isn't anything in the folder other than the .zips.

The
Code: [Select]@echo off
dir /b /o:d C:\contentstore_backups > directory
set /p delzip=<directory
del C:\contentstore_backups\%delzip%
del directory
Echo Oldest file deleted.
for /f "tokens=1-3 delims=/ " %%a in ("%date%") do (
set y=%%c
set m=%%b
set d=%%a
echo %%a
echo %%b
echo %%c
)
ren C:\contentstore_backup\contentstore.zip contentstore_%y%%m%%d%.zip
echo Zip File has be renamed! You may now close.
pauseA combo of my previous code (for deleting the oldest file) and my new one (which does the renaming).Batch Features:Quote from: Helpmeh on April 16, 2009, 05:58:14 AM
Mine works for getting rid of the oldest one...as long as there isn't anything in the folder other than the .zips.
A combo of my previous code (for deleting the oldest file) and my new one (which does the renaming).
Answer:
Quote from: em on April 14, 2009, 08:49:36 AM
However , after 7 days, I want the oldest file to get deleted , so that at a point I have only 7 backups in the folder "contentstore_backups".

bug fix:
for /f "skip=7" %%a in ('dir/b/o-n contentstore_*.zip') do del %%a

looks like the OP didn't come BACK hereQuote from: Reno on April 17, 2009, 12:29:07 AM
Batch Features:Answer:
bug fix:
for /f "skip=7" %%a in ('dir/b/o-n contentstore_*.zip') do del %%a

looks like the OP didn't come back here
Wait...my code works fine, it deletes the oldest one, and then renames the undated zip to what the OP requested.helpmeh, it's logic error.

imagine the batch first running, and initially there is only one file contentstore.zip
dir /b /o:d C:\contentstore_backups > directory
set /p delzip=<directory
del C:\contentstore_backups\%delzip%

bang, there it goes, today content_store.zip which should be renamed goes into dos black hole.

ok, how about if the directory already contain 2,3, or even 4 contentstore_yyyymmdd.zip
everytime the batch is run, the numbers of backup will never increase. thus the requierment of 7 backups at any time is not fulfil.

the only condition where your batch will works is the folder only contain 8 *.zip file(s) -including the contentstore.zip to be renamed, not LESS, not MORE. and only contentstore*.zip, or else the batch code is buggy.

and date retrieving problem, .......Quote from: Reno on April 18, 2009, 10:13:37 PM
helpmeh, it's logic error.

imagine the batch first running, and initially there is only one file contentstore.zip
dir /b /o:d C:\contentstore_backups > directory
set /p delzip=<directory
del C:\contentstore_backups\%delzip%

bang, there it goes, today content_store.zip which should be renamed goes into dos black hole.

ok, how about if the directory already contain 2,3, or even 4 contentstore_yyyymmdd.zip
everytime the batch is run, the numbers of backup will never increase. thus the requierment of 7 backups at any time is not fulfil.

the only condition where your batch will works is the folder only contain 8 *.zip file(s) -including the contentstore.zip to be renamed, not LESS, not MORE. and only contentstore*.zip, or else the batch code is buggy.

and date retrieving problem, .......
Oh...now I see. It could be fixed with a FOR loop (now that I know the basic functions of FOR, I love it)...I think.

for /f "delims=" %%a in ("directory") do (
set /a loop+=1
)
That should count how many lines are in directory, and...

if %loop%==8 del C:\contentstore_backups\%delzip%

So the full (hopefully) working code is:
Code: [Select]@echo off
dir /b /o:d C:\contentstore_backups > directory
set /p delzip=<directory
for /f "delims=" %%a in ("directory") do (
set /a loop+=1
)
if %loop%==8 del C:\contentstore_backups\%delzip%
del directory
Echo Oldest file deleted.
for /f "tokens=1-3 delims=/ " %%a in ("%date%") do (
set y=%%c
set m=%%b
set d=%%a
)
ren C:\contentstore_backup\contentstore.zip contentstore_%y%%m%%d%.zip
echo Zip File has be renamed! You may now close.
pauseThat should work...as long as FOR counts the lines...
3302.

Solve : Is it possible to write simple text files with batch??

Answer»

I know i can use the echo command to write something but that will enable me to write something with only one line, unless i use && or ^& but THATS only for if i'm WRITING ANOTHER batch file.

example code
Code: [Select]echo hello > hello.txt
My question is basically if i can write a file with multiple lines of text making it a simple text file?> overwrite file/create if not exist
>> append to filehttp://www.afunnystuff.com/forumpics/moresense.jpgCode: [Select]echo hello > hello.txt
echo hi >> hello.txt
echo does this work? >> hello.txtNotice the > in the first line and >> in all following lines.
The single > overwrites the previous contents of the file with what is before it.
Example:
echo The only line > file.ext

The double >> does NOT overwrite the previous contents of the file, but puts the text before it at the end of the file.
Example:
echo The last line > file.ext

Do you understand now?(
echo hello
echo world
)>a.txtQuote from: Prince_ on APRIL 19, 2009, 03:27:05 AM

(
echo hello
echo world
)>a.txt
that's the 4 line equivilent of what can be done in 2 (or 1).

echo hello > a.txt
echo world >> a.txt

or
echo hello > a.txt & echo world >> a.txtlike Helpmeh, you can move ">" to begin of your command.
> a.txt echo hello
>>a.txt echo world
>>a.txt echo does this work?

Quote from: tonlo on April 19, 2009, 08:49:06 AM
like Helpmeh, you can move ">" to begin of your command.
> a.txt echo hello
>>a.txt echo world
>>a.txt echo does this work?


I have never tried it that way...
3303.

Solve : calling same batch file within second batch file multiple times?

Answer»

I want to write a batch file that calls a second batch file mutiple times. Each time the second batch file is called I need to pass different parameters.
For example:
export --configfile conf/FOOExport.xml --DATE 20090401 --period monthly --output ..\TEST\FOO\monthly
export --configfile conf/BARExport.xml --date 20090401 --period monthly --output ..\TEST\BAR\monthly
export --configfile conf/BOOExport.xml --date 20090401 --period monthly --output ..\TEST\BOO\monthly

When I run this only the first line in the file GETS executed then the batch file stops.
I tried using the CALL option and changed the file to this
Call: export --configfile conf/FOOExport.xml --date 20090401 --period monthly --output ..\TEST\FOO\monthly
Call: export --configfile conf/BARExport.xml --date 20090401 --period monthly --output ..\TEST\BAR\monthly
Call: export --configfile conf/BOOExport.xml --date 20090401 --period monthly --output ..\TEST\BOO\monthly

But when I do this I get the FOLLOWING error on all of the lines:
The system cannot find the batch label specified -

For each call to export in the file.

I know this has got to have a simple solution but I am a NEWBIE to doing this.

Thanks,
Bobyou should not have a colon after the word "Call".
You got it, thanks!
I KNEW it was simple.

3304.

Solve : Renaming a File to INCLUDE BOTH Date & Time Stamp?

Answer»
Quote
Several times a day, you want to backup a file C:\folder1\catalog.MDB to C:\folder2\catalog &LT;timestamp>.mdb.

The FOLLOWING script in biterscripting ( http://www.biterscripting.com/install.html - it is free) will do the job.

Code: [Select]system copy "C:\folder1\catalog.mdb" ("\"C:\folder2\catalog "+gettime()+".mdb\"")
Come to THINK of it, there is only one line in this script.

J
3305.

Solve : several DOS questions?

Answer»

Why do I get the feeling this is going to be a long one?
one can use the longhand chdir to change directories as well. try using chdir in place of cd. if that works, then their is something stopping the shorthand version from working. If not Dias is probably right regarding a corrupted cmd.exe.I don't think cd is an alias of something else, as it works fine on directories of I: and C: disks until this I:\program_files case. chdir works same as cd
Code: [Select]I:\>chdir program_files
Invalid directory

Alithough mentioned already, I think still worth saying cd can work for a directory like I:\t_e but not for a directory like I:\eeeeeee_fffff.

I am not sure it is related that my I: disk is attached to a linux server via Network File System. So it is impossible to do chkdsk to my knowledge. Quote from: lehe on APRIL 18, 2009, 12:06:33 PM

I don't think cd is an alias of something else, as it works fine until this I:\program_files case. chdir works same as cd
Code: [Select]I:\>chdir program_files
Invalid directory

Alithough mentioned already, I think still worth saying cd can work for a directory like I:\t_e but not for a directory like I:\eeeeeee_fffff.

I am not sure it is related that my disk is attached to a linux server via Network File System. So it is impossible to do chkdsk to my knowledge.

weird, because on my computer I can cd to any directory regardless of the name. I think the fact that it is attached to a Linux server via NFS is extremely relevant. But I'm not to experienced with Linux Filesystems.Quote from: lehe on April 18, 2009, 12:06:33 PM
I am not sure it is related that my disk is attached to a linux server via Network File System.

Now he tells us

yeah I am not sure if NFS is the issue. The same thing also happen on my LOCAL disk C. I.e., if I create C:\program_files, cd cannot change to it. Also cd can work for a directory like C:\t_e but not for a directory like C:\eeeeeee_fffff.
Quote from: lehe on April 18, 2009, 12:28:49 PM
I am not sure if NFS is the issue. The same thing also happen on my local disk C. I.e., if I create C:\program_files, cd cannot change to it. Also cd can work for a directory like C:\t_e but not for a directory like C:\eeeeeee_fffff.


Are you using command or cmd?
I am using command.
Yeah, changing to cmd solve the problem!
So cmd is not DOS but command is?Quote from: lehe on April 18, 2009, 12:50:48 PM
I am using command.
Yeah, changing to cmd solve the problem!
So cmd is not DOS but command is?

At last.

Squall noticed this first. CMD.EXE is a 32 bit program. It's what you get when you select Command Prompt on the Windows Accessories MENU. COMMAND.COM, on the other hand, exists only for compatibility and 16bit programs. It exists solely for those programs which have not been UPDATED since the days of MS-DOS. It's designed to run 16bit applications, and operates just like the old MS-DOS did.In short- use cmd.couldnt he go to start - accesories - cmd and work it just the same?
3306.

Solve : substring question?

Answer»

Within a Windows XP batch file I NEED to find a substring within a variable string and then do something if it is equal or not equal. Find and FindStr seem to only work with files so I was wondering just how to do this with a variable in an if statement.

in the form :

if %%G contains "command" (

echo a message

)

I have not been able to figure out how to do this in a batch file. 1. echo %%g|find "command" >nul 2>&1 && echo a message
or
echo %%g|find "command" >nul 2>&1
if not errorlevel 1 echo a message

2. i assume you are inside a for loop, and has setlocal enabledelayedexpansion
set a=%%g
set a=!a:command=!
if "!a!" neq "%%g" echo a messageHi, RENO
please explain what is %%g mean? ThanksQuote from: Geek-9pm on April 18, 2009, 11:34:22 PM

Hi, reno
please explain what is %%g mean? Thanks

It is a small relative of your %%G

Quote from: Geek-9pm on April 18, 2009, 11:34:22 PM
Hi, reno
please explain what is %%g mean? Thanks
Quote from: Z.K. on April 18, 2009, 07:00:19 PM
if %%G contains "command" (
echo a message
)
there is indention in the above code, i assume he is inside a for loop, %%g refers to token variable. besides for loop, i can't think anywhere else in coding a %%g can be used.
Code: [Select]for /f "tokens=1*" %%f in (sometextfile.txt) do (
echo %%g|find "command" >nul 2>&1 && echo a message
)
example text file:
this is a command

sample output:
c:>\test.bat
a message

for complete explanation, type for/?Thanks, It said:

To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable NAMES are case sensitive, so %i is different
from %I.


It also said the variable is onl a single LETTER.

3307.

Solve : Non-Looping For Loop?

Answer»

I am trying to make get a user to log in, so they can continue using the batch SCRIPT, but the login is failing in the second FOR loop...

Here is my code. List.txt is a FILE with about 30 lines, each different. The first word is a possible username, the second a possible password. No USERNAMES are the same.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set fname=list.txt
:looplog
set num1=0
set num2=0
echo Enter your username.
set /p usr=Username^:
Echo Enter your password.
set /p pass=Password^:
pause
for /f "delims=" %%z in ('type %fname%') do (
set /a num1+=1
)
echo Lines^: %num1%
pause
for /f "tokens=1-2 delims= " %%a in ('type %fname%') do (
if "%%a"=="%usr" if "%%b"=="%pass%" goto cont
set /a num2+=1
if %num2%==%num1% cls & echo Username and/or password don't match. & goto looplog
)
:cont
echo HI!
pause
For some reason, the second FOR loop is not LOOPING...so it just keeps on going as if it didn't exist...I have no idea.
But, somebody once said,"If you can't fix it, Break it!"

So break up your code into pieces. See if thee is a way to get the second FOR thing in a BAT fioe by it self and see if it works by itself.

Asy you ALREADY know, batch files suffer from delayed execution. The first thins have not been done yet and it tries to do the next thing and the variables do not have the values. Breaking it into separate files might make it work. Or reveal what is wrong.Quote from: Geek-9pm on April 19, 2009, 05:50:49 PM

I have no idea.
But, somebody once said,"If you can't fix it, Break it!"

So break up your code into pieces. See if thee is a way to get the second FOR thing in a BAT fioe by it self and see if it works by itself.

Asy you already know, batch files suffer from delayed execution. The first thins have not been done yet and it tries to do the next thing and the variables do not have the values. Breaking it into separate files might make it work. Or reveal what is wrong.

The second FOR loop requires the first FOR loop (which does work) to calculate the amount of lines...so I can't really break it up. But I know what the problem is.
It just does the first line, and then does nothing else.
for /f "tokens=1-2 delims= " %%a in ('type %fname%') do (
if "%%a"=="%usr" if "%%b"=="%pass%" goto cont
set /a num2+=1
if %num2%==%num1% cls & echo Username and/or password don't match. & goto looplog
)
:cont
echo HI!
pauseCode: [Select]@echo off
setlocal enabledelayedexpansion
set fname=list.txt

:looplog
set num1=0
set num2=0
echo Enter your username.
set /p usr=Username:
Echo Enter your password.
set /p pass=Password:
pause
for /f "delims=" %%z in ('type %fname%') do (
set /a num1+=1
)
echo Lines: %num1%
pause
for /f "tokens=1-2 delims= " %%a in ('type %fname%') do (
if "%%a"=="%usr%" (
if "%%b"=="%pass%" (
goto :cont
)
)
set /a num2+=1
if !num2!==!num1! (
cls
echo Username and/or password don't match.
goto :looplog
)
)

:cont
echo HI^^!
pauseQuote from: Batcher on April 19, 2009, 09:19:33 PM
Code: [Select]@echo off
setlocal enabledelayedexpansion
set fname=list.txt

:looplog
set num1=0
set num2=0
echo Enter your username.
set /p usr=Username:
Echo Enter your password.
set /p pass=Password:
pause
for /f "delims=" %%z in ('type %fname%') do (
set /a num1+=1
)
echo Lines: %num1%
pause
for /f "tokens=1-2 delims= " %%a in ('type %fname%') do (
if "%%a"=="%usr%" (
if "%%b"=="%pass%" (
goto :cont
)
)
set /a num2+=1
if !num2!==!num1! (
cls
echo Username and/or password don't match.
goto :looplog
)
)

:cont
echo HI^^!
pause
Thanks!
3308.

Solve : query software?

Answer»

I have SCRIPT that will let you know all of software installed in your local machine by searching the key in your register.

Code: [Select]@Echo Off
Setlocal
For /f "tokens=1,2,*" %%i in ('Reg Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /S ^| Find /I "DisplayName"') Do Call [color=red]:softname[/color] "%%k"
Endlocal
Goto :EOF

[color=red]:softname[/color]
Set keyname=%1
If %keyname%=="" goto :EOF
Echo %keyname:"=%
Goto :EOF
And you ALSO can query software a network machine by using \\"pc-name or IP"\HKLM\.....
I tested to query a Win2k3 machine in my network. It is a virtual machine (VM) and network environment is workgroup. And you must have permission to run this script


Issue: when i tried to query a vista machine in domain using domain admin permission, the script met ERROR. But it was OK when i tried to query in that vista local machine
Sorry i can't attachment the error now (i am not at home now), i will attachment the error message later.
Thanks.


Update picture.
it seem not is domain or workgroup issue. I think the problem make my script run incorrect is different OS (vista). Here is the picture i try query soft from VM (win2k3 SP2) to host (Vista SP1 lastest update), 2 Machine in Workgroup


And host to VM

I disable all the FW, and use highest permission
NEED help... Not every OS allow remote operation registry. If you need run the command like reg query \\xxx.xxx.xxx.xxx\..., please make sure the service Remote Registry is started on the remote OS.Quote from: Batcher on APRIL 20, 2009, 06:45:48 AM

Not every OS allow remote operation registry. If you need run the command like reg query \\xxx.xxx.xxx.xxx\..., please make sure the service Remote Registry is started on the remote OS.

Many thank you, Batcher, how can i forgot the services
3309.

Solve : Shutdown Command to use in DOS?

Answer»

I don't see how that enters into the mix at all.

If I'm trying to shut down my PC in DOS, why would I want to TRY to ping something?

Anyway, my SOFTWARE GURU came thru for me and I have just downloaded the "Shutdown.com" program in a zip file, along with full documentation.

I'll only post the link when I've had time to fully test the program.

Thanks all!

Shadow Quote from: TheShadow on April 29, 2009, 08:06:14 PM

I don't see how that enters into the mix at all.

If I'm trying to shut down my PC in DOS, why would I want to try to ping something?

Anyway, my Software Guru came thru for me and I have just downloaded the "Shutdown.com" program in a zip file, along with full documentation.

I'll only post the link when I've had time to fully test the program.

Thanks all!

Shadow
The ping makes the batch WAIT for one second before continuing...just incase your program takes a bit of time to close.Well, I just finished testing the DOS Shutdown program and it works a treat.

I'll post the link when I have more time to upload the zip file to my FTP Server.
Probably tomorrow.

Shadow Quote from: TheShadow on April 29, 2009, 08:39:31 PM
Well, I just finished testing the DOS Shutdown program and it works a treat.

I'll post the link when I have more time to upload the zip file to my FTP Server.
Probably tomorrow.

Shadow
You can just upload the zip here...Well, I just cleaned up the Instruction text file and re-compressed the files into a self extracting zip file, using 7Zip.

The file "Shutdown DOS.exe" can be downloaded here:

http://www.box.net/shared/fcc6cam8x8

I thank everyone who has tried to help me with this little problem.

Cheers Mates!

Shadow

Thanx again Shadow !Did Shadow ever consider a hybrid method?
Perhaps Hardware modification and a small bit of software to force a machine to shut down could do the JOB. The DOS Shutdown.com program works a treat. Nothing else is required.

Try it.........you'll like it.

3310.

Solve : How to check condition in txt file?

Answer»

Quote from: Salmon Trout on November 17, 2009, 03:19:26 PM

But 1st December SATISFIES LEQ 30th November; and I see trouble ahead if the day NUMBER has a leading ZERO. I guess we'll find out in a fortnight.


Yogesh123 is comparing only the first 25 days of any month.

Yogesh123 does not compare Dec 1 with Nov 30.

It is POSSIBLE 01 could be considered an octal number? Is octal 1 > 25?Quote from: billrich on November 17, 2009, 04:09:10 PM
Yogesh123 is comparing only the first 25 days of any month.

Yogesh123 does not compare Dec 1 with Nov 30.

It is possible 01 could be considered an octal number? Is octal 1 > 25?
so what if he doesn't do that now? When you write code, write it in such a way that it won't break when things happen. Its called code resiliency , by yours truly. Quote from: gh0std0g74 on November 17, 2009, 04:58:33 PM
so what if he doesn't do that now? When you write code, write it in such a way that it won't break easily when things happen. Its called code resiliency , by yours truly.
3311.

Solve : Opening files from list of files?

Answer»

Gudday all
I wish to 1st create a list of known file names.
From that list, saved as file, open each file one by one to look at tokens 1 and 2 on the first line only for various patterns
I can create my file list ok
Code: [Select]dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt
but I am having trouble opening each file in that list and doing the parsing.
I tried
Code: [Select]for /f "tokens=1,2 delims=" %%a in (SPLfiles.txt) do (
set full_line=\%%a\%%b
set file_name=%%b
echo Full line: !full_line!
echo File name: !file_name!
echo.
but that fails as it looks at the file names not the file contents.

Can anyone help me please?if you can use gawk for windows (see my sig), this would easy enough
Code: [Select]C:\test>gawk "FNR==1{print $1,$2}" *.spl
or, you can use vbscript
Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "spl" Then
Set objFile = objFS.OpenTextFile(strFile)
strFirstLine = objFile.ReadLine
s = Split(strFirstLine," ")
objFile.Close
WScript.Echo "first token: "& s(0)
WScript.Echo "first token: "& s(1)
END If
Next
output
Code: [Select]C:\test>more file.spl
token1 token2 blah
word1 word2 word3

C:\test>cscript /nologo test.vbs
first token: token1
first token: token2
I have something similar to this written on my laptop, which I did not bring with me to work today. However when I get home I will post it for you to see if it helps.

My batch reads in a file (it's only 1 token but could easily changed to however many you need) and then runs some command.Just another way of doing this.

Code: [Select]# Script tokens12.txt
var str filelist, file, contents, line1, word1, word2
lf -r -n "*.spl" "D:/Archives/E20_120_AU/ArchiveCreator/Errors" > $filelist
while ($filelist <> "")
do
lex "1" $filelist > $file ; cat $file > $contents ; lex "1" $contents > $line1
wex -p "1" $line1 > $word1 ; wex -p "2" $line1 > $word2
echo $file "\t" $word1 "\t" $word2
done
Script is in biterscripting. Save the script in file C:/Scripts/tokens12.txt, start biterscripting, run the script by entering the following command

Code: [Select]script tokens12.txt

The documentation of the lex (line extractor) and wex (word/token extractor) commands is at http://www.biterscripting.com/helppages_editors.html .

Did a little more experimentation.
I can now get my script to grab the 1st 2 tokens off every line in every .spl file.
What I really want to do is just get the 1st 2 tokens off the 1st line of every file.

Code: [Select]@echo off

setlocal enabledelayedexpansion

dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt

for /f %%a in (SPLfiles.txt) do (
echo The file is %%a
set file=%%a
for /f "tokens=1,2 delims= " %%i in (%%a) do (
echo variable i = %%i
echo variable j = %%j
rem goto :finishgettingline
)
rem :finishgettingline
echo left loop after 1st line of the file %file%
)

I thought that if I put a goto to leave the inner loop (getting the tokens) after the 1st line was parsed then it would PARSE the 1st line of every file. Instead it just parses the 1st line of the 1st file then stops. The output is

Quote

The file is 20090619153310.SPL
variable i = SEW_AU
variable j = DEL_NOTE
left loop after 1st line of the file 20090619153310.SPL

No other files are parsed. I have 'remed' out the seemingly offending lines in the code above.

Also is it possible to pass a variable, in this case %%a, from the inner loop to the outer loop? I wanted the progarm to tell me when it finished each file. The line ' left loop after 1st line of the file' is printed but not the current file name.

You can use set /p to get the first line of a file.

SET /P variable=
It works because by default SET with the /p switch waits for a CR terminated string from STDIN (the keyboard) however you can use the < redirection symbol to make it take its input from a file. The crlf at the end of the first line of a text file ensures that the command terminates.

so this should work...

Code: [Select]@echo off

setlocal enabledelayedexpansion

dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt

for /f %%a in (SPLfiles.txt) do (
set file=%%a
echo the file is !file!
set /p firstline=<"%%a"
for /f "tokens=1,2 delims= " %%i in ("!firstline!") do (
echo variable i = %%i
echo variable j = %%j
)
)

notes...

(1) labels, GOTO etc

In many ways, NT command script language is a kludge, and it doesn't always work the way you would expect if you are used to "proper" programming or scripting languages and tools. One thing that is peculiar is the way it processes loops and other parenthetical structures. A loop is processed as if it was one logical line. Thus this

for [whatever] do (
some stuff
)

is equivalent logically to

for [whatever] do (some stuff)

(In fact if you only have one command in the loop you can use that format.)

Now you cannot have a label in the middle of a line, it has to be on a line by itself, so labels in loops break the code. Since your outer and inner loop is processed as one HUGE line, that is why it halted. Jumping out of loops is very tricky.

While I am on the topic, you may come across example scripts where the writer has used a double (or SINGLE) colon instead of REM to start a comment line

:: This is a comment

This is a carryover from MS-DOS where the practice did no harm (I think). It works because labels are disregarded (mostly!) and the line is a (broken) label. However such a line inside parentheses BREAKS THE CODE. It is an undocumented and unsupported "feature". The behaviour it CAUSES can give much puzzlement to coders, however it is often vociferously defended by people who ought to know better. My advice is, don't do it!


(2) Considering the FOR command,

for /f %%V in (dataset) do

With the /f switch, dataset (unquoted) is processed as a filename, whereas "dataset" is a string, which is why I used ("!firstline!") above.

(3)
In the other thread you asked about reference material for NT command scripting.

One good site I have found is

http://ss64.com/nt/

You may have the compiled help file ntcmds.chm on your system; it is not included on Vista & 7 I believe.

type

hh ntcmds.chm

at the prompt to find out.

If you don't have it, you can get if off an XP disk or installation, or download it from Microsoft (it is included in the Server 2003 Adminpak)

http://support.microsoft.com/kb/304718





Dear ST
Thank you once again.
After some fiddling the code works at last!
At least the boss is happy.
3312.

Solve : Read Characters from filename and move the file to a subfolder?

Answer» HI,
I need to read a filename and based on some characters, DECIDE to move the file in appropriate folders. Here is an example:

gibberish_Water_Cloud.abc
gibb_Water_Sky.abc
moregibb_Air_Sky.abc
stillmorgib_Air_Cloud.abc

I need to move these into following four folders that ALREADY EXIST:
Water_Cloud
Water_Sky
Air_Sky
Air_Cloud

Any help will be appreciated.
Thanks

This should help, make sure you put it in the same folder as the abc files.

Code: [Select]@echo off
for /f %%a in (*Water_Cloud.abc) do move %%a Water_Cloud\%%a
for /f %%a in (*Water_Sky.abc) do move %%a Water_Sky\%%a
for /f %%a in (*Air_Sky.abc) do move %%a Air_Sky\%%a
for /f %%a in (*Air_Cloud.abc) do move %%a Air_Cloud\%%a

Hope this helps
,Nick(macdad-)no need to use the for loop.
Code: [Select]move *Water_Sky Water_Sky
Oh well...EITHER worksyes, either works. but ..............
3313.

Solve : Need Help with Batch. Copy from source to dest, rename if exist.?

Answer»

Hi,

I'm trying to do recursive copy of a SRC folder to a DEST folder.
SRC and DEST both have the SAME folder structures (that is they have the same subdirectories, no matter how deep)

if file exist in DEST, rename it, then copy the SRC file to DEST
if file does not exist in DEST, then simply copy the SRC file to DEST

eg. SRC\subfolder1\subfolder2\file1.txt to DEST\subfolder1\subfolder2\file1.txt

the file1.txt (from DEST\subfolder1\subfolder2\) will be rename to file1.txt.bak, THEN file1.txt (from SRC\subfolder1\subfolder2\) will be copy to location DEST\subfolder1\subfolder2\

eg. SRC\subfolder3\subfolder4\file2.txt to DEST\subfolder3\subfolder4\

the file2.txt (from SRC\subfolder3\subfolder4\) will be copy to location DEST\subfolder3\subfolder4\


currently i have the this code, but it has problem, as that i can't get the name of the current folder, see below to better understand:

- - - - - - -

@echo off & setLocal EnableDelayedExpansion

set SRC="C:\main folder\"
set DEST="E:\main folder\"

pushd !SRC!

:: loop all directories
for /f "tokens=* delims=" %%p in ('dir/b/s/ad') do (

pushd %%p

set SUBDIR=%%p &LT;--------PROBLEM (don't need the full path, only need folder name?)

:: a list of files
for /f "tokens=* delims=" %%a in ('dir/b/a-d') do (
if exist !dest!\!SUBDIR!\%%a ren !dest!\!SUBDIR!\%%a %%a.bak
copy %%a !dest!\!SUBDIR!\

echo File name: %%a

)
popd
)

- - - - - - -

can someone help me fix my code, or if you can create some code from scratch that can do what i need, that'll be great too!

Thanks
mikeset SUBDIR=.%%~pp.Hi

When i add your code, Im getting:

The syntax of the COMMAND is incorrect.

Thanksoops, sorry, miss out this line:
for /f "tokens=* delims=" %%p in ('dir/b/s/ad') do ( -- list directory

set subdir=.%%~pnxp


dont forget to put quotes around pathname:
if exist "!dest!\!SUBDIR!\%%a" ren "!dest!\!SUBDIR!\%%a" "%%a.bak"
copy "%%a" "!dest!\!SUBDIR!\"
Hi,

see the bold below for the output.. i actually want SUBDIR to be folder "4", so i can attach folder "4" to DEST,
so that when this line comes:
!dest!\!SUBDIR!\
it will be something like:
C:\Documents and Settings\lum\Desktop\bat dest\c8\4\



@echo off & setLocal EnableDelayedExpansion

set SRC="C:\Documents and Settings\lum\Desktop\bat source\c8"
set DEST="C:\Documents and Settings\lum\Desktop\bat dest\c8"

pushd !SRC!

:: loop all directories
for /f "tokens=* delims=" %%p in ('dir/b/s/ad') do (

pushd %%p

echo %%p <-----------C:\Documents and Settings\lum\Desktop\bat source\c8\4

set SUBDIR=.%%~pnxp

echo !SUBDIR! <------.\Documents and Settings\lum\Desktop\bat source\c8\4


:: a list of files
for /f "tokens=* delims=" %%a in ('dir/b/a-d') do (
if exist "!dest!\!SUBDIR!\%%a" ren "!dest!\!SUBDIR!\%%a" "%%a.bak"
copy "%%a" "!dest!\!SUBDIR!\"

echo File name: %%a

)
popd
)Quote from: vip2cool on April 17, 2009, 08:41:04 AM

the file1.txt (from DEST\subfolder1\subfolder2\) will be rename to file1.txt.bak, THEN file1.txt (from SRC\subfolder1\subfolder2\) will be copy to location DEST\subfolder1\subfolder2\

eg. SRC\subfolder3\subfolder4\file2.txt to DEST\subfolder3\subfolder4\
this is your original question

ANYWAY, this only works on single folder (not working on getting 2,3 or 4 level directories)
set SUBDIR=%%~nxp -- x SWITCH in case you have extension on foldername

and type for/? and look at the bottom for more information on available switches.


untested, already late, i can't get my brain working right
set subdir=%%p
set subdir=!subdir:%src%\=!
echo !subdir!
Yea, i'm actually need multiple levels of folder support.. something like below:

SRC\subfolder1\...\subfolderN
...
SRC\subfolderN\...\subfolderN

DEST\subfolder1\...\subfolderN
...
DEST\subfolderN\...\subfolderN


Thanksok, battery in full charge, brain in full working condition

Code: [Select]@echo off & setlocal enabledelayedexpansion

set SRC=C:\main folder\
set DEST=E:\main folder\
if not exist %dest% md %dest%

for /r "%src%" %%a in (*) do (
set d=%%~dpa
set d=%dest%!d:%src%=!

echo %%a --^> !d!
if exist "!d!%%~nxa" move "!d!%%~nxa" "%%~nxa.bak" && echo ren - %%~nxa.bak

if not exist "!d!" md "!d!" && echo md - !d!
copy "%%a" "!d!" >nul && echo copy - %%~nxa

REM xcopy can auto create subdir, replacing the above 2 lines, but slower in execution ??
REM xcopy/i "%%a" "!d!" >nul && echo xcopy- %%~nxa
) Many thanks!

the code was almost working!

currently, all .bak goes to where the batch file is located,
is it possible to leave the .bak files in the same directory it was from?

e.g. if textfile.txt already exisit in DEST, after running the batch, DEST will be:
DEST=E:\main folder\folder1\folder2\textfile.txt <---new file copied from source
DEST=E:\main folder\folder1\folder2\textfile.txt.bak <---old file originally from dest

Thanks again!!bug fix:
replace this line:
if exist "!d!%%~nxa" move "!d!%%~nxa" "%%~nxa.bak" && echo ren - %%~nxa.bak
to
if exist "!d!%%~nxa" move "!d!%%~nxa" "!d!%%~nxa.bak" && echo ren - %%~nxa.bak
it's perfect! thanks for all the help!
3314.

Solve : Writing to a CSV file using a batch process.?

Answer»

I want to create and write data to a CSV file from within a batch PROCESS for one of my ongoing projects. Can ANYBODY help me in this? I am very new to writing batch FILES and it WOULD be really great if anyone can provide me with the code.first you head down to here to learn how to do batch files. then come here if you encounter problems.

3315.

Solve : batch check codition & echo?

Answer»

Dear Experts,

How to do this,

if token no 6 in abc.txt is LEQ current time, do echo %%a %%b %%c %%d %%e %%f %%g >> output.txt

abc.txt is =
abc.tre 0 W131738 Nov 16 12:00:57 2009
sfsdf.sdfsdf 0 W131455 Nov 16 10:02:11 2009
fsdf.rty 0 W7F0BCU182 Nov 16 11:02:12 2009
qw.qwe 2 w4059 Nov 16 09:05:38 2009
wsx.rfv 2 W0132017 Nov 16 05:06:13 2009
xdr.cft 0 W0132017 Nov 16 07:06:33 2009
tgb.ikm 2 W0131738 Nov 16 12:15:01 2009


if current time is 11:00:00
Output.txt should have,
sfsdf.sdfsdf 0 W131455 Nov 16 10:02:11 2009
qw.qwe 2 w4059 Nov 16 09:05:38 2009
wsx.rfv 2 W0132017 Nov 16 05:06:13 2009
xdr.cft 0 W0132017 Nov 16 07:06:33 2009


This is what i have tried,
but the output.txt is just showing %i %j %k %l %m %n %o
cd\
set Ct=%time%
set Ctt=%Ct:~0,2%
for /f "tokens=6" %%i in (abc.txt) do set LD=%%i
set LDD=%LD:~0,2%
if %LDD% LEQ %Ctt% (echo %%i %%j %%k %%l %%m %%n %%o>> output.txt
) else (
echo No result
)
pause

please advise,i often see your posts. you should show what you have tried by now.Dear gh0std0g74,
as advised,
I have updated my post use a better language to do date comparison. eg in vbscript
Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile = objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
CurrentDateTime =Now
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
s = Split(strLine," ")
t=""
For i = 3 To UBound(s)
t = t &" "&s(i)
Next
t=Trim(t)
datetime = Split(t," ")
mth= datetime(0)
dy = datetime(1)
thetime = Split(datetime(2),":")
hr = thetime(0)
min = thetime(1)
sec = thetime(2)
theyr = datetime(3)
strDateTimeInFile = CDate( dy & " " & mth & " " & theyr) &" "&CDate( hr & ":" & min & ":" & sec )
If DateDiff( "d", CurrentDatetime ,strDateTimeInFile ) > -1 Then
WScript.Echo "CurrentTime is earlier than strDateTimeInFile"
WScript.Echo strLine
End If
Loop
on command line
Code: [Select]c:\test> cscript /nologo test.vbs file
Can it be done using batch dos commands?
beacause i am not more concern about date comparison, comparison parameter could be no's also.nice

just one thing


Quote

strDateTimeInFile = CDate( dy & " " & mth & " " & theyr) &" "&CDate( hr & ":" & min & ":" & sec )

Why use CDate and String concat? You could use DateSerial and TimeSerial; also, this will allow for the return type to be a Date, rather then a string. (although I imagine type coercion is making everything work as it is; you can never really be sure in different locales)

Code: [Select]
DateTimeInFile= DateSerial(theyr,mth,dy)+TimeSerial(hr,min,sec)

OLE automation Dates are stored as "double" types; "1" is one day after the origin (I can't recall, I think it was in the 1700's or something); times are represented as fractional portions. Therefore, we can add a TimeSerial to a DateSerial to create an entire TimeStamp.

Quote from: Yogesh123 on November 17, 2009, 02:06:24 AM
Can it be done using batch dos commands?
beacause i am not more concern about date comparison, comparison parameter could be no's also.

You'll probably have to hope Salmon Trout or one of the other Batch Experts decides to tackle this one if you want a batch solution. Quote from: BC_Programmer on November 17, 2009, 02:09:50 AM
nice

just one thing


Why use CDate and String concat? You could use DateSerial and TimeSerial; also, this will allow for the return type to be a Date, rather then a string. (although I imagine type coercion is making everything work as it is; you can never really be sure in different locales)

Code: [Select]
DateTimeInFile= DateSerial(theyr,mth,dy)+TimeSerial(hr,min,sec)

heh, i had always wanted to try using these 2 functions, but never really got to it. CDate is what i am familiar with so i just wrote the script without MUCH thinking. But good call though. Quote from: Yogesh123 on November 17, 2009, 02:06:24 AM
beacause i am not more concern about date comparison, comparison parameter could be no's also.
why do you say its not about date comparison? didn't you say you need the 6th token to be LEQ current time or something.?? If it is, then IT IS date comparison. Unless your date format in the file is formatted to become like this
YYYYMMDDHHMMSS, then it may be possible for comparison. (but still you need to format the current time and date also ), which is too much of a hassle to do in batch. Its time to move on.Quote from: gh0std0g74 on November 17, 2009, 02:22:57 AM
heh, i had always wanted to try using these 2 functions, but never really got to it. CDate is what i am familiar with so i just wrote the script without much thinking. But good call though.

Basically, when dealing with Dates, I've always found it works best to have everything as a date, rather then a string, always best to avoid Locale issues. Although as you said you whipped it up without thinking and it is definitely possible to over-analyze any approach @echo off
setlocal enable delayed expansio
for /f "tokens=1-7" %%a in (file.txt) do (
set tme1=!time::=!
set tme2=%%f
set tme2=!tme2::=!
if !tme2! LEQ !tme1! echo %%a %%b %%c %%d %%e %%f %%g >> output.txt
)
Untested, might not work, but it will at least point you in the right direction. Yogesh - try this. It is dependent on your %time% format being hh:mm:ss.ms, no allowance is made for AM or PM if that is included in the format. If you use the %1 variable for testing purposes it must be entered in the full format as above. The script is untested.

Code: [Select]@echo off>output.txt
setlocal enabledelayedexpansion

:: set time=%1

set time=%time::=%
set time=%time:~0,6%

for /f "delims=*" %%1 in (abc.txt) do (
set line=%%1

for /f "tokens=1-6" %%2 in ("!line!") do (
set filetime=%%7
set filetime=!filetime::=!

if !filetime! leq !time! echo %%1>>output.txt
)
)

type output.txt
No doubt one of the scripting gurus will COME up with something much more efficient.

Good luck.We must use:
setlocal enabledelayedexpansion
Use !LD! not %LD% Salmon Trout provided this INFO a day or so ago

rem I remarked set Ct=%time% out for a better test.
Remove set Ctt=08 and the rem's in the code


C:\batch>cat yo3.bat

Code: [Select]rem set Ct=%time%
rem echo Ct = %Ct%
rem set Ctt=%Ct:~0,2%

set Ctt=08
echo Ctt = %Ctt%

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-7" %%i in (abc5.txt) do (
set LD=%%n
echo LD=!LD!
set LDD=!LD:~0,2!
echo LDD=!LDD!
echo LDD less or equal Ctt
if !LDD! LEQ !Ctt! (
echo %%i %%j %%k %%l %%m %%n %%o
) else (

echo.
echo No result found

echo.

)
OUTPUT:

C:\batch> yo3.bat
Ctt = 08
LD=12:00:57
LDD=12
LDD less or equal Ctt

No result found

LD=10:02:11
LDD=10
LDD less or equal Ctt

No result found

LD=11:02:12
LDD=11
LDD less or equal Ctt

No result found

LD=09:05:38
LDD=09
LDD less or equal Ctt

No result found

LD=05:06:13
LDD=05
LDD less or equal Ctt
wsx.rfv 2 W0132017 Nov 26 05:06:13 2009
LD=07:06:33
LDD=07
LDD less or equal Ctt
xdr.cft 0 W0132017 Nov 16 07:06:33 2009
LD=12:15:01
LDD=12
LDD less or equal Ctt

No result found

C:\batch>
3316.

Solve : findstr get different offset of the same string?

Answer»

Below is my batch script.

CODE: [Select]@echo off
rem character offset in command line
(echo TestStr&echo.)|findstr /o ".*"

rem character offset in file
echo TestStr>a.txt
echo.>>a.txt
findstr /o ".*" a.txt
I used the same string TestStr. Why return different offset? One is 10 while the other one is 9. See below.

Quote

C:\Test>test.bat
0:TestStr
10:
0:TestStr
9:

Anybody can help me out?

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

[Update 2009-04-20 07:30:20 AM] I FIND a new clue. Save below code as a batch file.

Code: [Select](echo TestStr&echo.)|findstr /o ".*"
pause
Run it, get below result.

Quote
C:\Test>(echo TestStr & echo.) | findstr /o ".*"
0:TestStr
10:

C:\Test>pause
Press any key to continue . . .

One strange thing should be pointed out. The Command Line Interpreter adds 2 blanks before &. But generally, the command separator is only 1 blank.

To see the duplicate blank in another way, let's run below command.

Code: [Select](echo TestStr&echo.)|findstr /o ".*">a.txt
We'll find there is a blank at the end of TestStr in the file a.txt.

Why the Interpreter adds 2 blanks before &? Need help for further investigation.
what is the actual problem you are trying to solve?Quote from: gh0std0g74 on April 19, 2009, 08:52:26 PM
what is the actual problem you are trying to solve?
Thanks for your quick reply.

I find this question when calculating the length of a string. Actually, I know how to get the length of a string. Here we go.

Code: [Select]@echo off
rem character offset in command line
for /f "tokens=1 delims=:" %%a in ('^(echo TestStr^&echo.^)^|findstr /o ".*"') do (
set /a StrLen1=%%a-3
)
echo %StrLen1%

rem character offset in file
echo TestStr>a.txt
echo.>>a.txt
for /f "tokens=1 delims=:" %%a in ('findstr /o ".*" a.txt') do (
set /a StrLen2=%%a-2
)
echo %StrLen2%
I just interested in why the offsets are different, as mentioned in the topic.there is this invisible character for each new line, costing 2 bytes. - 0x0d 0x0a

Code: [Select]C:\>(echo teststr&echo.)>a.txt

C:\>dir a.txt|find "a.txt"
20/04/2009 11:59 11 a.txt

11 bytes - (2bytes*2lines) = 7 character
Code: [Select]C:\>findstr/on ".*" a.txt
1:0:teststr
2:9:

offset 9 - (2bytes*(2-1)lines) = 7 character (disregard the CrLf of last line)

a.txt contents:
Code: [Select]C:\>(echo.d100 10a & echo.q)|debug a.txt
-d100 10a
0B20:0100 74 65 73 74 73 74 72 0D-0A 0D 0A teststr....
-q
echo + findstr
Code: [Select]C:\>(echo.teststr&echo.&echo hello)|findstr/on ".*"
1:0:teststr
2:10:
3:13:hellofor the above code, i've no idea why each new line cost 3 bytes Quote
there is this invisible character for each new line, costing 2 bytes. - 0x0d 0x0a
Good Grief! we have traveled in time back to 1979 when a programmer discovers that Intel® systems differ from UNIX system. Intel® uses two chars to end a line because of the prevalence of Model 23 TeleType® machines then being used for development on 8080 CPUs using Isis II. nowadays UNIX systems can run on Intel machines. Now It's an OS specific NEWLINE character that has been discussed before.

Windows/DOS: CRLF (ASCII 13, ASCII 10)
UNIX/LINUX: LF (ASCII 10)
MAC: CR (ASCII 13)In 1979 Intel and others provided 8080 development systems that were not UNIX and used the two chars to end a line. You could send a text file to the TeleType machine.Can't do hat with just a line feed. And in Intel based system it has been that way, because Intel said so, not because of anything about the CPU. And years later when MANY started to use UNIX on Intel CPUs it confused the programmers. Not the fault of the CPU, it was not the Intel way. It was a question of what system you learned on. And old habits die hard. We still use two chars to end the line, but I doubt very much anybody is using any teletype machines nowadays. Mine worked better If I set up three nulls after Lin feed. The output thing would send nulls, if told to do so.
I don't miss it one bit. Excuse the pun.Quote from: Reno on April 19, 2009, 11:02:58 PM
there is this invisible character for each new line, costing 2 bytes. - 0x0d 0x0a
...
for the above code, i've no idea why each new line cost 3 bytes

Yes, I knew the eol (end of line) comment character 0D (CR) 0A (LF).

Why it costs 3 bytes in my first scenario? Let's wait for the answer together : )Three bytes? in the command line there is a space in front of the first item. Could that be it?Quote from: Geek-9pm on April 20, 2009, 01:22:35 AM
Three bytes? in the command line there is a space in front of the first item. Could that be it?

I'm afraid not. Because I find a new clue. Save below code as a batch file.

Code: [Select](echo TestStr&echo.)|findstr /o ".*"
pause
Run it, get below result.

Quote
C:\Test>(echo TestStr & echo.) | findstr /o ".*"
0:TestStr
10:

C:\Test>pause
Press any key to continue . . .

One strange thing should be pointed out. The Command Line Interpreter adds 2 blanks before &. But generally, the command separator is only 1 blank.

To see the duplicate blank in another way, let's run below command.

Code: [Select](echo TestStr&echo.)|findstr /o ".*">a.txt
We'll find there is a blank at the end of TestStr in the file a.txt.

Why the Interpreter adds 2 blanks before &? Need help for further investigation.

I am going to update above info in the topic.
3317.

Solve : Batch file & choices?

Answer»

I'm new to this level of programing so forgive me if any of this is stupid. I'm trying to write a batch file that reads from a SPREAD sheet and does something based on an input.

I already got it reading and doing with:

for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.CSV) do set choice=%%p


IF %choice% ==ONE GOTO ONE
IF %choice% ==TWO GOTO TWO
IF %choice% ==THREE GOTO THREE

Where %%p is a colum in the spreadsheet and chice is just a variable. However i want to change it so rather than entering this choice on the spreadsheet they are propted for it. i.e.

Press A for One
Press B for Two

Enter A or B

I started by putting :

for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv) do CHOICE /C:abc

IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE


This worked for the first row on the spreadhseet but i can't GET it to work for the following rows. I get the prmpts to enter abc... for the number of rows but this dosn't translate into jumping to the code section, running the code and then repeating for the next row.

Hope thats clear, if you need anything else let me know. Full code bellow and spreadsheet is a csv file of peoples details.


@ECHO OFF
:BEGIN
CLS


ECHO Enter Letter for site:
ECHO a for one
ECHO b for two
ECHO c for thre


for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv)do (ECHO %%g
for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv) do CHOICE /C:abcdefghijklmno


IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END


:THREE
ECHO YOU HAVE PRESSED three
GOTO END

:TWO
ECHO YOU HAVE PRESSED two
ECHO %%g
GOTO END

:ONE
ECHO YOU HAVE PRESSED ONE
GOTO END

:END
I'm just going to shorten your code. INSTEAD of listing every number from x to y, why not do this instead?
tokens=1-12

So thr correct syntax would be:
for /f "Skip=1 tokens=1-12 delims=," %%g in (whatever) do (
command a
command b
...
)

you can have as many commands as you like within the braclets. Thanks for the code shortening.

I've given up trying to code my way out of this and created an excel macro which i linked to the batch file to do what i need. Cheers for the help/Quote from: arough on November 19, 2009, 02:07:00 AM

Thanks for the code shortening.

I've given up trying to code my way out of this and created an excel macro which i linked to the batch file to do what i need. Cheers for the help/
Good for you. I'm glad you made your own way.
3318.

Solve : Possible to Network?

Answer»

I have all these nics and thought about putting one into my 486. Thing is can I make it so that it is on a network or do I have to use something like novell or some KIND of NETWORKING os like that.you need the network drivers for the CARD. If the 486 has DOS you should select a NIC that has DOS drivers.


you'll be ABLE to use the NET command to setup shares and so forth.

3319.

Solve : How to check task manager process status?

Answer»

Dear Experts,
How to check WHETHER the purticular process is running or not,

Suppose there is a word application opened,
then process seen in the task MANAGER is "Winword.exe",
then how do i check whether the "Winword.exe" process is running(exist) or not.

please advise.you can use TASKLIST. See tasklist /? for more INFO.

3320.

Solve : VBS to EXE?

Answer» HELLO!

I have a file that i need to save as an exe so it can not be edited at or and/or so users are not getting our passwords... i have been searching for some time now and cannot find freeware that will let me convert and ALSO append an icon... does anyone know of any free software that will let me perform these tasks?

Thanks for the assistance!

HoFLFrom your information iut is hard to understand what you want to do.
Do you intend to prevent the use of VBS to PROTECT your system?
Dio you have a script that must be PROTECTED?
Is the script part of a web page?
Can you program in another language instead of VBS?

I want to convert the following script into an ".exe" file. I just cannot seem to find a free app that actually works. One of the takes i need to be able to do is append an icon to the newly created ".exe".

CODE: [Select]Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.run ("runas /env /user:administrator fluidpower.exe")
WScript.Sleep (100)
WshShell.AppActivate "C:\windows\system32\runas.exe"
WScript.Sleep (100)
WshShell.SendKeys "password"
WScript.Sleep (100)
WshShell.Sendkeys "~"
WScript.Sleep (100)
Thanks for he help!

HoFL
3321.

Solve : batch file not working?

Answer»

hi i GOT a code earlyer and i edited it a bit well alot and its not working if anoyone can spot the problen plz reply

Code: [Select]@echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
set /p "pass=>"
if %pass%==password (goto stop) else (goto incorrect)
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a "try= %try% - 1"
you have %try% trys left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
pause
exitItems in RED are my REPLACEMENTS.

@echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
set /p "pass=>"
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
pause (this is UNNEEDED)
exit

That took about 2 minutes...PRETTY simple stuff...I didn't look that hard, but it should work now.it still not working as soon as i press enter to enter the password it goes away Quote from: Helpmeh on April 19, 2009, 09:57:26 AM

Items in red are my replacements.

@echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
set /p pass=^>
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
pause (this is unneeded)
exit

That took about 2 minutes...pretty simple stuff...I didn't look that hard, but it should work now.
That should do it.Quote
if not "%pass%"=="password goto incorrect

Spot the error

Also:

Quote
echo plase type password

This is how you spell "please".

Quote
echo you have used up all your trys system is shutting down

The plural of try is tries.



Quote from: Dias de verano on April 19, 2009, 01:15:33 PM
Spot the error


Lol...I can't believe I missed that...this is so wrong, if you try to password-protect your pc with batch and put the batch file in startup folder, it's the most silly thing i've ever heard.
cmd batch run in a seperate process, in it's own box. To terminate it, i just need to press Ctrl-C or click on the X mark to close the box or just do nothing.

plz use the built-in user account:
Start-->Control panel-->user accountQuote
Quote
echo plase type password
This is how you spell "please".
Quote
echo you have used up all your trys system is shutting down
The plural of try is tries.

If BATCH is lexicographically sensitive,
- I better give it up altogether

yea but my dad my mum and my brother dont know that and any way the peice of code isent finished

also i found somin else
changes in red
Code: [Select] @echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
[color=red]set /p "pass=>" [/color]
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
exit
thanks for your helpQuote
if not "%pass%"=="password goto incorrect

there is a quote mark missing at the end of "password

This will cause a syntax error.
Quote from: steven32collins on April 20, 2009, 09:17:54 AM
also i found somin else
changes in red
Code: [Select] @echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
[color=red]set /p "pass=>" [/color]
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
exit
The quotes shouldn't be required. Please not that you must escape the greater than character (as I did in a previous post).Quote from: Helpmeh on April 20, 2009, 03:14:06 PM
The quotes shouldn't be required. Please not that you must escape the greater than character (as I did in a previous post).

Either no quotes at all or two sets. One set no good.

Quote from: Dias de verano on April 20, 2009, 03:44:21 PM
Either no quotes at all or two sets. One set no good.


I was talking about set /p "pass=>" is his code. This is what needs to be done: set /p pass=^>
3322.

Solve : Decypher file attribute in a FOR loop?

Answer»

My tests on the attribute variable seemed to work but I will give your suggestion a try.

Code: [Select]if %mm% GTR 01 set /a jd1=%jd1%+31
I am creating two dates in the format yyyyddd. I start by taking the year and multiplying by 1000. Then I have to add DAYS based on the month. If the month is March then I need to add the days for January and February. Then I add the day for the date in question.

For eample, suppose the date is 03/15/2009. I take the year and multiply by 1000 getting 2009000. The month is greater than 1 so I add 31 days for January. The month is greater than 2 so I add 28 days for February (yes, I do not account for leap year). The month is not greater than 3 so it falls through the rest of the "if" statements. I then add the current day. Now the date is 2009074.

The "if" statement for greater than 12 will never be true and should be deleted.



QUOTE from: kwc1059

I am creating two dates in the format yyyyddd. I start by taking the year and multiplying by 1000

You may find these SCRIPTS useful

http://www.commandline.co.uk/cmdfuncs/dandt/index.html

Also, VBscript has built in date MATH functions. You can USE them from batch, if VBscripts are allowed on your system

Code: [Select]@echo off

REM Create VBscript
echo wsh.echo Year(wscript.arguments(0))^&DatePart("y", wscript.arguments(0))>Daynumber.vbs

REM now you can use it in your script as many times as you want

set querydate1=20/11/2009

REM pass the date to the VBscript & get back the result
for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate1%') do set Daynumber1=%%D

set querydate2=20/03/2009

for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate2%') do set Daynumber2=%%D

echo The day number of %querydate1% is %Daynumber1%
echo The day number of %querydate2% is %Daynumber2%

output

Code: [Select]The day number of 20/11/2009 is 2009324
The day number of 20/03/2009 is 200979
As you can see, my system uses the European dd/mm/yyyy format for dates but I believe that if your system locale settings are US you would find that 11/19/2009 would give you 2009323 but you would have to try that yourself.

Hello
3323.

Solve : config parser in perl?

Answer»

Hello every one

I just tried out one more THING and get stuck and needed ur help plaease help me regarding following issue.

I have a test.txt file like follows:
[.cpp file]
a.cpp
b.cpp
c.cpp
[end]

[.h file]
a.h
n.h
[end]

now i want to right the perl script which parser the file so that i can complie the .cpp file correctally.(i already have the method to complie it), and need to copy header files at one place(already have method for it)

just want to know how we can use CONFIG parser module in this.

Thanks for HELPIF you want to use a module, you can search CPAN. one of them is Config::IniFiles. install and play with it. read its documentation. however, you can also do it without a parser module.
Code: [SELECT]while (<>){
if (/\[end\]/ ){ $flag=0 }
if ( /\[.cpp file\]/ ){ $flag=1;NEXT}
$flag && print $_ ;
}

output:
Code: [Select]# perl test.pl file.ini
a.cpp
b.cpp
c.cpp

thanks for reply , i tried to play with that module.Quote from: roohi on April 21, 2009, 02:29:59 AM

thanks for reply , i tried to play with that module.
if it doesn't suit your needs, search CPAN for Parser or Config (or other search terms) and see if you can find others that's suitable for you.
3324.

Solve : Opening explorer.exe?

Answer»

If i was to open explorer.exe is there anyway to switch between to two interfaces??? so for instance have my music on 1 and my work on the other. i understand this would slow down my computer but it would be great to know

Thanks,
KhasiarIm guessing you mean like in Linux where you can switch between more than one work spaces, and I'm also guessing this is to hide something and pretend you're doing something else (Excuse me if I'm wrong).

If I am correct, no, you cannot open explorer.exe more than once. Give it a try. It won't work. But you could simulate another Work station inside of yours using VMware.

If you have a good nVidia video card you can, but not with batch. if you are using XP follow the below link and down load the "Virtual Desktop Manager"

http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspxdam, i was hoping for an inbuilt solution, thanks anyway guyz Quote from: Khasiar on NOVEMBER 18, 2009, 04:57:00 PM

dam, i was hoping for an inbuilt solution, thanks anyway guyz

I take it you don't have admin rights and aren't allowed to install anything.

Sounds like Google may have been correct. What are you trying to hide? You can have 2 Explorer WINDOWS open and tile them vertically.



Or there are various free Explorer substitutes with multi pane layout options such as xplorer²



Quote from: Salmon Trout on November 19, 2009, 12:39:12 AM
You can have 2 Explorer windows open and tile them vertically.



Or there are various free Explorer substitutes with multi pane layout options such as xplorer²





HAHAHAHa yea actuallly how could I have been so ignorant to not think of this?!?!?

Nice Actually i am doing this at work and have admin rights as i am in ITbtw that picture is blank, are you talking about 2 folder explorers or actual user interface explorers
Quote from: Khasiar on November 19, 2009, 05:39:59 PM
btw that picture is blank, are you talking about 2 folder explorers or actual user interface explorers

The picture is definately not blank, and to answer your question, it is of 2 folders open beside each other. Quote from: Khasiar on November 19, 2009, 05:39:59 PM
btw that picture is blank, are you talking about 2 folder explorers or actual user interface explorers


Maybe PHOTOBUCKET is blocked where you are viewing this forum?

2 instances of Windows Explorer. I am not sure what this means: " 2 folder explorers or actual user interface explorers"Quote from: Khasiar on November 19, 2009, 05:38:49 PM
Actually i am doing this at work and have admin rights as i am in IT

Is there any reason you can't download and install the desktop manager I provided the link to?

Since you are in "IT" I will wait for you to figure out what vital information you have left out in all of this.Windows Explorer handles both the windows desktop and the "folder explorers" more precisely, Explorer windows.

I believe that Windows Explorer only allows one "desktop" windows explorer to run WITHIN each desktop. If one is already running, it opens a Explorer Window instead.

Short story: if you want two DESKTOPS, you'll need a multiple desktop solution, such as that already provided.

I've always rather liked the SysInternals "Desktops" program:

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

added advantage is that it works on Vista And windows 7... I think.
3325.

Solve : Help about ms-dos?

Answer»

Respected sir,

Please send me solution about following problems

I bought branded PC which has no CD ROM and the OS on that is MS dos. If I want to install Xp, how should I install it. It has LAN card. Is there possible to install OS through LAN in MS dos mode.

Please reply as soon as possible.
It's urgent Add a cd / dvd DRIVE, they are very cheap
My solution:
Bring your HDD to another PC and install (it faster than install OS though network).
USB flash disk, and make it like bootable and have OS source install in it.Quote from: tonlo on April 21, 2009, 04:44:31 AM

My solution:
Bring your HDD to another PC and install (it faster than install OS though network).
USB flash disk, and make it like bootable and have OS source install in it.
do you think that other PC needs to have same hardware?I wouldn't think so- but some drivers in config.sys might not load.

Worst case scenario being F5 to skip the two files.

the "basic" DOS system will run on any PC- getting the extras (like sound and VESA support) are the tough ones.if it does work like bring the HDD to another PC and install XP, it would cause problems when its put back into the original PC. Is windows smart enough to "reconfigure" itself on different hardware ?oh. Nevermind- we're talking windows here.

Nope- that won't work unless the PCs are similar.

Although, in the case windows won't load (wrong Hal and drivers and such), then sometimes a Repair install can get it booting again. It would still have the wrong drivers and likely start using the generic ones, but it would be enough to start and install the proper ones.


I found something interserting on NET when people try to install OS on an Eee PC (no cdrom). Hope it helps
http://www.multimolti.de/blog/2008/12/14/install-windows-7-on-asus-eee-pc-900/

And a guidance for the ASUS Eee PC 901 and 1000 series notebooks

Quote
General
Welcome to our how-to guide for the ASUS Eee PC 901 and 1000 series notebooks. Please be sure to read our legal disclaimer before proceeding. As we have previously noted, we strongly suggest the purchase of the ASUS Eee PC 1000H due to its faster hard drive. However, this guide will work on any Eee PC 901 or 1000 series nettop computer.
We apologize for the delay in putting this together, however, it was well worth the wait. This guide benchmarks higher than any other process we tried, and it is completely stable. All functionality on the device works, except for sound and Ethernet (Wi-Fi does work very well).
Beyond that, read more to see the steps.
First, you will need a couple of things.
1) iDeneb 10.5.4. This is a modified version of the Mac OS X installer, which will allow installation on unsupported hardware. Due to legal concerns, we cannot provide you with a direct link. However, a BitTorrent download of it is available by searching on ThePirateBay.org as well as Demonoid.com.
2) A retail, licensed copy of Mac OS X Leopard. Please support Apple and don’t steal software. This guide is here to help you use Leopard legally. If you’re going to steal Leopard, please go to another web site… we don’t want to help you.
3) A USB 2.0 DVD-ROM drive.
Optional things that may help: A USB Keyboard and Mouse. If you have an SSD version of the Eee PC, you may want to use an USB Hard Drive.
BIOS Update
The Eee PC 901’s BIOS has a bug that slows down third-party operating systems. While the technical reasons are complicated, essentially the power management settings (ACPI) are incorrect inside the BIOS.
To fix this, we need to flash with a modified BIOS. This process is unsupported by ASUS, and if it were to fail, you may void your warranty. To protect your warranty, be sure to flash back to the standard BIOS before sending the unit in for any repair.
This step is optional, but recommended. It will greatly SPEED up the boot time of the Atom-based Eee PC.
You can get the update from the BIOS.mod page of osrom.net. To install the update, you can use the ASUS Update tool pre-installed with Windows XP. Alternatively, you can use the bootablew flash tools available on ASUS’s web site.
Steps to Install
Caution, keep in mind that this will erase all information on your Eee PC. Also, please check with ASUS to make sure you are running the latest version of your Eee PC BIOS before installing.
1) Connect the USB 2.0 DVD-ROM drive to the computer. Insert the iDeneb install disc. Power it on and rapidly press the F2 key.
2) When the BIOS menu appears, go to Advanced > CPU Configuration. Disable all three items in this sub-menu. Press Esc and scroll to the Boot tab. Re-arrange boot priority to have the desired drive boot listed first. Finally, Exit and Save Changes. Also, go to Onboard Devices in the BIOS and disable all four items (after we install Mac OS X fully, we will change these settings).
3) The computer will reboot. Rapidly press the Escape key until a Boot Menu appears. Select the DVD drive and press any key at the prompt to boot from the disc.
4) When the Installer boots, select English as the default language. Then, go to Utilities > Disk Utility.
5) Select the drive you want to install on. Go to the Partition tab that appears. Chose the partitioning as Mac OS Extended (Journaled). If you have an SSD-based system, chose Mac OS Extended (not journalized, this will improve performance).
6) Click the Options… BUTTON. Select the GUID Partition Table and click OK. Then click Apply to format the drive. Finally, click the red close button to exit Disk Utility.
7) Proceed with the Installer as instructed. When you reach the drive selection, chose the drive you just formatted. Then press Continue. Finally, on the next screen, chose Customize to select the correct packages.
Click the triangle to expand the patches.
Expand the triangle for Chipsets and check ICHx Fixed.
Expand the triangle for Kernel and check Kernel 9.4.0 Vanilla.
Expand the triangle for Wireless and check Broadcom.
Expand the triangle for Fix and check both FireWire Remove and ApplePS2Controller
Expand the triangle for Video, then the triangle for Intel. Finally, check the box for GMA950.
9) Click Continue and then proceed with the installation.
10) Complete the Setup Wizard which appears on first boot. Congratulations, you now have Mac OS X on your Eee PC!
Post-Install Drivers & Enhancements
So, you now have Mac OS X on your Eee PC. But, you probably notice that some things aren’t working. Namely, audio, graphics acceleration, and Wi-Fi all are not functional. In these next steps, we will install the drivers necessary to enable these features.
1) Download this installation set. It contains drivers and tools that we will use to perfect the installation. Credit goes to some of the staff at MoDaCo for helping to compile portions of the kit.
2) Extract the contents on your desktop.
3) Restart the computer and access your BIOS settings. Turn SpeedStep back on in CPU Configuration. Go to Onboard Devices and enable all four items. We are doing this at this time, to ensure that you have completed Setup Assistant. Doing this step before completing Setup Assistant can cause the installation to hang.
4) Run the AboutThisMac tool inside the folder that you just extracted. This will correct the processor identification in the About This Mac window.
5) Now, we need to install some drivers. Copy or move the Kext Installer utility to the Applications folder. Launch it.
6) Drag all the files from the Drivers folder onto the Kext Installer window. Enter your password, and allow it to begin. NOTE that if you left your password blank when setting up the Eee PC, you need to give your admin account a password. You can do this in System Preferences > Accounts. This utility will not run on an account that does not have a user password set.
7) When the Kext Installer completes, it will ask you to reboot. Restart the computer, and then run System Preferences > Energy Saver. You should now be able to add the battery status icon to your menubar (if it wasn’t there already).
One last part… setting up Wi-Fi. Download this driver from chipset maker Ralink. Install the Mac OS 10.5 version of the driver from the resulting disk image. Reboot when requested.
9) To configure Wi-Fi, first launch System Preference > Network. It will alert you that a new Ethernet connector has been found. This is actually your Wi-Fi card. You can rename the device to Wi-Fi, or leave it as is. Click OK, and close out of System Preferences.
10) Connecting to a Wi-Fi network is a bit different. Instead of using the AirPort menu bar, go to your Applications folder. Launch the new utility located there, called WirelessUtilityCardbusPCI. From there, go to the Site Survey tab, and press Rescan. You should be able to chose your wireless network and connect to it, by double-clicking on the network you want to connect to.

Conclusions, Work Remaining
Benchmarking this workflow with Geekbench, we scored a 910. That puts the Eee PC ahead of any PowerBook G4 (graphics aside), and within 9% of a 1.6 GHz Power Mac G5. All this in a machine that costs around $670 (taking into account the cost of the system, and the purchase of a retail copy of Leopard).
OBVIOUSLY, two things remain to get up-and-running on the Atom-based Eee PC. First being audio support. Second, built-in Ethernet. We’re working on it, and some limited progress has been made. While we can’t guarantee sound on the Eee PC, it certainly is the top priority right now.
On putting the Eee PC to sleep. Sleep works fine (if you followed the guide above). To wake the system, press the power button. Unlike a Mac, opening the lid will not wake the machine, only pressing the Power button.
Finally, as with any unsupported hardware, do not any Mac OS X system software update, or any Security Update from Apple, without checking here first. These updates can inadvertantly interfere with patches that we have run. Generally, if Apple Software Update does not require a reboot to install the update, it is safe to install. And, of course, stay tuned to MacEee.com, both for updates to this guide, and for complete Eee PC coverage.
Optional: Migrating to the speedy SSD partition.
Caution! This step is only for seriously advanced users. We don’t suggest it for everyone… most will be fine with running off the 8 GB SSD array.
We won’t go in-depth on this, as it is meant for experienced users. However, if you have an SSD-based Eee PC and want to move your OS X install to the 4 GB partition, it can be done. First, trim down your installation (preferably on a USB hard drive at this point). You can do this first by running Youpi Optimizer, and then by removing files that you don’t need from the installation. Be careful, as many files may be needed to boot the operating system.
You may want to backup your USB hard drive first, using Disk Utility on another machine. This will give you more flexibility to trim the installation.
Once you have done that, you use SuperDuper to transfer the install to the 4 GB SSD drive. Note that you will likely need to use a third-party tool to move the virtual memory spare files to the other SSD drive (since with only 4 GB, you will be low on disk space regardless).

Quote from: tonlo on April 21, 2009, 04:44:31 AM
My solution:
Bring your HDD to another PC and install (it faster than install OS though network).
USB flash disk, and make it like bootable and have OS source install in it.

Will not work.

3326.

Solve : flash drive ram?

Answer»

Quote from: tonlo on April 21, 2009, 11:43:11 AM

My idea.
Yes Flash drive is RAM ... if you agree with me window PAGE file (swap partition in Linux) is RAM.

You want to put page file/swap file on a flash drive? That would kill the flash drive quickly.
Quote from: DIAS de VERANO on April 21, 2009, 12:02:12 PM
You want to put page file/swap file on a flash drive? That would kill the flash drive quickly.


That's why let people use my extra blank DVD's for partition transfer.I personally don't suggest steven32collins to do that. I just answer "is there a way" question.http://www.microsoft.com/windows/windows-vista/features/readyboost.aspxQuote from: Geek-9pm on April 21, 2009, 12:54:50 PM
http://www.microsoft.com/windows/windows-vista/features/readyboost.aspx

This was covered a couple of pages back.
Quote
Dias de verano
http://www.microsoft.com/windows/windows-vista/features/readyboost.aspx
This was covered a couple of pages back.
Sorry, my bad.
Yes, you said that as the first response to the original post.
Still -
Way would Microsoft allow or document a feature that would cause harm to the Flash device? IMO that is just typical of Microsoft. But it does make we wonder.I think he can make a PART of HD work like RAM.
I see that topic starter uses the Windows XP, so he can configure the VIRTUAL MEMORY.

P.S. It will work a little bit faster and as you know the data access speed of HD is not such as RAM

Cheers.Quote
would Microsoft allow or document a feature that would cause harm to the Flash device?

No. Some people have the incorrect and mistaken idea that Readyboost works by storing the swap file on the flash drive. This is not so. Readyboost does not exercise a flash drive in the same way that using it as a swap partition would.

Flash memory can only take so MANY writes. Even with techniques such as wear levelling, swap file use will destroy a flash drive in a fairly short time.

The core idea of ReadyBoost is that a flash drive has a much faster seek time (less than 1 millisecond), allowing it to satisfy requests faster than a hard disk when booting or reading certain system files. (System files, right? That don't change - write once, read many times) By the way, unless you have USB 2.0 and you are using a top end pen drive or memory card ReadyBoost won't make a lot of difference. And even then it won't be anything to write home about.

A swap file on the other hand is constantly changing as memory is paged in and out. Furthermore, Windows uses the page file in blocks of 4096 bytes but flash memory usually has logical blocks of 65536 Bytes and whenever a 4K block is written the flash device has to erase and rewrite a whole 64K block. So pretty soon all the memory cells on the flash drive will be worn out.



3327.

Solve : Delete zero size files in a drive eg:D:\ in win xp?

Answer»

HelloI use XP SP3 too and ('dir /b /s /a-d') worked fine. I don't know why it didn't work for you. One thing - if you scan a whole drive there may be a long time when NOTHING seems to be happening.

zerodel.bat

Code: [Select]@echo off
setlocal enabledelayedexpansion
set /a file=0
if exist "%temp%\deletions.bat" del "%temp%\deletions.bat"
for /f "delims==" %%A in ('dir /a /b /s /a-d') do (
if "%%~zA"=="0" (
set /a file+=1
echo [!file!] 0 bytes "%%~dpnxA"
echo del "%%~dpnxA" >>"%temp%\deletions.bat"
)
)
Echo.
Echo Deletions:
type %temp%\deletions.bat

output

Code: [Select]C:\basic>zerodel
[1] 0 bytes "C:\basic\freebasic\New Text Document.txt"
[2] 0 bytes "C:\basic\freebasic\examples\compiler.log"
[3] 0 bytes "C:\basic\freebasic\examples\file\.txt"
[4] 0 bytes "C:\basic\freebasic\examples\Windows\COM\MoviePlayer\movctrl\obj\deleteme.txt"
[5] 0 bytes "C:\basic\freebasic\examples\Windows\COM\WebBrowser\webctrl\obj\deleteme.txt"
[6] 0 bytes "C:\basic\freebasic\FbEdit\Projects\Applications\Convert\Convert.bi"
[7] 0 bytes "C:\basic\freebasic\FbEdit\Projects\Samples\DialogApp\DialogApp.Bi"
[8] 0 bytes "C:\basic\freebasic\fbmat020\fbmat020\demo\largeint\PrimFlgs.bin"
[9] 0 bytes "C:\basic\freebasic\mike\projects\colorbars\compiler.log"
[10] 0 bytes "C:\basic\freebasic\mike\projects\graf2\compiler.log"
[11] 0 bytes "C:\basic\freebasic\mike\projects\pi-app\PrimFlgs.bin"
[12] 0 bytes "C:\basic\qbasic\avi.asm"
[13] 0 bytes "C:\basic\qbasic\ETHEREAL.LOG"
[14] 0 bytes "C:\basic\qbasic\RTSP.TXT"
[15] 0 bytes "C:\basic\qbasic\URLDUMP.TXT"

Deletions:
del "C:\basic\freebasic\New Text Document.txt"
del "C:\basic\freebasic\examples\compiler.log"
del "C:\basic\freebasic\examples\file\.txt"
del "C:\basic\freebasic\examples\Windows\COM\MoviePlayer\movctrl\obj\deleteme.txt"
del "C:\basic\freebasic\examples\Windows\COM\WebBrowser\webctrl\obj\deleteme.txt"
del "C:\basic\freebasic\FbEdit\Projects\Applications\Convert\Convert.bi"
del "C:\basic\freebasic\FbEdit\Projects\Samples\DialogApp\DialogApp.Bi"
del "C:\basic\freebasic\fbmat020\fbmat020\demo\largeint\PrimFlgs.bin"
del "C:\basic\freebasic\mike\projects\colorbars\compiler.log"
del "C:\basic\freebasic\mike\projects\graf2\compiler.log"
del "C:\basic\freebasic\mike\projects\pi-app\PrimFlgs.bin"
del "C:\basic\qbasic\avi.asm"
del "C:\basic\qbasic\ETHEREAL.LOG"
del "C:\basic\qbasic\RTSP.TXT"
del "C:\basic\qbasic\URLDUMP.TXT"

C:\basic>
Quote from: Salmon Trout on November 19, 2009, 01:40:07 PM

I use XP SP3 too and ('dir /b /s /a-d') worked fine. I don't know why it didn't work for you. One thing - if you scan a whole drive there may be a long time when nothing seems to be happening.

zerodel.bat

Code: [Select]@echo off
.....
for /f "delims==" %%A in ('dir /a /b /s /a-d') do (
if "%%~zA"=="0" (
set /a file+=1
echo [!file!] 0 bytes "%%~dpnxA"
echo del "%%~dpnxA" >>"%temp%\deletions.bat"
)
)
.....

The above method delete files one by one. Not that its really a big deal, but a suggestion for a more efficient way, since del can delete multiple files passed to it on the command line, is to concat all the FILENAMES into one string, either by batches (or as many as del can TAKE as input) and then pass it to del. Hello
3328.

Solve : deleting multiple files with batch?

Answer»

Hey guyz, im trying to delete the copies of my songs in a directory. i got alot of files with the same file name and its annoying trying to delete one by one, eg.

1.mp3 1mb
1.mp3 1mb

like to delete all but one..

thanks
I'd move the one you want out of the directory, then empty the directory (del *.*). After that, you can move the one back.yea, thats OK with just 1 file, but im talking over 1000 with over 300 directories. you can see my problemNeed to get some idea of your directory TREE.Quote from: Khasiar on April 23, 2009, 11:16:04 PM

yea, thats ok with just 1 file, but im talking over 1000 with over 300 directories.

Originally you wanted to save one file in a directory.

Quote from: Khasiar on April 23, 2009, 11:07:39 PM
Hey guyz, im trying to delete the copies of my songs in a directory.

like to delete all but one..

Could you EXPLAIN a little more of what you mean to accomplish as well as, like Dusty said, describing the directory tree that contains these files you want to delete?The following will do binary compare:
------------------------------------
1. Traverse all the directory and save the listing to a temp file
2. SORT temp file by file size
3. for each files with the same size, do file compare fc.exe/b song1.mp3 song2.mp3

The following will do file name check:
-----------------------------------
1. Traverse all the directory and save the listing to a temp file
2. sort temp file by file name
3. for each files with the same name, delete duplicate(s)

which one are you after?ok. same file names in the same directory? possible on windows file system?Quote from: gh0std0g74 on April 24, 2009, 05:48:15 AM
ok. same file names in the same directory? possible on windows file system?

Is your question rhetorical?
That would cause an ERROR if some of the files have exact duplicates in the same directory when you try to use MOVE, or copy.i was actually trying to ask if OP's duplicate files are in different folders or not, because AFAIK(am not a windows expert) , wouldn't the OS give error you there are same file name ( case insensitive ).No idea at this point. First it sounded like 1 file of many in a directory, now it's 1000 files over 300 directories. In either case, it's impossible for two identical files with identical names to exist in the same directory.Sorry to confuse everyone, the main situation is that i have many files that are the same in different directories.

eg

c:\music\artist\123.mp3
c:\music\favs\123.mp3
c:\music\mymusic\123.mp3
c:\music\hismusic\123.mp3

problem is, ive copied most of them, and when i look in my media library i see doubles, triples and even up to 5 times the same song.... i know what was i thinking lol... but this was my first attempt of trying to arrange my files in a somewhat orderly manner by artist etc... and its a horrible mess... any help would be great...


Khasiar if you have Perl and can use it. Uses MD5 to check for file duplicates.
Code: [Select]use Digest::MD5;
use File::Find;
use File::Copy;
my %seen;
my $destination = "c:/tmp";
sub getmd5 {
my $file = $_[0];
open(FH,"<",$file) or die "Cannot open file: $!\n";
binmode(FH);
my $md5 = Digest::MD5->new;
$md5->addfile(FH);
return $md5->hexdigest;
close(FH);
}
sub wanted {
if ( -f $_ && /\....$/ ){
my $file = $File::Find::name;
my $md5 = getmd5 $file;
if ( defined($seen{$md5}) ){
# duplicates
print "duplicate $file" . "=>" . $md5 ." \n";
unlink $file or die "Cannot remove $file:$!\n";
}else{
$seen{$md5} = $file;
}
}
}

my $dir = "c:/test";
# Traverse desired directory
File::Find::find({wanted => \&wanted}, $dir);
foreach my $v (values %seen){
print "\$v: $v\n";
move ("$v", "$destination" ) or warn "Cannot move file to destination:$!\n";
}


alternatively, if you want to do in batch, you can use fc command, for loop, doing some if else check etc etc.. Ahhh ok.

If you're running Windows, might be easier to use something like this:
http://www.snapfiles.com/get/dupfilefinder.htmlThanks quaxo im pretty sure this is excatly what i wanted, using it now so ill let you know if it works laters ..


cheers

Khasiar
3329.

Solve : showing all files in all subdirectories by owner attribute?

Answer»

grant, here it is. code becomes longer with the additional feature, i've try my BEST to make it as compact as possible.
the below code will run version 1, if you want to run version 2, comment the line call:version 1 and uncomment call:version 2.

Code: [Select]::NetBackup.bat
@echo off & setlocal enabledelayedexpansion & cls

set/p copy_dir=Input Directory to COPY to (eg. c:\test\) :
set copy_dir || goto:eof
if not exist %copy_dir% md %copy_dir%

set vPath=&set vUser=
echo.Input Full Path (eg: \\remote-pc\sharefolder or c:\data or .) & set/p vPath=-
::set vPath || call:interface
set vPath || goto:eof
echo.&set/p vUser=Input Full User Name to Search (eg: %computername%\%username%) :
set vUser || goto:eof

echo.&echo Mapping %vPath% to next available drive letter
PUSHD %vPath% && (echo Success!!) || goto:eof

call:version1 &REM version1 code is short but took longer time to execute
::call:version2 &REM version2 code is longer but took less time to execute

popd
goto:eof


:version1
echo.&echo.Running Version 1...
for /r %%a in (*) do (
dir/q/a-d "%%a"|find/i "%vUser% ">nul 2>&1 && (
echo %%~fa
copy "%%a" "%copy_dir%" 1>&2
)
)
goto:eof

:version2
echo.&echo.Running Version 2...
time/t|find " ">nul && set/a A=5,B=0||set/a A=4,B=0
for /f %%a in ('echo."%vUser: ="^&echo."%"') do if not %%~a.==. set/a B+=1

set/a token=A+B-1
set token=%A%-%token%*
set token

for /l %%a in (1 1 %B%) do call set u=%%u%%%%%%%%a
set/a B+=1
for /r /d %%a in (.) do (
pushd %%~fa
for /f "skip=5 tokens=%token%" %%1 in ('dir/q/a-d "%%~fa" 2^>nul') do (
if /i "%u%"=="%vUser% " (
echo %%~f%B%
copy "%%~f%B%" "%copy_dir%" 1>&2
)
)
popd
)
goto:eof


i've also written an interface to view network computer and its share folder, you can plug the code into the bottom NetBackup.bat if you wish to use it.
Code: [Select]:interface
::The following is the interface to look for network pc and network shared folder
echo.&set/p c=Do you want to run interface (y/n) ?
if /i "%c%" neq "y" goto:eof

echo.&set/p vCompName=Input Computer Name (or blank to search) :
2>nul set vCompName || (
for /f "tokens=1,2* delims=[] " %%a in ('net view^|more +3^|find/n "\\"') do (
set v%%a=%%b& echo %%a. %%b)
set c=&set/p c=Enter Choice :
call set vCompName=%%v!c!%%
set vCompName || goto:eof
)

echo.&set/p vFolder=Input Folder Name (or blank to search) :
2>nul set vFolder || (
for /f "tokens=1-3* delims=[] " %%a in ('net view %vCompName%^|more +7^|find/n " Disk "') do (
set f%%a=%%b& echo %%a. %%b %%c %%d)
set c=&set/p c=Enter Choice :
call set vFolder=%%f!c!%%
set vFolder || goto:eof
)

set vPath=%vCompName%\%vFolder%


Quote from: Grant123 on March 20, 2009, 08:44:12 AM

so at this point, I give up on DECIPHERING your code but I'll run it and trust that it works!
there is only one way to make to code more readable, modify it to become longer by using the usual syntax, eg lots of if else if else, set, for, etc.

i just notice that for network share, the owner file name is not computername\username, but something like this:
Code: [Select]05/30/2008 03:49 AM <DIR> \Everyone FolderA
04/23/1999 07:22 AM 93,890 \Everyone COMMAND.COM
05/11/1998 05:01 AM 33,191 ... HIMEM.SYS
03/07/2009 01:34 AM 85,504 BUILTIN\Administrators sample.txt
Quote from: Reno on March 21, 2009, 03:55:36 AM
grant, here it is. code becomes longer with the additional feature, i've try my best to make it as compact as possible.
the below code will run version 1, if you want to run version 2, comment the line call:version 1 and uncomment call:version 2.

Code: [Select]::NetBackup.bat
@echo off & setlocal enabledelayedexpansion & cls

set/p copy_dir=Input Directory to copy to (eg. c:\test\) :
set copy_dir || goto:eof
if not exist %copy_dir% md %copy_dir%

set vPath=&set vUser=
echo.Input Full Path (eg: \\remote-pc\sharefolder or c:\data or .) & set/p vPath=-
::set vPath || call:interface
set vPath || goto:eof
echo.&set/p vUser=Input Full User Name to Search (eg: %computername%\%username%) :
set vUser || goto:eof

echo.&echo Mapping %vPath% to next available drive letter
pushd %vPath% && (echo Success!!) || goto:eof

call:version1 &REM version1 code is short but took longer time to execute
::call:version2 &REM version2 code is longer but took less time to execute

popd
goto:eof


:version1
echo.&echo.Running Version 1...
for /r %%a in (*) do (
dir/q/a-d "%%a"|find/i "%vUser% ">nul 2>&1 && (
echo %%~fa
copy "%%a" "%copy_dir%" 1>&2
)
)
goto:eof

:version2
echo.&echo.Running Version 2...
time/t|find " ">nul && set/a A=5,B=0||set/a A=4,B=0
for /f %%a in ('echo."%vUser: ="^&echo."%"') do if not %%~a.==. set/a B+=1

set/a token=A+B-1
set token=%A%-%token%*
set token

for /l %%a in (1 1 %B%) do call set u=%%u%%%%%%%%a
set/a B+=1
for /r /d %%a in (.) do (
pushd %%~fa
for /f "skip=5 tokens=%token%" %%1 in ('dir/q/a-d "%%~fa" 2^>nul') do (
if /i "%u%"=="%vUser% " (
echo %%~f%B%
copy "%%~f%B%" "%copy_dir%" 1>&2
)
)
popd
)
goto:eof


i've also written an interface to view network computer and its share folder, you can plug the code into the bottom NetBackup.bat if you wish to use it.
Code: [Select]:interface
::The following is the interface to look for network pc and network shared folder
echo.&set/p c=Do you want to run interface (y/n) ?
if /i "%c%" neq "y" goto:eof

echo.&set/p vCompName=Input Computer Name (or blank to search) :
2>nul set vCompName || (
for /f "tokens=1,2* delims=[] " %%a in ('net view^|more +3^|find/n "\\"') do (
set v%%a=%%b& echo %%a. %%b)
set c=&set/p c=Enter Choice :
call set vCompName=%%v!c!%%
set vCompName || goto:eof
)

echo.&set/p vFolder=Input Folder Name (or blank to search) :
2>nul set vFolder || (
for /f "tokens=1-3* delims=[] " %%a in ('net view %vCompName%^|more +7^|find/n " Disk "') do (
set f%%a=%%b& echo %%a. %%b %%c %%d)
set c=&set/p c=Enter Choice :
call set vFolder=%%f!c!%%
set vFolder || goto:eof
)

set vPath=%vCompName%\%vFolder%

there is only one way to make to code more readable, modify it to become longer by using the usual syntax, eg lots of if else if else, set, for, etc.

i just notice that for network share, the owner file name is not computername\username, but something like this:
Code: [Select]05/30/2008 03:49 AM <DIR> \Everyone FolderA
04/23/1999 07:22 AM 93,890 \Everyone COMMAND.COM
05/11/1998 05:01 AM 33,191 ... HIMEM.SYS
03/07/2009 01:34 AM 85,504 BUILTIN\Administrators sample.txt

Reno - I didn't get a chance to REPLY to this last message. The project's been pushed back farther and farther and I expect to be using this tool in June some time. You've saved me tons of time and I really appreciate it!
Thanks!
3330.

Solve : File Management?

Answer»

Hi there

Can anyone PLEASE help me write a following BATCH file please?

1) Backups a folder on a server "A"
4) Rename that folder
5) Call another batch file to execute someother process(i have this batch file so just needs calling)

Please advice
regards
Quote from: captedgar on November 18, 2009, 03:12:55 PM

Hi there

Can anyone please help me write a following batch file please?

1) Backups a folder on a server "A"
4) Rename that folder
5) Call another batch file to execute someother process(i have this batch file so just needs calling)

Please advice
regards


Hints:
1) copy/xcopy/MOVE. See copy /?, move /?, xcopy /? for more
2) ren /? , rename /?
3) call /?HelloHelloHello
3331.

Solve : How to - If user clicks EXIT then unmount (popd) network drive?

Answer»

I have a batch file that mounts a drive and runs various scripts on a network drive. Once the scripts completes the drive automatically unmounts. If the user clicks the exit button on the dos window I would like to unmount the drive. Do you KNOW how unmount a drive if the user exits the batch operation? Thanks MC


IF EXIT popd \\mynetwork

Why don't you just run the batch file in the background so user can't exit it by closing the prompt? Or do I not understand the problem?This is not possible if you MEAN "DOS" in Windows, SINCE that is actually CMD.

You can't unmount a drive in CMD.I have the mounting and unmounting working fine. Users test the scripts so they are allowed the flexibility to kill a batch if needed.

I just wanted to know if you can use

if Exit then do something...Oh i see what your using, Popd, haven't seen that in a while.

And no you can't check to see if the batch file closes then do something, it's not possible in batch.Alrighty thanks :-)you can compile somebatfile.bat to someexefile.exe wich will create subbatfile.bat. That subbatfile.bat will check if that compiled someexefile.exe is running or no yes, but if he means run whatever COMMANDS on program termination then thats not possible.

3332.

Solve : how creat ip address ,sub net mask default gatway batch file?

Answer»

my office ip address is xxx.xxx.xxx.xxx.xxx
subnet mask and GATE way is what ever that is putting by my senior but when i visit another office and this office ip change like yyy.yyy.yyy.yyy
can i preapre new BATCH file when i am at my A office than time i RUN that office batch file and when i visit another office at that time i run another batch file
in batch file automatically SET thats branch ip address by using netsh command

3333.

Solve : Automatic Set IP?

Answer»

My BAT script

Code: [Select]@ECHO off
:start
cls
ECHO.
ECHO Press : 1. Get IP from DHCP
ECHO 2. Change IP : 192.168.10.x / 32
ECHO 3. Show Ip config
ECHO X. Exit

set choice=
echo Choice :
set /p choice=

if not '%choice%'=='' set choice=%choice:~0,1%
:: Lay bat dau tu ky tu 0 cua chuoi~, do dai cua chuoi la 1.
:: choice=abcdef
::%choice:~3,2%=de

if '%choice%'=='1' goto function1
if '%choice%'=='2' goto function2
if '%choice%'=='3' goto function3
if '%choice%'=='x' goto end

ECHO "%choice%" is not valid please try again
ECHO.
goto start


:function1
echo.
Netsh interface ip set address name="lan" dhcp
goto end

:function2
set x=
echo.
echo IP : 192.168.10.X
echo X =
Set /p x=
Netsh interface ip set address name="lan" static 192.168.10.%x% 255.255.255.0
goto end

:function3
ipconfig | find /I "lan"
PAUSE
goto start

::Local Area Connection

:end
Script work fine, but i want it all automatic. I don't need to input anything . To make the script automatically, i think the first THING i need to know DHCP status of the interface. and then if DHCP is yes ----> run :function2, else run function1. I don't know how to get the DHCP status of an interface, how if machine have 1 interface and more than 2 interface?
Code: [Select]set name=lan

for /f "skip=2 tokens=1,2* delims= " %%a in ('netsh interface ip show addresses %name%') do (
set dhcpOn=%%c
goto :EndFor
)
:EndFor
if /I "%dhcpOn%" equ "yes" goto function2
if /I "%dhcpOn%" equ "no" goto function1
pause
this works for me, i dont know if it will for you Thanks, Devcom again.
i am not test your code yet, but i think it will work.
I know the command
netsh int ip show add
But i didn't know we can only display 1 interface by input the interface name like that
netsh int ip show add "interface name"Quote

To make the script automatically, i think the first thing i need to know DHCP status of the interface. and then if DHCP is yes ----> run :function2, else run function1. I don't know how to get the DHCP status of an interface, how if machine have 1 interface and more than 2 interface?
Now the second thing is function2, it still request user input. Can we it automatic too? My solution is random a number between 1-254 and set to X. And then run ping command if it is request time out --> set X ---> done, Else loop random again. It will have a risk if there are a machine enable firewall.
Quote from: tonlo on April 20, 2009, 11:33:28 PM
Now the second thing is function2, it still request user input. Can we it automatic too? My solution is random a number between 1-254 and set to X. And then run ping command if it is request time out --> set X ---> done, Else loop random again. It will have a risk if there are a machine enable firewall.

You can refer to below code to get an available IP. Let me know if you need further help.

Code: [Select]@echo off
set IPPart1=192
set IPPart2=168
set IPPart3=10
set IPPart4=#

echo Need MINUTES to look for an available IP.
for /l %%a in (2,1,254) do (
ping -n 1 -l 1 %IPPart1%.%IPPart2%.%IPPart1%.%%a >nul
)
rem Don't care whether an IP is pingable. We just need the arp cache.
arp -a>"%temp%\UsedIP.tmp"
for /l %%a in (254,-1,2) do (
findstr "%IPPart1%\.%IPPart2%\.%IPPart3%\.%%a" "%temp%\UsedIP.tmp"||set IPPart4=%%a
goto :FindIP
)

:FindIP
set AvaiIP=%IPPart1%.%IPPart2%.%IPPart3%.%IPPart4%
if "%IPPart4%" neq "#" (
echo Find an available IP: %AvaiIP%
) else (
echo No IP is available currently.
)
pause
goto :eof
Hi BATCHER,
Maybe that is your typing mistake
Quote
for /l %%a in (2,1,254) do (
ping -n 1 -l %IPPart1%.%IPPart2%.%IPPart1%.%%a >nul
ping -n 1 -l "missing size" %IPPart1%.%IPPart2%.%IPPart3%.%%a >nul
I understand why to ping all the IP in subnet 192.168.10/24. But i take so long, i changed the buffer size to 10byte to test how long does it take. Over 2min just for get ARP table. I can't spend 2min to automatic set the IP address because i can set IP in window graphic mode in ~30s.
Any better solutions?if you allways want same 'x' then use this :
Code: [Select]:function2
set x=24
echo IP : 192.168.10.%x%
Can't because i will share my script with other people in LAN. It will occur conflict IP.
How about if it change subnet to 16, and random the 3rd, 4th Octet. More random time, more less conflict happen Code: [Select]@echo off
setlocal enabledelayedexpansion
set IP=192.168.10

for /L %%P in (10,1,30) do (
ping -n 1 -w 10 %IP%.%%P >nul
if !errorlevel! equ 1 echo.%IP%.%%P is free...
if !errorlevel! equ 0 echo.%IP%.%%P isn't free...
)
pause
you can use that so all people in lan can get first free IP
it took me 11 sec to check 20 ip'sHi tonlo,

I've fixed that typo. Thanks for your reminder.
3334.

Solve : DOS filerename error?

Answer»

I am getting the following error message:

"BULK BILL.dsi" BULKBILL 834.dsi
The syntax of the command is incorrect.

This is the code that i am using
for /f "tokens=1-4 delims=:" %%d in ("%time%") do rename "BULK BILL.dsi" BULKBILL%%d%%e.dsi

This worked FINE yesterday afternoon several times. The only differnce is that las night the code was producing a FILENAME such as the ones below with the last four chars representing the hour and minute:
BULKBILL1702
BULKBILL1710
BULKBILL1807

Today the code is producing a filename that has a SPACE between the name and the timestamp, such as the error above shows.

Any IDEAS are appreciated.correction to the code:
for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename "BULK BILL.dsi" BULKBILL%%d%%e.dsi

I had a 4 in place of the 5 for the tokens. However, it still does not work when i change the tokens to 5.Code: [Select]@echo off
for /f "tokens=1-2 delims=:" %%a in ("%time%") do (
ren "BULK BILL.dsi" "BULKBILL%%a%%b.dsi"
)

3335.

Solve : Sync Environments?

Answer»

Hi there
Can anyone help me write a following batch file PLEASE?
I need a batch file which does the following
stops IIS on a remote server called "A"
change a .xml file within the folder on that server "A"
Call another batch file to execute a process
Rename a folder
Copy the same folder from another server "B" onto the above folder
restart IIS on server "A"

Please advice
regards
My suggestion is to setup a VPN Secure Tunnel you then would be able to do what you WANT. VPN Tunnel is doable if you are SHUTTING down your own IIS Server. Any way other than VPN Tunnel Method would be asking us all here to do the hacking for you to attack someone elses IIS Server.

Please set up a VPN Tunnel and then come back if you STILL need ASSISTANCE to do this.

3336.

Solve : forgot how to copy from drive a: diskette to drive c: hardrive?

Answer» How do I copy INFO from diskette a: to C: ? FORGOT the FORMULA. O.J.type COPY /? at the PROMPT

3337.

Solve : Explain THis Huge Dupe plsssssssssss.....?

Answer»

@echo off
cls
startw unpack.exe
del unpack.exe > nul
rem Technic DupeFiles Recovery Engine (c) 2003
cls
echo ...
echo Duping Files - PLEASE Wait.
echo ...
COPY /Y ".\system\data\blank.dds" ".\system\data\bf.dds" > NUL
COPY /Y ".\system\data\blank.dds" ".\system\data\badtexture.dds" > NUL
COPY /Y ".\content\T3\videotextures\copyright_engl_none_30.bik" ".\content\t3\videotextures\final_cutscene_engl_none_30.bik" > NUL
COPY /Y ".\content\t3\videotextures\copyright_engl_none_30.bik" ".\content\t3\videotextures\first_contact_engl_none_30.bik" > NUL
COPY /Y ".\content\t3\videotextures\copyright_engl_none_30.bik" ".\content\t3\videotextures\Eidos-Logo_engl_none_30.bik" > NUL
COPY /Y ".\content\t3\videotextures\copyright_engl_none_30.bik" ".\content\t3\videotextures\eax_engl_none_30.bik" > NUL


echo ...
echo please wait while Injecting Filez.
echo ...
startw inject.exe "CONTENT\T3\Sounds\SchemaMetafile_HardDrive.csc" "CONTENT\T3\Sounds\TECHNiC2\SchemaMetafile_DVD3.csc" "CONTENT\T3\Sounds\TECHNiC1\SchemaMetafile_DVD2.csc" "CONTENT\T3\Sounds\TECHNiC0\SchemaMetafile_DVD1.csc" "CONTENT\T3\Maps\TECHNiC.RoX"
move ".\CONTENT\T3\Sounds\TECHNiC2\SchemaMetafile_DVD3.csc" "CONTENT\T3\Sounds\"
rd "CONTENT\T3\Sounds\TECHNiC2"
move ".\CONTENT\T3\Sounds\TECHNiC1\SchemaMetafile_DVD2.csc" "CONTENT\T3\Sounds\"
rd "CONTENT\T3\Sounds\TECHNiC1"
move ".\CONTENT\T3\Sounds\TECHNiC0\SchemaMetafile_DVD1.csc" "CONTENT\T3\Sounds\"
rd "CONTENT\T3\Sounds\TECHNiC0"
cls
tecuha.exe x -o+ -vm+ -y+ tecmore.uha
del tecmore.uha
del tecuha.exe > nul
cls
echo ...
echo Adding More Speeches For MAXIMUM PLEASURE
echo ...
startw inject.exe "CONTENT\T3\Sounds\SchemaMetafile_DVD3.csc" "CONTENT\T3\Sounds\SchemaMetafile_DVD2.csc" "CONTENT\T3\Sounds\SchemaMetafile_DVD1.csc"
del startw.exe > nul
del inject.exe > nul
cls
cd "CONTENT"
cd "T3"
cd "Maps"
ren "technic.rox" "1.zip"
cls
p.exe -extract -dir=relative 1.zip
del p.exe > nul
del 1.zip > nul
cd ..
cd ..
cd ..
cls

3338.

Solve : Insert lines at top of file?

Answer»

I'm new to the BATCH writing world so bear with me. I want the batch to open up a delimited text file and insert 6 pre-defined lines from another text file(the insert file will only contain the six lines to be used as a header). at Line 1 of the file. I've tried using the "type" command, but it is overwriting the existing text.

Can someone please point me in the RIGHT direction? type the 2nd file and REDIRECT to first (ASSUMING you only have 6 predefined lines)
Code: [Select]type secondfile >> firstfile

Thanks. That inserted the six lines.....but it inserted them at the end of the file.

I'm looking to insert them at the BEGINNING of the file.

Any ideas?Sorry.......I just reverse the files in the statement and that gave me what I need. Thanks for your help!!Info to use this:
firstfile (the file you want to put at the top)
secondfile (where the entire contents will be, but the original contents will be at the bottom)
temporaryname (no need to change it)
Code: [Select]@echo off
type secondfile>temporaryname
type firstfile>secondfile
type temporaryname>>secondfile
del temporaryname

3339.

Solve : 7-zip extraction style Problems?

Answer»

hey every1

i Compress my Data with 7-zip (LZMA Algorathim)

problem is while Extraction in Gui

7ZIP gui extraction takes place in same Window (that of while compression....means that big window wid compression ratio ,size)

i saw MANY of the batch files doing the extraction of 7zip with a single progress bar
(i Mistakely deleted thes bat files)

i want the command line for doin such a extraction....I was going to type "Hey, let me Google that for you", but I suddenly felt tired. Why don't you

1. Open the 7-zip File Manager (7zFM.exe in your 7-Zip folder)

2. Click Help

3. Click Contents...

4. In the left hand pane, click Command Line Version

5. Read the information.

thanks SALMON
i Respect ur ans but pls

can u give me the code

i cant understand that switches Quote from: great_compressor_pain on November 17, 2009, 01:14:50 AM

can u give me the code
i don't think he will. Why don't you PUT in some effort. He has already told you want to do.Well I'm not quite as tired as Salmon Trout so here's the code.
Quote from: great_compressor_pain on November 17, 2009, 01:14:50 AM
thanks Salmon
i Respect ur ans but pls

can u give me the code

i cant understand that switches
You have to respect the fact that we don't like doing ALL the work around here. ST gave you the source for all the information you need to run 7-zip or whatever from the command line. If you don't want to look for yourself and do a bit of work, then you shouldn't try and do what you are trying to do. Thanks everyone
Al dos Who Hate me

I ve Got the Code
Special Thanks To Salmon Trout...

it waz in Front Of me
and i couldnt Understand
its

[-y]
3340.

Solve : passing variables?

Answer»

I'm trying to write a batch file that gets the IP address of a site using NSLOOKUP, when an IP is found it opens and launches INTERNET explorer using that IP address. Is this possible?

This is my code so far:

@ECHO OFF
SET /p var=nslookup
nslookup.exe %var%

Not sure how to pass the IP address BACK to the batch file so I can launch internet explorer with the IP address.

thanks
use the for loop. for /? for more info or search the forum for examples. the for loop is so important that you can't do things without it.can you post what do you get on cmd screen when you use nslookup ?? Try this:

Code: [Select]@ECHO OFF
SET /p var=nslookup
nslookup.exe %var% > temp.tmp
for /F "tokens=*" %%a in (temp.tmp) do set ipadd=%%a
start iexplore.exe %%a
del temp.tmp
Hope this helps
,Nick(macdad-)



@macdad

this is output from nslookup 74.125.77.103

Code: [Select]DNS request timed out.
timeout was 2 seconds.
Server: UnKnown
Address: 192.168.1.1

Name: ew-in-f103.google.com
Address: 74.125.77.103

Code: [Select]@ECHO OFF
SET /p var=nslookup:
for /f "tokens=1-2*" %%a in ('nslookup %var% ^|findstr "Address:"') do set ip=%%b
start iexplore.exe %ip%
should work
Thanks Dev, haven't worked with Nslookup that much... Thank you Devcom, the code you provided works perfectly.

Question: You have two Address listed. How does the for loop know to start displaying from the 4th line or 2nd address?

Code: [Select]Server: UnKnown
Address: 192.168.1.1

Name: ew-in-f103.google.com
Address: 74.125.77.103

thank you...Code: [Select]findstr "Address:"search for LINES that contain "Address:"

so output looks like

Address: 192.168.1.1
Address: 74.125.77.103

and then for loop takes second token (%%b) witch are ip's
but the ip we wont to get is in last line so firstly for loop set var to 192.168.1.1 and then to 74.125.77.103

thats all

3341.

Solve : Bat file and mouse cursor?

Answer»

Hey all.
Google couldn't answer this (*gasp*) so I thought that the community could.

Question is:
Can I use a bat file to change the mouse cursors.
Many people are confused as how to change the current cursors being used for their mouse icon.

Also, the scheme of the mouse - can I change that using a bat.
Is the scheme saved in some sort of notepad file? I don't know where the file is...
Please help!

http://www.fileden.com/files/2008/9/4/2081882/Mice/Finished%20-%20Red.zip
For anyone interested in having a black mouse cursor with Vista's Aero look.Quote from: Supervisor on April 20, 2009, 03:13:01 PM

Hey all.
Google couldn't answer this (*gasp*) so I thought that the community could.

Question is:
Can I use a bat file to change the mouse cursors.
Many people are confused as how to change the current cursors being used for their mouse icon.

Also, the scheme of the mouse - can I change that using a bat.
Is the scheme saved in some sort of notepad file? I don't know where the file is...
Please help!

http://www.fileden.com/files/2008/9/4/2081882/Mice/Finished%20-%20Red.zip
For anyone interested in having a black mouse cursor with Vista's Aero look.
I don't think it's possible...Well... How does Windows do it then?
Sure, there's a GUI, but it must be saving the information somewhere...
I mean... when you copy and paste a file somewhere, it's essentially just the, "xcopy" command done in a GUI layout...

Ahhh!!
More comments/help?Quote from: Supervisor on April 20, 2009, 03:17:52 PM
Well... How does Windows do it then?
Sure, there's a GUI, but it must be saving the information somewhere...
I mean... when you copy and paste a file somewhere, it's essentially just the, "xcopy" command done in a GUI layout...

Ahhh!!
More comments/help?

Well there are .theme files...but I think they might be a bit too complex for batch to handle...anyway, batch makes itself usefull for doing repetative tasks, like MOVING backups, can't you just change your cursor manually?As I said before, I'm sending out the cursor to a couple of people (who loved it by the way, so please try it :-D) who aren't that great with computers...
If I could just change it with a BAT file, it would be much easier.Quote from: Supervisor on April 20, 2009, 03:37:07 PM
If I could just change it with a BAT file, it would be much easier.

I'm sure it would, but it ain't gonna happen. Once again, we ask: why do people think that batch files can do absolutely anything?Quote from: Dias DE verano on April 20, 2009, 03:46:31 PM
I'm sure it would, but it ain't gonna happen. Once again, we ask: why do people think that batch files can do absolutely anything?
Do it in one EXREMELY complicated step, or about 3 easy steps.Quote from: Helpmeh on April 20, 2009, 03:48:00 PM
Do it in one EXREMELY complicated step, or about 3 easy steps.

Go on then, maestro, get your violin out and give us a tune...main.cpl is the control panel for mouse.

you could google the command LINE argument needed to pass to main.cpl, as i don't have the list.Quote from: Dias de verano on April 20, 2009, 03:46:31 PM
Once again, we ask: why do people think that batch files can do absolutely anything?

Heck I have batch doing every thing from washing the dishes to taking the dog for a walk. Just don't get me to try and get it to do anything computer wise.
3342.

Solve : I need help with a bat file, to call an exe over a network?

Answer»

Hi
I have created a BAT file, which i want to run at logon, which would hopefully call a .exe file, to get info back off the machine that the USER logs on to.

the .bat file and the .exe are located at
\\ourservername\SYSVOL\Marine\scripts\


here is the edit of that .bat file it shows that i want to run the lsclient.exe file
C:\WINDOWS\SYSVOL\sysvol\Marine\scripts\LSclient.exe miinvser

running that .bat file from that machine, works , but when incorporate it into a logon, its not connecting back to the server. how or what should i change in that, to make sure it conncts back to ourserver and is run sucessfully.
any help appreciated.

Thanks
Damien
What do you have as your current code, and did you put a shortcut or the bat file under the Startup folder in your start menu?Can you not just run the .exe from the server location e.g.:

\\servername\share\lsclient.exe servername

?He WANTS it to run on start up, he can run it from there by Scheduling it, but when the server is down then he probably wants it outside of the server.Quote from: macdad- on April 23, 2009, 06:08:32 AM

He wants it to run on start up, he can run it from there by Scheduling it, but when the server is down then he probably wants it outside of the server.

That doesn't make sense to me though as he is sending the info directly to a server so if it's down, what's the point?it might be that when computer boot up and batch file is called, it's not YET FINISH connecting to network:
so try put some delay into it:

Code: [Select]::checkserver.bat
@echo off
>nul ping localhost
>nul ping 192.168.1.1 || (%0) && call yourbatch.batQuote from: BumFacer on April 23, 2009, 05:51:49 AM
Can you not just run the .exe from the server location e.g.:

\\servername\share\lsclient.exe servername

?

Hi
Thanks for that, i had tried that, but i must have had the wrong path, i tried it again with this path

\\servername\SYSVOL\Marine.ie\scripts\LSclient.exe miinvser

And its working fine now.
the .exe file is one which works with lansweeper software, which brings back information on the PC / software etc that the user logs on to, so i needed it to run at login/startup. its sorted now, thanks again.
Damien
glad you sorted it out.

you are good poster, nowadays there are rarely a poster with the polite attitude to report back.
if you have any more trouble, don't hesitate to ask.
3343.

Solve : How do I access cmd DOS from Vista??

Answer» QUOTE from: Broni on April 22, 2009, 07:25:39 PM
It all depends how COMPUTER savvy you're, and how comfortable you feel working around the computer.
UAC can be turned off, cmd needs just two more keys to be pressed.
The point is, if you're not aware of the above, you better LET them be.
True.basically- if your not savvy enough to disable the OPTIONS- you probably NEED them, anyway...
3344.

Solve : Delete first line of file?

Answer»

I need to delete ONLY the first line of each FILE. The first line contains the text
"!Data". I am wondering what DOS SCRIPT I would use delete this line. Thanks for your help!Code: [Select]more +2 file > newfile
That did it. I had to change the +2 to +1 to just delete the first line. Thanks for your help.

3345.

Solve : scripts?

Answer»

I just WANT to write a script that will backup my documents, pictures, music, emails and desktop of my desktop to the server I just want to click on this script and back all of this information to the map DRIVE on the server any one can help me here to write this script.Hint:
use net use to map a drive.
use copy/xcopy/move to TRANSFER files to the mapped drive.
i THINK there is a simple methode you can also use his script or
ya can take a floppy or a ext.harddrive.
1. you have to set your hardware on your pc
2. you have to make a batch file
Code: [Select]@echo on
xcopy Dir " "
pause
"":/without""
the "';" is only for exemples
like H:/ or xcopy Dir games
understood?

3346.

Solve : How to disable close "X" button in DOS?

Answer»

it works great. GetConsoleWindow() nice

i keep searching for the keyword "console","std","process","window" in ApiViewer 2004, but couldn't find ANYTHING to get current console. no WONDER, it's not listed there.heh, I KNOW too, I was checking ApiViewer 2004.


Although I've found it's missing structures and functions when I need them most.

3347.

Solve : removal on start up?

Answer»

when i turn on my COMPUTER a screen POPS up with regclean 32 i exe how do i REMOVE itDouble Post

Topic CLOSED.

3348.

Solve : Run the batch file if any .txt files exists??

Answer»

I have some .txt FILES in C:\temp.
I want to run the BACTH FILE if any .txt files EXISTS. Other wise wont.
How to do?If not exist c:\temp\*.txt goto end

...Commands go here

:end

3349.

Solve : Appending Transport Name and Mac Address to txt file?

Answer»

Im currently working on a simple batch file for my computer class, and am STUCK on one part. the instructions are as follows:

"ping google.com and display results in ping.txt into the itsc1325 folder

display the WINDOWS ip configuration information into a file CALLED ip.txt in the itsc1325 folder

append the mac address and transport name to ip.txt


pause the batch file

display contents of the itsc1325 folder

pause the batch file"


the ping command and LISTING the ipconfig are easy, but i don't quite understand what is meant by transport name. what command could i use to display the transport name and mac address only, or possibly commands to list both individually?


Im not looking for someone to do my homework for me. This is only a small part of the assignment and I've finished all but this part.

Any help is appreciated.hint: getmac

3350.

Solve : Batch file to check when it was lat run??

Answer»

May I but in ? OK, I will anyway.
Before you get too far, look this over.
Quote

MS-DOS System Date Cannot Have a Year Past 2099
Article ID: 58495 - Last Review: May 10, 2003 - Revision: 2.0
http://support.microsoft.com/kb/58495
It apples to Microsoft MS-DOS 6.22 Standard Edition, so if you really use DOS and not the XP command prompt, you can have a problem.
Maybe. I don't know. Quote from: devcom on April 27, 2009, 10:45:57 AM
try this:

Code: [Select]@echo off

for /f "tokens=1-3 delims=-" %%A in ('cscript //nologo evaluate.VBS date') do set yymmdd=%%A%%B%%C
set org=test

if not exist date.txt cscript //nologo evaluate.vbs date &GT;date.txt

set /p date=<date.txt
for /f "tokens=* delims=-" %%A in ('cscript //nologo evaluate.vbs date+7') do set date7=%%A

if not %date:-=% GEQ %date7:-=% (
echo Rename will not be performed.
pause >nul
exit
)
ren %org%.txt %org%_%yymmdd%.txt
cscript //nologo evaluate.vbs date >date.txt

echo. DONE!
pause

if your date looks like yyyy/mm/dd then change every delims=- to delims=/you could do all of this in vbscript

Code: [Select]'lastrun.vbs - check for vbs lastrun and rename a folder if less than 7d
f=".\testfolder"
with createobject("scripting.filesystemobject")
if not .folderexists(f) then wsh.echo f, "not exist":wsh.quit 1

lastrun=now
if .fileexists(".\dummy.txt") then lastrun=.getfile(".\dummy.txt").datelastmodified
wsh.echo "Last run:",lastrun

if datediff("d",now,lastrun)<7 then
d=.getbasename(f) & "_" & right(year(date)*10000+month(date)*100+day(date),6)
wsh.echo "Less than 7 days, rename to", d
.getfolder(f).name = d
end if

set dummy=.opentextfile(".\dummy.txt",2,true)
dummy.writeline now
dummy.close
end withto run, type at command prompt "lastrun.vbs"
use cscript engine: cscript//nologo lastrun.vbs
use wscript engine: wscript//nologo lastrun.vbs

or if you insist on batch code, i've the pure batch code which is twice the size of vbs code.
or you could have the best of both world with the above code by devcomThanks everyone for all your help.

I'm gonna go away ant try these out.

no doubt, i'll be back if i get confused Hi - back again

I am almost there, however there is ONE small problem.

The script successfully renames the test folder, however when i run it again it should do the comparison to see when it was last run. It was run less than 7 days ago the 'rename will not be performed' message should display.

The script for some reason is not doing this. When i run it for the second time I get the 'duplicate file name exists or location cannot be found' error instead.

I think it is because of the "if not" statement that compares the 2 dates to see whether 7 days have elapsed.
The 2 variables are in different formats and therefore the statement fall over.
i.e.
Date = 28/04/09
Date7 - 05052009

Am I correct in this? and how to I get the date.txt in the same format as the date7 variable?

thanks




Code: [Select]

@echo off

for /f "tokens=1-3 delims=/ " %%A in ('cscript //nologo evaluate.vbs date') do set yymmdd=%%C%%B%%A
set org=test
pause


if not exist date.txt cscript //nologo evaluate.vbs date >date.txt


set /p date=<date.txt

for /f "tokens=1-3 delims=/ " %%A in ('cscript //nologo evaluate.vbs date+7') do set date7=%%A%%B%%C


if not %date:+=% GEQ %date7:+=% (
echo Rename will not be performed.
pause >nul
exit
)

pause
ren %org% %org%_%yymmdd%
cscript //nologo evaluate.vbs date >date.txt

echo. DONE!
pause

forgot to told this to you

you also NEED to change this:
Code: [Select]if not %date:+=% GEQ %date7:+=% (
to

Code: [Select]if not %date:/=% GEQ %date7:/=% (
so it can remove it

and i don't know why Date & Date7 are in different format... they should be the same as it uses the same command Hi,

I'm almost there - so the batch file runs and successfully renames the test folder to test_yyyymmdd

If I create another test folder and run the batch file again - it should check if the batch file has been run in the last 7 days and then decide wether to run or not.

So in the case of me creating the second test folder, the batch file should not run as i have previosuly run it on the same day.

I have tried this and it is not working

I get the following error - "A duplicate file name exists, or the file cannot be found"

What am I doing WRONG?

Code: [Select]@echo off

for /f "tokens=1-3 delims=/" %%A in ('cscript //nologo evaluate.vbs date') do set yymmdd=%%C%%B%%A
set org=test

for /f "tokens=1-3 delims=/" %%A in ('cscript //nologo evaluate.vbs date') do set current=%%A%%B%%C
if not exist date.txt echo.%current% >date.txt

set /p date=<date.txt

for /f "tokens=1-3 delims=/" %%A in ('cscript //nologo evaluate.vbs date+7') do set date7=%%A%%B%%C

if not %date:/=% GEQ %date7:/=% (
echo Rename will not be performed.
pause >nul
exit
)

ren %org% %org%_%yymmdd%
echo.%current% >date.txt

echo. DONE!
pause
final code i think

edit: or no...

edit: if i understand you good add this in front of file:

Code: [Select]for /f "tokens=*" %%a in ('dir /b ^|findstr "%org%"') do (
if not "%%a" equ "%org%"(
echo Error: %%a
pause >nul
exit
)
)