Computer Hope

Microsoft => Microsoft DOS => Topic started by: jofspades on June 06, 2013, 02:40:53 PM

Title: Things to Program
Post by: jofspades on June 06, 2013, 02:40:53 PM
I got bored, and ran out of ideas for batch files.
Ideas? Anyone?
Title: Re: Things to Program
Post by: Squashman on June 06, 2013, 02:51:59 PM
Sure.  See if you can adapt the Vincenty formula into batch.
Title: Re: Things to Program
Post by: patio on June 06, 2013, 03:12:14 PM
Have Fun... (http://www.wired.com/threatlevel/2013/06/analyst-who-cracked-kryptos/)
Title: Re: Things to Program
Post by: Salmon Trout on June 06, 2013, 03:53:19 PM
Add every file in a folder to a Zip archive.
Delete every file in a folder tree more than 5 days old.
(Probably easier in VBscript) find the square root of a number by Newton's method.
Shutdown the computer.
Reboot the computer.
Create 100 text files each one 1000 bytes in size with consecutively numbered names in the format text0001.txt text0002.txt etc


Title: Re: Things to Program
Post by: Lemonilla on June 06, 2013, 06:32:31 PM
Write a secure password input system. (Harder than you would think)
Title: Re: Things to Program
Post by: Lemonilla on June 06, 2013, 07:42:35 PM
a script to create a graph.
Title: Re: Things to Program
Post by: Ocalabob on June 06, 2013, 09:08:36 PM
Delete every file in a folder tree more than 5 days old.
Create 100 text files each one 1000 bytes in size with consecutively numbered names in the format text0001.txt text0002.txt etc
Greetings Salmon Trout,
I liked the two above. Gave them a 'go'  just for fun. For your consideration:

Delete every file:
Code: [Select]
@echo off
Robocopy C:\my_folder c:\my_del_folder /e /mov /minage:5
RD /s /q C:\my_del_folder
Create files: (ham fisted approach)
Code: [Select]
@echo off
Setlocal

call :make_file
:start
set /a #=#+1
set num=0000%#%

for /l %%b in (1,1,100) do (
type 1000.txt>text000%%b.txt
if %%b==100 goto :EOF
)

:make_file
for /l %%b in (1,1,25) do (
echo "999999999999999999999999999999999999">>1000.txt
if %%b==25 goto :start
)

They worked for me using WIN 7. I did limited testing.

Thoughts?



Title: Re: Things to Program
Post by: foxidrive on June 06, 2013, 11:49:15 PM
I used your methods in this modification Ocalabob
I think this format of filename was meant. 

We should have contests on a task to see who's is smallest in bytes, or fastest, or most easily read etc. :)

Code: [Select]
@echo off

set c=10000
for /l %%b in (1,1,40) do (
>>tmp echo 12345678901234567890123
)

:loop
set /a c=c+1
set num=%c:~-4%
type tmp>text%num%.txt
if %c% LSS 10100 goto :loop
del tmp
Title: Re: Things to Program
Post by: Ocalabob on June 07, 2013, 05:36:15 AM
@foxidrive
I tested your script. That's good work! Hat tip. :)

Now what about "Delete every file in a folder tree more than 5 days old."
Title: Re: Things to Program
Post by: Squashman on June 07, 2013, 06:41:36 AM
fsutil file createnew C:\testfile.txt 1000
Title: Re: Things to Program
Post by: Sidewinder on June 07, 2013, 07:26:51 AM
Quote
Now what about "Delete every file in a folder tree more than 5 days old."

Code: [Select]
forfiles /p c:\testfolder /s /d -5 /m *.* /c "cmd /c echo @PATH"

The echo command can be replaced with the del command. Use forfiles /? for more info.

 8)
Title: Re: Things to Program
Post by: foxidrive on June 07, 2013, 09:37:27 AM
Now what about "Delete every file in a folder tree more than 5 days old."

You and Sidewinder have that sewn up. :)
Title: Re: Things to Program
Post by: Salmon Trout on June 09, 2013, 01:53:46 PM
(Probably easier in VBscript) find the square root of a number by Newton's method.

' sqr (N) is approx equ to 0.5 * (N/A + A)
N = wscript.arguments(0)
A = 1
D = 1
Do Until D = 0
    C = (N/A + A) / 2
    D = A - C
    A = C
Loop
wscript.echo "Square root of " & N & " = " & C


This can be done in batch...

Title: Re: Things to Program
Post by: Ocalabob on June 14, 2013, 07:08:23 PM
@Salmon Trout
Quote
Reboot the computer.

Batch file using WIN 7.

Code: [Select]
C:\"Program Files (x86)"\O2Micro\Oz600\Devcon Reboot
foxidrive? :)
Title: Re: Things to Program
Post by: patio on June 14, 2013, 07:27:29 PM
HuH ? ?
Title: Re: Things to Program
Post by: Ocalabob on June 14, 2013, 07:50:05 PM
Maybe I was too brief. :)

Code: [Select]
::Devcon_Reboot.bat
::@echo off
C:\"Program Files (x86)"\O2Micro\Oz600\Devcon Reboot
Title: Re: Things to Program
Post by: Lemonilla on June 14, 2013, 08:38:44 PM
Code: [Select]
shutdown /r

Code: [Select]
REM this one saves your applications
shutdown /g
Title: Re: Things to Program
Post by: Ocalabob on June 14, 2013, 09:09:17 PM
@Lemonilla
I was trying for something more esoteric just for fun. Your solutions are more 'real world'. Hat tip! :)
Title: Re: Things to Program
Post by: Salmon Trout on June 14, 2013, 11:26:47 PM
@Salmon Trout
Batch file using WIN 7.

Code: [Select]
C:\"Program Files (x86)"\O2Micro\Oz600\Devcon Reboot
foxidrive? :)

Devcon is a Microsoft command line utility that is not a standard part of Windows; you have to download it. It is a developer tool, a command line equivalent of Device Manager, and I should think that used carelessly by someone with little knowledge or sense of responsibility it could seriously disrupt a computer. However you can reboot the computer with no need for extras in one line like this:

Code: [Select]
@shutdown /r /t X
where X is the number of seconds you want to wait before rebooting, 0 (zero) being immediately.
Title: Re: Things to Program
Post by: foxidrive on June 15, 2013, 04:10:58 AM
beaten by page 2 :)
Title: Re: Things to Program
Post by: Squashman on June 15, 2013, 05:15:19 AM
@Salmon Trout
Batch file using WIN 7.

Code: [Select]
C:\"Program Files (x86)"\O2Micro\Oz600\Devcon Reboot
foxidrive? :)
Why wouldn't you just use the SHUTDOWN command.
Title: Re: Things to Program
Post by: Salmon Trout on June 15, 2013, 05:43:05 AM
Why wouldn't you just use the SHUTDOWN command.

Welcome to the chorus...
Title: Re: Things to Program
Post by: foxidrive on June 15, 2013, 07:56:37 AM
Code: [Select]
::Devcon.exe from microsoft
@echo off
Devcon Reboot

There wouldn't have been any comment if the path wasn't there and the point it was from Microsoft was made. :)

After all, this thread is about figuring out different ways to write batch files... :)