LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2012, 06:50 PM   #1
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Rep: Reputation: 30
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\"
 
Old 07-10-2012, 07:11 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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"
 
Old 07-10-2012, 07:24 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Have a read of this.

(with thanks to @David the H.)
 
Old 07-10-2012, 07:33 PM   #4
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by syg00 View Post
Have a read of this.

(with thanks to @David the H.)
that's for the bash version i'm using dos
 
Old 07-10-2012, 09:35 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
... dos !!! Man, I can't remember the last time I wrote a bat file.
Sorry for butting in ...
 
Old 07-10-2012, 10:08 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
ahhh syg00 ... showing your age again ...lol

OP - ntubski's solution looks good
 
Old 07-10-2012, 10:09 PM   #7
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
true but i need to do this via an f loop though
 
Old 07-11-2012, 02:17 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
You can if you wish, but the point being made is that the 2 code snippets shown by ntubski do the same thing
 
Old 07-11-2012, 03:05 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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.
 
Old 07-11-2012, 08:22 AM   #10
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by grail View Post
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\"
 
Old 07-11-2012, 08:45 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Well that would be the usual story of you now adding further detail which changes the question, but now you have a working solution?
 
Old 07-11-2012, 08:48 AM   #12
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by grail View Post
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

Last edited by steve51184; 07-11-2012 at 08:49 AM.
 
Old 07-11-2012, 10:11 PM   #13
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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
 
Old 07-12-2012, 03:35 AM   #14
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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?
 
Old 07-12-2012, 07:11 AM   #15
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
damn got it all working was the error of a random extra set of quotes lol

thanks all
 
  


Reply

Tags
batch, cmd, windows



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch file conversion command? the same command on all files in a folder ? pete2222 Linux - General 6 10-02-2010 11:59 AM
Moving file which it's name contain spaces by command line??? Mr.mick-duck Linux - General 6 03-14-2009 05:30 AM
bash - replace all spaces in file, folder names babag Programming 24 04-20-2008 12:17 AM
smbfs, fstab, spaces in the folder i want to mount. Problems! JapanFred Linux - Networking 1 12-29-2005 03:27 PM
Spaces in folder/file names ~ termial Garoth Linux - Software 1 11-12-2004 01:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration