WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> Split to 2GB if bigger
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1315962484

Message started by mickey on Sep 14th, 2011 at 3:08am

Title: Split to 2GB if bigger
Post by mickey on Sep 14th, 2011 at 3:08am
I would like take files that are bigger than 2 gigs and split them into 2gb sections before being uploaded through the ftp plugin.  But have it ignore files under 2 gigs and just have it upload them as they are.  This is what I have so far using automatically start any program.  

Executable
C:\Programfiles\WinRar\Rar.exe
Directory
C:\
Parameters
IF %WD_FILE_SIZE_GB% LEQ 2 GOTO :IgnoreSmall

Should I be doing this with a .bat file instead, as I want the smaller files to be moved to the folder being watched for ftp uploads along with the files being archived?  And what do I have to do to get it to split the larger files into 2GB parts?  They can be .zip or .rar, as long as they are split into 2GB or smaller sections.

Title: Re: Split to 2GB if bigger
Post by Gert on Sep 14th, 2011 at 11:43am
Hi,

Yes, you should use a bat file instead. You can not write an "IF" like that in the parameter of the "run any program" plugin.

I am not sure how you want to split the files, it largely depends how the "receivers" will be joining those parts again.

If you try to explain a bit better, I will be happy to help you write a script.

Title: Re: Split to 2GB if bigger
Post by mickey on Sep 14th, 2011 at 3:36pm
Will be joined back together using winrar. No need to compress. Just split. I want files under 2GB to be passed on to upload folder. And files over 2GB to be split then passed on to the upload folder.



edit:

just to let you know the email I received was in German even though English is selected in my profile.

Title: Re: Split to 2GB if bigger
Post by Gert on Sep 15th, 2011 at 11:37am
German language forum notifications are a known issue, sorry for that.

A script like below should work, I am not sure how the rar.exe commandline would look, just make sure it also creates the splits in the OUTDIR

[code]rem where should files be moved (or RAR-ed) to?
SET OUTDIR=C:\Out\Upload

IF %WD_FILE_SIZE_MB% LSS 2048 GOTO :MoveNow

rem the size is bigger than 2048mb, here you need to split the file to %OUTDIR%


GOTO :EOF
:MoveNow
MOVE "%WD_FILE%" "%OUTDIR%"
GOTO :EOF

[/code]

Title: Re: Split to 2GB if bigger
Post by mickey on Sep 16th, 2011 at 4:17am
thanks.

Title: Re: Split to 2GB if bigger
Post by Gert on Sep 28th, 2011 at 12:12pm
The issue is with your SET statements and use of variables.

Change

Code (]SET %1=rar a "D:\Size\%WD_FILE%.rar" -ed -m0 -r -ilog -v2097152k "D:\Extracted\%WD_FILE%"
SET %2=CD D:\Extracted
[/code):

to
[code]SET VAR1=rar a "D:\Size\%WD_FILE%.rar" -ed -m0 -r -ilog -v2097152k "D:\Extracted\%WD_FILE%"
SET VAR2=CD D:\Extracted


and change

Code (]start "c:program files\winrar\rar.exe" %2 %1
[/code):

to
[code]start "c:\program files\winrar\rar.exe" %VAR2% %VAR1%


I am sure that will work a lot better.

Title: Re: Split to 2GB if bigger
Post by mickey on Sep 29th, 2011 at 1:54am
yup, sure does, thanks.

Title: Re: Split to 2GB if bigger
Post by Gert on Oct 1st, 2011 at 8:13pm
Please see http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html
for all %WD_xxxxx% variables you can use.

I think you are looking for %WD_FILE_B%

Title: Re: Split to 2GB if bigger
Post by mickey on Oct 2nd, 2011 at 6:40am
Yea, that page will be very helpful.  Thanks for all the help.

Title: Re: Split to 2GB if bigger
Post by lanky71 on Sep 21st, 2013 at 2:19pm
Hi,
I was running this bat file as described above, but I wanted to just rar/zip the file if over 2GB in file size and files that aren't over 2GB just to be left in the original directory.
Is there a command for this? cause at the moment the files that are smaller then 2GB are being moved to the directory where the rar/zip files are moved to.

Title: Re: Split to 2GB if bigger
Post by Dirk on Sep 21st, 2013 at 3:32pm
just use


Code (]IF %WD_FILE_SIZE_MB% GEQ 2048 GOTO :MoveNow[/code):
type
[code]help if

in a dos box to see all operators you can use

Title: Re: Split to 2GB if bigger
Post by lanky71 on Sep 22nd, 2013 at 5:58am
Does this look correct?

[code]
SET PATH="C:\Program Files\winRAR\";%path%
SETLOCAL ENABLEEXTENSIONS
CD C:\Users\root\Downloads\Extracted\
SET OUTDIR=C:\Users\root\Downloads\Done\

IF "%WD_FILE_SIZE_MB%" LSS 2040 GOTO :EOF

:SPLIT
rar a -ed -ilog -m0 -r -rr10 -v2000000 "C:\Users\root\Downloads\Done\%WD_FILE_B%.rar" "%WD_FILE%"

GOTO :EOF
[/code]

CD = the directory to monitor for files that may need raring and SET OUTDIR the directory where the rar'd files are to be put.
And if the original file size is smaller then 2000mb then leave as is do not rar or move. But if over 2000mb then rar and put rar'ed file into outdir but leave original file in CD directory.

code modified by Gert

Title: Re: Split to 2GB if bigger
Post by Dirk on Sep 22nd, 2013 at 9:54am
It looks correct to me. (You do not need the cd ...  line, but it doesn't matter if you have it)

Title: Re: Split to 2GB if bigger
Post by lanky71 on Sep 28th, 2013 at 9:58am
ok,
finally got around to testing this and it doesn't seem to be working.
theres another process that renames and moves files to the "done" folder which is working, but the rar over 2gb filesize process says done in watchdirectory but nothing is happening.

Title: Re: Split to 2GB if bigger
Post by Gert on Sep 28th, 2013 at 12:00pm
I have changed your code above a bit for 2 issues I see.

Your original was

Code (]rar a -ed -ilog -m0 -r -rr10 -v2000000 "C:\Users\root\Downloads\Done\
%WD_FILE_B%.rar" "WD_FILE%"
[/code):

I have changed it to
[code]rar a -ed -ilog -m0 -r -rr10 -v2000000 "C:\Users\root\Downloads\Done\%WD_FILE_B%.rar" "%WD_FILE%"

I removed the linefeed and added a missing %

Title: Re: Split to 2GB if bigger
Post by lanky71 on Sep 28th, 2013 at 3:50pm

lanky71 wrote on Sep 22nd, 2013 at 5:58am:
Does this look correct?

[code]
SET PATH="C:\Program Files\winRAR\";%path%
SETLOCAL ENABLEEXTENSIONS
CD C:\Users\root\Downloads\Extracted\
SET OUTDIR=C:\Users\root\Downloads\Done\

IF "%WD_FILE_SIZE_MB%" LSS 2040 GOTO :EOF

:SPLIT
rar a -ed -ilog -m0 -r -rr10 -v2000000 "C:\Users\root\Downloads\Done\%WD_FILE_B%.rar" "%WD_FILE%"

GOTO :EOF
[/code]

CD = the directory to monitor for files that may need raring and SET OUTDIR the directory where the rar'd files are to be put.
And if the original file size is smaller then 2000mb then leave as is do not rar or move. But if over 2000mb then rar and put rar'ed file into outdir but leave original file in CD directory.

code modified by Gert


Hi,
The above quoted text  is my code that I am using and it's not working.

Title: Re: Split to 2GB if bigger
Post by Gert on Sep 28th, 2013 at 5:15pm
I do not know what could be the issue (I didn't test your code), maybe a wrong command line option for rar?

The easiest way to see what could be happening.....
Make sure the "Run a bat file" task has the option "Capture output" selected.
Run the task, put a new file in the monitored directory so your script is called
stop the task
select the menu "Tools -> View task directory" - this opens windows explorer, typically inside C:\ProgramData\WatchDirectory
go to the sub-directory with the same name as your task
There you will find one outputxxxxx_yyyyy.log file for each time your script was called.

You may spot the error when you examine the contents of the most current logfile.

Title: Re: Split to 2GB if bigger
Post by lanky71 on Sep 29th, 2013 at 2:27am
ok, ive had a look but i cant see any errors or faults aside from lots of extra lines, I also tried specifying the .exe file for winrar and it didnt seem to change anything

Code (]

C:\Program Files (x86)\watchDirectory>GOTO :StartOfBat
C:\Program Files (x86)\watchDirectory>"C:\Program Files (x86)\watchDirectory\wdAnnotate.exe" info "Starting C:\Program Files\WinRAR\Split.bat for event"

C:\Program Files (x86)\watchDirectory>Call "C:\Program Files\WinRAR\Split.bat" FILENEW
C:\Program Files (x86)\watchDirectory>SET PATH="C:\Program Files\WinRAR\";C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\watchDirectory>SETLOCAL ENABLEEXTENSIONS
C:\Program Files (x86)\watchDirectory>CD C:\Users\root\Downloads\Extracted\
C:\Users\root\Downloads\Extracted>SET OUTDIR=c:\Users\root\Downloads\Done\
C:\Users\root\Downloads\Extracted>IF "432" LSS 2040 GOTO :EOF
C:\Program Files (x86)\watchDirectory>"C:\Program Files (x86)\watchDirectory\wdAnnotate.exe" info "Done"
[/code):

And
[code]

C:\Program Files (x86)\watchDirectory>GOTO :StartOfBat
C:\Program Files (x86)\watchDirectory>"C:\Program Files (x86)\watchDirectory\wdAnnotate.exe" info "Starting C:\Program Files\WinRAR\Split.bat for event"

C:\Program Files (x86)\watchDirectory>Call "C:\Program Files\WinRAR\Split.bat" FILENEW
C:\Program Files (x86)\watchDirectory>SET PATH="C:\Program Files\WinRAR\WinRAR.exe";C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\watchDirectory>SETLOCAL ENABLEEXTENSIONS
C:\Program Files (x86)\watchDirectory>CD C:\Users\root\Downloads\Extracted\
C:\Users\root\Downloads\Extracted>SET OUTDIR=c:\Users\root\Downloads\Done\
C:\Users\root\Downloads\Extracted>IF "13889" LSS 2040 GOTO :EOF
C:\Program Files (x86)\watchDirectory>"C:\Program Files (x86)\watchDirectory\wdAnnotate.exe" info "Done"


Title: Re: Split to 2GB if bigger
Post by Gert on Sep 29th, 2013 at 9:04am
I think it may have to do with the "quotes" surrounding "%WD_FILE_SIZE_MB%", it causes the IF statement to do an alphabetical comparison instead of numerical. Remove the quotes and do NOT add WinRar.exe to the path - that won't work.

Title: Re: Split to 2GB if bigger
Post by lanky71 on Sep 29th, 2013 at 1:38pm
thank you that has fixed it :)

Is there anyway to also get the bat file to rename the files that are rared as well? like adding a prefix to the newly created split rar files?

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.