Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Years with spaces

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
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…

808 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