I am trying to batch extract some rar's that are in some zip in some directories. Long story short this is my loop through the rar files:
for %%r in (*.rar) do (
unrar x %%r
)
Problem is that %%r gets the wrong value. If the files name is "file name.rar" then %%r gets the value "file" - it stops at the first space in the file name.
How do I get this loop to work file files with spaces in names?
Thank you
-
unrar x "%%r"
-
The problem is that 'for' uses space as the default delimited. You can set this using the delims = xxx. look here for syntax. Or you can use ForFiles.
Joey : cmd is also not a UNIX shell which does globbing wherever it sees an asterisk. For every rar file you will have its filename completely contained in %%r, regardless of it having spaces or not. -
Try this:
for /f "usebackq delims==" %i in (`dir /b *.rar`) do unrar x "%i"
If you are using it in a batch file, remember you will need to double the percent signs to escape them.
Bojan : Thank you very much. -
%%r
will contain the complete file name including spaces. It's your call tounrar
which has the problem. If the file name contains spaces you have to enclose it in quotation marks, otherwiseunrar
won't be able to see that the two (space-separated) parametersfile
andname.rar
are actually a single filename with a space.So the following will work:
for %%r in (*.rar) do unrar "%%r"
Also, if you aer curious where the problem lies, it's sometimes very helpful to simply replace the program call with echo:
for %%r in (*.rar) do @echo %%r
where you will see that %%r includes the spaces in file names and doesn't rip them apart.
Bojan : I thought of that, but it still wouldn't work like that. It seams that %%r really had a wrong value and quotes would do much. Maybe I got something else wrong... I don't know.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.