Page 1 of 1

Syntax Problem - moving files in subdirs with white space in filename

Posted: 14 Mar 2019 13:37
by kindly_confused
Hi,

I want to sort my .jpg files by time of day - I found that the filename contains the hour of the day at which it was taken - time corresponds to a digit preceded by a white space - only white space in the filename.

This command works to list the specific files in question:

Code: Select all

dir /s E:\photos\"* 19*".jpg
The white space is before the 19.

Trying to get this to work in conjunction with move or copy does not work.

Code: Select all


for /F %i in ('command to get files list') do command %i

for /f %i in ('dir E:\photos\"* 19*".jpg') do move E:\ %i

Any suggestions would be great.

I want to put this code into a batch file so I can sort my photos by time of day.

Re: Syntax Problem - moving files in subdirs with white space in filename

Posted: 14 Mar 2019 14:37
by aGerman
untested

Code: Select all

for /f "delims=" %%i in ('dir "E:\photos\* 19*.jpg"') do move "%%i"  "E:\your destination folder\"
In a batch script percent signs of FOR variables have to be doubled. The space is one of the default delimiters in a FOR loop which means that you have to override this behavior by defining "delims=". The file names in the FOR variable still contain the space and thus, the variable has to be quoted,

But ... why don't you just use wildcards in the move command?

Code: Select all

move "E:\photos\* 19*.jpg" "E:\your destination folder\"
Steffen

Re: Syntax Problem - moving files in subdirs with white space in filename

Posted: 14 Mar 2019 17:25
by kindly_confused
Thanks Steffen

Second option works.

First option has a syntax problem - I had issues myself dealing with delim...

Any other suggestions for using a for loop?

I have implemented the move command in my batch file - works very well.

Re: Syntax Problem - moving files in subdirs with white space in filename

Posted: 14 Mar 2019 18:11
by Squashman

Code: Select all

for %%i in ("E:\photos\* 19*.jpg") do move "%%i"  "E:\your destination folder\"

Re: Syntax Problem - moving files in subdirs with white space in filename

Posted: 14 Mar 2019 20:03
by kindly_confused
Problem, I celebrated too soon.

I wasn't clear enough - I need to scan sub-folders.

For loops are giving me a headache - already took two Tylenols this afternoon

As I stated:

This command works to list the specific files in question - IT SCANS SUB-FOLDERS:

[SCANNING SUB-FOLDERS WORKS!]

Code: Select all

dir /s E:\photos\"* 19*".jpg
The white space is before the 19.

Trying to get this to work in conjunction with move or copy does not work.

[DOESN'T WORK AND DOESN'T SCAN SUB-FOLDERS]

Code: Select all


for /F %i in ('command to get files list') do command %i

for /f %i in ('dir E:\photos\"* 19*".jpg') do move E:\ %i

I need a means of scanning sub-folders for a string containing a white space and then moving (or copying) the files to another folder.

I have several network drives mapped to ntfs folders.

Big thanks.

Re: Syntax Problem - moving files in subdirs with white space in filename

Posted: 14 Mar 2019 21:14
by Squashman

Code: Select all

for /R "E:\photos" %%i in ("* 19*.jpg") do move "%%i"  "E:\your destination folder\"