Solved

Years with spaces

Posted on 2011-09-02
3
266 Views
Last Modified: 2012-05-12
Not sure if this is the right zone, apoligise if it isnt.

Ive written a quick batch file to backup some mysql databases, but put the date at the end of the file, so Ive got:-
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @( 
    Set Day=%%A
    Set Month=%%B
    Set Year=%%C   
)    
g:\xampplite\mysql\bin\mysqldump -h 192.168.1.105 -u myUser -pmyPass myDB >"c:\Backups\myDB_%Year%-%Month%-%Day%.sql"

Open in new window


The backup works great but the filename is  c:\Backups\myDB_2011   -09-02.sql

On a quick look the value Year is "2011   ".

Is there anyway to trim the spaces from the value?

Thank you
0
Comment
Question by:tonelm54
3 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 36472559
If you did a copy and paste from your script, you simply have some spaces after "Set Year=%%C" (select the line, and you'll see it).
0
 

Author Closing Comment

by:tonelm54
ID: 36472563
:-) Simple, thank you
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36472705
And just to add on slightly. one way to avoid this problem that BAT scripts can suffer from is to use quotes around the set, so that even if there are trailing blanks they won't be assigned to the variable, like:

    Set "Day=%%A"
    Set "Month=%%B"
    Set "Year=%%C"

Open in new window

~bp
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question