Microsoft Batch File (Variable filename with space in)

Posted on 2012-09-20
Last Modified: 2012-09-20
I need to get the following batch line working but I’m coming up with an issue when the files have a space in them.

for %%X in (*.7z) DO 7zg x %%X -oG:\Data\FTPTemp\sop –y

The file name is “SOP 200912.7z”

Many thanks,
Question by:merrittuk
    LVL 13

    Accepted Solution


    for %%X in (*.7z) DO 7zg x "%%X" -oG:\Data\FTPTemp\sop –y

    Open in new window

    LVL 1

    Author Closing Comment

    Hi Frank

    Got it! thank you.

    LVL 43

    Expert Comment

    by:Steve Knight
    BTW You might also want to use  "%%~X".

    The ~ removes any quotes that may be around the name as sometimes you can find a process will add "" to filenames that need them and not to others, so I always do this to get to a known state, then you add them back.

    LVL 51

    Expert Comment

    by:Bill Prew
    Now there's some great turn around, less than 3 minutes from post to an accepted solution, great work frankhelk!


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
    This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

    728 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