Solved

Years with spaces

Posted on 2011-09-02
3
264 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 53

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 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