Tag Archive for scripting

DOS Batch – Date Folder Reverse

Date Directory RenameI came across a very irritating issue today. When doing an import of HD videos using Panasonic’s HD Writer AE, it automatically puts all the files into folders named with a format DD-MM-YYYY (47 of them!).

This would all be fine if Windows realised this was a date, instead of sorting into order by the DD first, but it doesnt. I wasnt about to go through and manually rename all the directories to YYYY-MM-DD so they would sort correcty, so I wrote a quick batch file to do it, and thought it may be of use to some people.

Copy the below into a text file, edit the year (currently 2010) as required, rename to .bat and drop it into the root folder you want to rename the other directories from, then simply double click!

@echo off
@echo This batch file will reverse date formats for any folders in the current dir from DD-MM-YYYY to YYYY-MM-DD
pause

for /D %%i in (*-*-2010) do (
 call :renamer %%i
 )
pause

goto :EOF

:renamer
set var=%1
ren %1 2010-%var:~3,2%-%var:~0,2%

Post to Twitter Post to Facebook Post to Delicious Post to Digg Post to LinkedIn Post to Reddit Post to StumbleUpon

MySQL Tips

The following is simply a gathering of easy hints, tips and scripts for MySQL beginners (and a memory aid for me!):

 

Useful MySQL queries

 

List all your databases and their total sizes

SELECT table_schema “Database Name”, sum( data_length + index_length ) / 1024 / 1024 “Database Size in MB”

FROM information_schema.TABLES GROUP BY table_schema ;

 

List all your tables in a specific database and their total sizes

SELECT table_schema “Database Name”,
table_name “Table Name”,
sum( data_length + index_length ) / 1024 / 1024 “Table Size in MB”
FROM information_schema.TABLES
WHERE table_schema like “[insertyourdatabasenamehere]
GROUP BY table_name
ORDER BY table_schema,table_name;

 

Dump a database contents out to a gzipped file and skip certain tables

mysqldump -u[username] -p [databasename] –ignore-table=[insertyourdatabasenamehere].[tabletoignore1]

–ignore-table=
[insertyourdatabasenamehere] .
[tabletoignore2] | gzip -c > sqlfile.sql.gz

 

Run an SQL script file against a database

mysql -u[username] -p [databasename] < sqlfile.sql

 

Easy!

Post to Twitter Post to Facebook Post to Delicious Post to Digg Post to LinkedIn Post to Reddit Post to StumbleUpon

Stop censorship