LinuxQuestions.org
Review your favorite Linux distribution.
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, 07:50 PM   #1
steve51184
Member
 
Registered: Dec 2006
Posts: 372

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, 08:11 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,542

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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, 08:24 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,497

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

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

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, 10:35 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,497

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

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

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

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

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
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, 04:05 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
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, 09:22 AM   #10
steve51184
Member
 
Registered: Dec 2006
Posts: 372

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, 09:45 AM   #11
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
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, 09:48 AM   #12
steve51184
Member
 
Registered: Dec 2006
Posts: 372

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 09:49 AM.
 
Old 07-11-2012, 11:11 PM   #13
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,542

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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, 04:35 AM   #14
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
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, 08:11 AM   #15
steve51184
Member
 
Registered: Dec 2006
Posts: 372

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:59 PM
Moving file which it's name contain spaces by command line??? Mr.mick-duck Linux - General 6 03-14-2009 06:30 AM
bash - replace all spaces in file, folder names babag Programming 24 04-20-2008 01:17 AM
smbfs, fstab, spaces in the folder i want to mount. Problems! JapanFred Linux - Networking 1 12-29-2005 04:27 PM
Spaces in folder/file names ~ termial Garoth Linux - Software 1 11-12-2004 02:56 PM


All times are GMT -5. The time now is 03:18 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration