Solved

Years with spaces

Posted on 2011-09-02
3
261 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 83

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 51

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now