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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bhas85
Posts: 8
Joined: 27 Nov 2014 13:55

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

#1 Post by bhas85 » 27 Nov 2014 14:04

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.

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

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

#2 Post by Yury » 27 Nov 2014 15:04

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

bhas85
Posts: 8
Joined: 27 Nov 2014 13:55

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

#3 Post by bhas85 » 04 Dec 2014 12:07

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=*.

bhas85
Posts: 8
Joined: 27 Nov 2014 13:55

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

#4 Post by bhas85 » 05 Dec 2014 16:48

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=*.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#5 Post by foxidrive » 08 Dec 2014 05:11

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?

bhas85
Posts: 8
Joined: 27 Nov 2014 13:55

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

#6 Post by bhas85 » 08 Dec 2014 12:41

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.

josephf
Posts: 11
Joined: 01 Feb 2014 23:22

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

#7 Post by josephf » 08 Dec 2014 22:02

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 \\

bhas85
Posts: 8
Joined: 27 Nov 2014 13:55

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

#8 Post by bhas85 » 09 Dec 2014 11:33

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 . . .

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#9 Post by Squashman » 09 Dec 2014 11:45

You are positive you have files in this directory: C:\batch\vijay1

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#10 Post by Squashman » 09 Dec 2014 11:56

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.

bhas85
Posts: 8
Joined: 27 Nov 2014 13:55

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

#11 Post by bhas85 » 10 Dec 2014 13:19

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

Post Reply