Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Years with spaces

Posted on 2011-09-02
3
Medium Priority
?
271 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 85

Accepted Solution

by:
oBdA earned 2000 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 59

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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…
Suggested Courses

824 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