Page 1 of 1

Batch script to copy 0 byte and non 0 byte to another dir

Posted: 27 Nov 2014 14:04
by bhas85
I tried to find the solution but no luck.Could some one please provide me the batch script for the below one.
In a directory i had 3 types of files which need to move to another directory.
1) .RAW and .XML files if they are zero they need to move
2) Any file without any extension i.e normal file need to me moved whether it is zero or non zero.

Thanks in advance.

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 27 Nov 2014 15:04
by Yury

Code: Select all

@echo off

set "from=D:\Test 2"
set "to=D:\Test 1"
set masks_1=*.RAW *.XML
set masks_2=*.

pushd "%from%"
for /f "tokens=1*" %%i in ('robocopy . %random% %masks_1% /nc /ndl /njh /njs /l') do if %%i==0 >nul move /y "%%j" "%to%"
for /f "delims=" %%i in ('dir /a-d/b %masks_2%') do>nul move /y "%%i" "%to%"
popd

exit /b 0

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 04 Dec 2014 12:07
by bhas85
Hi Yuri,
Thanks a lot for your script.I had one question if the file is `text1` i.e without any extension.Not sure the below intilisation will work or not.Please explain me on this concept to move the file to different directoty.

set masks_2=*.

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 05 Dec 2014 16:48
by bhas85
Hi Yuri,

Thanks a lot for your reply.I had some queries please explain me.I didn't understand the below one.For example i had file names 'file1,file2 etc which are zero or non zero'.Could you please explain me how the below intilisation will work.

Code: Select all

set masks_2=*.

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 08 Dec 2014 05:11
by foxidrive
bhas85 wrote:I had one question if the file is `text1` i.e without any extension.Not sure the below intilisation will work or not.


You can try the script in a test folder. What happened to the files in the folder when you ran this?

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 08 Dec 2014 12:41
by bhas85
Hi Foxidrive,

When i tried to test the script.It says file not found.

@echo off

set "from=U:\vijay1"
set "to=U:\vijay2"
set masks_1=*.raw *.xml
set masks_2=*.

pushd "%from%"
for /f "tokens=1*" %%i in ('robocopy . %random% %masks_1% /nc /ndl /njh /njs /l') do if %%i==0 >nul move /y "%%j" "%to%"
for /f "delims=" %%i in ('dir /a-d/b %masks_2%') do>nul move /y "%%i" "%to%"
popd

pause


o/p

Code: Select all

'\\cifs.flnas.info53.com\home'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
File Not Found
Press any key to continue . . .


Please let me know what's wrong here.I need to move all file type as file to "TO" Folder as well.

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 08 Dec 2014 22:02
by josephf
Is U:\ a network drive?

If it is you have to map it sometimes.

Code: Select all

net use U: \\     
REM ^<^<^< Your drives network computer name should be put after the \\

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 09 Dec 2014 11:33
by bhas85
Hi Joesphf,

I changed the drive but still i am seeing file not found error.Could you please help me what exactly do i need to change.

Code: Select all

@echo off

set "from=C:\batch\vijay1"
set "to=C:\batch\vijay2"
set masks_1=*.raw *.xml
set masks_2=*.

pushd "%from%"
for /f "tokens=1*" %%i in ('robocopy . %random% %masks_1% /nc /ndl /njh /njs /l') do if %%i==0 >nul move /y "%%j" "%to%"
for /f "delims=" %%i in ('dir /a-d/b %masks_2%') do>nul move /y "%%i" "%to%"
popd

pause


error:

Code: Select all

File Not Found
Press any key to continue . . .

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 09 Dec 2014 11:45
by Squashman
You are positive you have files in this directory: C:\batch\vijay1

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 09 Dec 2014 11:56
by Squashman
The File Not Found error is coming from the DIR command in this line of code.

Code: Select all

for /f "delims=" %%i in ('dir /a-d/b %masks_2%') do>nul move /y "%%i" "%to%"

Basically means you do not have any files without an extension.

Re: Batch script to copy 0 byte and non 0 byte to another di

Posted: 10 Dec 2014 13:19
by bhas85
Hi Squashman,

Yes i had files in the directory "C:\batch\vijay1".But still i am getting file not found.

1.raw
1.xml
kiran.xml
vijay.raw
vijay123