Microsoft Batch File (Variable filename with space in)

Posted on 2012-09-20
Medium Priority
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:Glyn Merritt
LVL 14

Accepted Solution

frankhelk earned 1000 total points
ID: 38418320

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

Open in new window


Author Closing Comment

by:Glyn Merritt
ID: 38418338
Hi Frank

Got it! thank you.

LVL 43

Expert Comment

by:Steve Knight
ID: 38418429
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 59

Expert Comment

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


Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

850 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