Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 12 total  RSS 

Batch loop for wave to mp3 (using lame)

It keeps the input files and sorts both mp3 and wave files nicely in two separate directories.
@echo off
if NOT EXIST MP3 md MP3
if NOT EXIST WAV md WAV

for %%f in (*.wav) do (
	cls
	lame -b 96 -V 5 -B 128 -m j --vbr-new -q 5 "%%f" "MP3\%%f.mp3"
	move "%%f" WAV
)

Batch re-size a collection of images from the command line

for img in $(ls *.png); do convert $img -resize 75% smaller-$img; done;

find line in text file, add to another text file

// Batch - search .txt / .csv / etc using argument, return matches to .txt / .csv / etc file
// skips the ---------- foo.csv returned by find alone
find /i "%1" foo.csv | find /i "%1" >> bar.txt

Batch code to make win folder hidden and password protected

Open any text editor and copy the the contents of this code to a text file and save it with any name having .bat extension.

cls
@ECHO OFF
echo 			// Check1 (In Main Function)
title Folder LockFolder
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLockFolder
if NOT EXIST LockFolder goto MDLockFolder
:AuthConfirm
echo Are you sure u want to Lock Folder  (Y/N)
set/p "cho=>"
if %cho%==Y goto LockFolder
if %cho%==y goto LockFolder
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto AuthConfirm
:LockFolder
ren LockFolder "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder LockFolder Locked!
goto End
:UNLockFolder
echo Enter password to Unlock Folder
set/p "pass=>"
if NOT %pass%==TYPE YOUR PASSWORD HERE goto FailUnlock
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" LockFolder
echo Folder UnLocked successfully!
goto End
:FailUnlock
echo Invalid password!
echo Try again?  (Y/N)
set/p "choice=>"
if %choice%==Y goto UNLockFolder
if %choice%==y goto UNLockFolder
if %choice%==N goto END
if %choice%==n goto END
:MDLockFolder
echo 			// Check2 (In MD Dir Function)
md LockFolder
echo Folder LockFolder created successfully!
goto End
:End

Opera Syncing using Svn

This batch file allows to run opera after checking out your web-based opera profile. When you terminate your opera session, the batch will commit the changes you made to your profile during the opera session.

 REM OperaSync.bat
 @echo off
 
 set PRG=Opera
 set TARGET=%APPDATA%/%PRG%/%PRG%/profile
 set EXEC=%PROGS%/%PRG%/%PRG%.exe
 set REPO=https://********.googlecode.com/svn/trunk/%PROG%Sync
 set USER=*************
 
 echo Checking out from %REPO% ...
 svn checkout %REPO% "%TARGET%" --username %USER%
 echo %PROG% running ...
 %EXEC%
 echo Commiting to %REPO% ...
 svn commit -m --force-log "%TARGET%"
 echo Done.
 
 @echo on


Here's the list of files that I update from a svn repo for my Opera profile
contacts.adr
files.txt
jscripts/
jscripts/deliciousmp3.js
notes.adr
opcacrt6.dat
opcert6.dat
opera6.adr
search.ini
sessions/
sessions/autosave.win
sessions/autosave.win.bak
speeddial.ini

batch set day / date / time variables

// set day / day / time variables in batch
cd %temp%
echo.|date>datevar.bat
echo.|time>timevar.bat
echo set DATEvar=%%4>current.bat
call datevar
echo set DAYvar=%%3>current.bat
call datevar
echo set TIMEvar=%%3>current.bat
call timevar
echo %DAYvar%
echo %DATEvar%
echo %TIMEvar%

basic batch drive presence check

// check if removable drives are present. useful with batch backups and letter-jumping flash drives.
// floppies (a:, b:) can cause screen flash asking for floppy to be inserted.
//
// two batch files required - 1. foo.bat
@echo off
echo simple drive check > %temp%\tmp.txt
echo. >> %temp%\tmp.txt
for %%a in (c:, d:, e:, f:, g:) do call bar.bat %%a
cls
type %temp%\tmp.txt
echo.

// 2. bar.bat
%comspec% /f /c vol %1 | find /c "Vol" | choice /c:210
if not errorlevel 2 if errorlevel 1 echo %1 present >> %temp%\tmp.txt
if not errorlevel 3 if errorlevel 2 echo %1 not present >> %temp%\tmp.txt

// screen output can be suppressed by wrapping
ctty nul
for %%a in (c:, d:, e:, f:, g:) do call bar.bat %%a
ctty con

// in foo.bat

basic batch conditional evaluation

// check if argument has been passed to batch file

if not [%1]==[] echo %1
if not [%1]'==' echo %1

MySql Backups Under Windows

This batch script will backup any MySql database on the local machine, including all routines (stored procedures and functions), to a file named after the database followed by the date (YYYY-MM-DD) and time (HHMMSSSS). The first argument is the database name, second is the username to run the backup as and third is the password.

This script requires your date and time formats to be the windows default formats. Changing them can break this script. The script pauses at the end to cause a cmd window to remain open for long enough for the user to read the output.

@echo off
echo Starting Backup of Database: %1

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dt=%%c-%%a-%%b)
For /f "tokens=1-4 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b%%c%%d)
set bkupfilename=%1 %dt% %tm%.bak
echo Backing up to file: %bkupfilename%

mysqldump %1 --routines -u %2 -p%3 > "%bkupfilename%"

echo Backup Complete!
pause
echo on


--
Version 0.1.0 - 2006-03-13
STEM: The STEM Cells of PHP
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License
http://creativecommons.org/licenses/by-sa/2.5/

One-click connect from cygwin to full-screen Linux (X stuff required)

Optional: execute the following once (see http://hacks.oreilly.com/pub/h/66 for
details), to avoid typing in the password.

set LINUX_HOST=mylinuxhost
ssh-keygen -t rsa
ssh %USERNAME%@%LINUX_HOST% "mkdir .ssh; chmod 0700 .ssh"
bash -c 'scp ~/.ssh/id_rsa.pub %LINUX_HOST%:.ssh/authorized_keys2'


Now, if you save the following as a BATCH file, you can just click it
to connect to fullscreen Linux:

set LINUX_HOST=mylinuxhost
start /min xinit 
xhost +%LINUX_HOST%
ssh %LINUX_HOST% "declare -x DISPLAY=%COMPUTERNAME%:0; echo $DISPLAY;gnome-session"'


NOTES:
1.
Sometimes xhost + does not execute in time. O well. Just close
all windows that got opened and try again.

2.
If you didn't do the step one (ssh keys), you will be prompted
to enter the linux password; this increases the chances of the above
error.

3.
The single terminal window appearing in the Linux desktop is in fact
a window from your PC.

« Newer Snippets
Older Snippets »
Showing 1-10 of 12 total  RSS