Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Copying files with spaces, commas, etc.

Jun
15
1
I download a lot of pictures for jigsaw puzzles. Then put a random number prefix on the file names so I can mix up groups of the same kind of picture.

For some reason I can't get files with spaces, commas and, such to copy. I've tried:

double quoting just the "%variable"
double quoting "drive\directory\%variable"

Also with single quotes and back quotes ( ` ).

If I try and move a file "test file.jp6" I get the following

TCC: (Sys) D:\tmp_y\Move_test.btm [15] The system cannot find the file specified.
"D:\tmp_y\Test"
TCC: (Sys) D:\tmp_y\Move_test.btm [15] The system cannot find the file specified.
"D:\tmp_y\File.jg6"

Here's the code:

Code:
@echo off
setlocal
:Main
    on Break goto Done
    dir /b D:\tmp_y\*.jg* > FileList.x
    setdos /x-45678
    set FileHandle=%@fileopen["FileList.x",r,t]
    set FileName=%@fileread[%FileHandle]
    set DirNum=0
    set x=0
    Do while %FileName ne **EOF**
        If %@len[%DirNum] lt 2 set DirNum=0%DirNum
        If not exist "d:\Games\BigJig\My_Jigsaws_%DirNum" md "d:\Games\BigJig\My_Jigsaws_%DirNum"
        set x=%@inc[%x]
        move /q "d:\tmp_y\%FileName" "d:\Games\BigJig\My_Jigsaws_%DirNum\"
        set FileName=%@fileread[%FileHandle]
        If %x eq 100 echo Moved to My_Jigsaws_%DirNum
        If %x eq 100 set DirNum=%@inc[%DirNum]
        If %x eq 100 set x=0
    enddo
:Done
    set FileHandle=%@fileclose[%FileHandle]
    del /q FileList.x
    endlocal
    pause
    quit

Edited code to reflect what I have done since I update to ver. 21. 2017-11-14 19:22
 
Last edited:
It looks to me like you have double-quotes within double-quotes: one from line 8 (or 16), and one from line 15. They aren't nestable. You probably want to remove the double-quotes from your @FILEREAD lines.
 
Charles, without the quote around %@fileread[%FileHandle], after giving the error from my first post, it goes in to an endless loop repeating:

TCC: (Sys) D:\tmp_y\Move_test.btm [15] The system cannot find the file specified.
"D:\tmp_y\**EOF**"

I've already tried "D:\tmp_y\"%FileName"" and gotten the same error as my first message.

If it makes a difference I'm running:

TCC 19.10.54 x64 Windows 10 [Version 6.3.16299]
TCC Build 54 Windows 10 Build 16299
 
I upgraded to:
TCC 21.01.60 x64 Windows 10 [Version 10.0.16299]
TCC Build 60 Windows 10 Build 16299

Unquoted the %@fileread[%FileHandle] and that now works.

However, I'm still getting:
TCC: (Sys) D:\tmp_y\Move_test.btm [15] The system cannot find the file specified.
"D:\tmp_y\Test"
TCC: (Sys) D:\tmp_y\Move_test.btm [15] The system cannot find the file specified.
"D:\tmp_y\File.jg6"

Updated the code in my first post.
 
I would double quote any place where you are using, not setting, Filename.......

Code:
@echo off
setlocal
:Main
    on Break goto Done
    dir /b D:\tmp_y\*.jg* > FileList.x
    setdos /x-45678
    set FileHandle=%@fileopen["FileList.x",r,t]
    set FileName=%@fileread[%FileHandle]
    set DirNum=0
    set x=0
    Do while "%FileName" ne "**EOF**"
        If %@len[%DirNum] lt 2 set DirNum=0%DirNum
        rem Below, why not use if not isdir ....?
        If not exist "d:\Games\BigJig\My_Jigsaws_%DirNum" md "d:\Games\BigJig\My_Jigsaws_%DirNum"
        set x=%@inc[%x]
        move /q "d:\tmp_y\%FileName" "d:\Games\BigJig\My_Jigsaws_%DirNum\"
        set FileName=%@fileread[%FileHandle]
        iif %x eq 100 then
            echo Moved to My_Jigsaws_%DirNum
            set DirNum=%@inc[%DirNum]
            set x=0
        endiff
    enddo
:Done
    set FileHandle=%@fileclose[%FileHandle]
    del /q FileList.x
    endlocal
    pause
    quit
 
Solved

It was the "setdos /x-45678" line. I had seen the line in a thread here concerning copying files with foreign language characters. Which I do get sometimes.
 

Similar threads

Back
Top