LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   having problems with spaces in file/folder name with 'for' command (https://www.linuxquestions.org/questions/programming-9/having-problems-with-spaces-in-file-folder-name-with-for-command-4175415994/)

steve51184 07-10-2012 06:50 PM

having problems with spaces in file/folder name with 'for' command
 
hi all i'm trying to use the 'for' command along with 'move' to help move all .rar files from one folder to another but some files have spaces and don't get moved as the spaces break the script

i've tried adding " to the folder path but that didn't work any ideas?

this is what i have so far:

Code:

for /F %%f in ("F:\old\*.rar") do move "%%f" "F:\new\"

ntubski 07-10-2012 07:11 PM

The /F option doesn't accept wildcards, and you shouldn't quote wildcards:
Code:

for %%f in (F:\old\*.rar) do move "%%f" "F:\new\"
Even simpler:
Code:

move F:\old\*.rar "F:\new"

syg00 07-10-2012 07:24 PM

Have a read of this.

(with thanks to @David the H.)

steve51184 07-10-2012 07:33 PM

Quote:

Originally Posted by syg00 (Post 4724433)
Have a read of this.

(with thanks to @David the H.)

that's for the bash version i'm using dos :p

syg00 07-10-2012 09:35 PM

:doh: ... dos !!! Man, I can't remember the last time I wrote a bat file.
Sorry for butting in ... :p

grail 07-10-2012 10:08 PM

ahhh syg00 ... showing your age again ...lol

OP - ntubski's solution looks good :)

steve51184 07-10-2012 10:09 PM

true but i need to do this via an f loop though

grail 07-11-2012 02:17 AM

You can if you wish, but the point being made is that the 2 code snippets shown by ntubski do the same thing :)

bigearsbilly 07-11-2012 03:05 AM

You should try http://www.4dos.info/

I used to use it back in the day!

We used to leave our doors unlocked, and it was sunny.

steve51184 07-11-2012 08:22 AM

Quote:

Originally Posted by grail (Post 4724658)
You can if you wish, but the point being made is that the 2 code snippets shown by ntubski do the same thing :)

but again i need the f loop... here's the full command i use:

Code:

for %%f in ("F:\old\*.rar") do if %%~zf lss 680525824 move "%%f" "F:\new\"

grail 07-11-2012 08:45 AM

Well that would be the usual story of you now adding further detail which changes the question, but now you have a working solution?

steve51184 07-11-2012 08:48 AM

Quote:

Originally Posted by grail (Post 4724991)
Well that would be the usual story of you now adding further detail which changes the question, but now you have a working solution?

no no working solution yet.. that command still fails with spaces in the name i just posted my full command as others were suggesting to just use the 'move' command :(

ntubski 07-11-2012 10:11 PM

Hmm, works for me:
Code:

C:\>dir C:\temp\old

 Directory of C:\temp\old

11/07/2012  11:03 PM    <DIR>          .
11/07/2012  11:03 PM    <DIR>          ..
10/07/2012  08:03 PM                0 has spaces.rar
10/07/2012  08:05 PM                0 nospace.rar
11/07/2012  10:59 PM                17 space non empty.rar
              3 File(s)            17 bytes
              2 Dir(s)  222,495,064,064 bytes free

C:\>for %f in ("C:\temp\old\*.rar") do @if %~zf lss 10 move "%f" "C:\temp\new\"
        1 file(s) moved.
        1 file(s) moved.

C:\>dir C:\temp\new

 Directory of C:\temp\new

11/07/2012  11:04 PM    <DIR>          .
11/07/2012  11:04 PM    <DIR>          ..
10/07/2012  08:03 PM                0 has spaces.rar
10/07/2012  08:05 PM                0 nospace.rar
              2 File(s)              0 bytes
              2 Dir(s)  222,495,064,064 bytes free


grail 07-12-2012 03:35 AM

Not having played with batch files for a while, much like syg00, I would point out that ntubski is using single % signs and has an @ in front of if.
Maybe these are the missing items?

steve51184 07-12-2012 07:11 AM

damn got it all working was the error of a random extra set of quotes lol

thanks all :)


All times are GMT -5. The time now is 10:17 PM.